HTTP-DAV
view release on metacpan or search on metacpan
lib/HTTP/DAV/Resource.pm view on Meta::CPAN
my ($self, $node) = @_;
# <!ELEMENT status (#PCDATA) >
# <!ELEMENT responsedescription (#PCDATA) >
my $node_status = HTTP::DAV::Utils::get_only_element($node, "D:status");
my $node_rd
= HTTP::DAV::Utils::get_only_element($node, "D:responsedescription");
my $status = $node_status->getFirstChild->getNodeValue()
if ($node_status);
my $rd = $node_rd->getFirstChild->getNodeValue() if ($node_rd);
return ($status, $rd);
}
###
# Pass in the XML::DOM prop node Element and it will
# parse and store all of the properties. These ones
# are specifically dealt with:
# creationdate
# getcontenttype
# getcontentlength
# displayname
# getetag
# getlastmodified
# resourcetype
# supportedlock
# lockdiscovery
# source
sub _XML_parse_and_store_props {
my ($self, $node) = @_;
my %return_props = ();
return unless ($node && $node->hasChildNodes());
# These elements will just get copied straight into our properties hash.
my @raw_copy = qw(
creationdate
getlastmodified
getetag
displayname
getcontentlength
getcontenttype
);
my $props = $node->getChildNodes;
my $n = $props->getLength;
for (my $i = 0; $i < $n; $i++) {
my $prop = $props->item($i);
# Ignore anything in the <prop> element which is
# not an Element. i.e. ignore comments, text, etc...
next if ($prop->getNodeTypeName() ne "ELEMENT_NODE");
my $prop_name = $prop->getNodeName();
$prop_name = HTTP::DAV::Utils::XML_remove_namespace($prop_name);
if (grep (/^$prop_name$/i, @raw_copy)) {
my $cdata = HTTP::DAV::Utils::get_only_cdata($prop);
$self->set_property($prop_name, $cdata);
}
elsif ($prop_name eq "lockdiscovery") {
my @locks = HTTP::DAV::Lock->XML_lockdiscovery_parse($prop);
$self->set_locks(@locks);
}
elsif ($prop_name eq "supportedlock") {
my $supportedlock_hashref
= HTTP::DAV::Lock::get_supportedlock_details($prop);
$self->set_property("supportedlocks", $supportedlock_hashref);
}
# Work in progress
# elsif ( $prop_name eq "source" ) {
# my $links = $self->_XML_parse_source_links( $prop );
# $self->set_property( "supportedlocks", $supportedlock_hashref );
# }
#resourcetype and others
else {
my $node_name = HTTP::DAV::Utils::XML_remove_namespace(
$prop->getNodeName());
my $str = "";
my @nodes = $prop->getChildNodes;
foreach my $node (@nodes) { $str .= $node->toString; }
$self->set_property($node_name, $str);
}
}
###
# Cleanup work
# set collection based on resourcetype
#my $getcontenttype = $self->get_property("getcontenttype");
#($getcontenttype && $getcontenttype =~ /directory/i ) ||
my $resourcetype = $self->get_property("resourcetype");
if (($resourcetype && $resourcetype =~ /collection/i)) {
$self->set_property("resourcetype", "collection");
my $uri = HTTP::DAV::Utils::make_trail_slash($self->get_uri);
$self->set_uri($uri);
}
# Clean up the date work.
my $creationdate = $self->get_property("creationdate");
if ($creationdate) {
my ($epochgmt) = HTTP::Date::str2time($creationdate);
$self->set_property("creationepoch", $epochgmt);
$self->set_property("creationdate", HTTP::Date::time2str($epochgmt));
}
my $getlastmodified = $self->get_property("getlastmodified");
if ($getlastmodified) {
my ($epochgmt) = HTTP::Date::str2time($getlastmodified);
$self->set_property("lastmodifiedepoch", $epochgmt);
$self->set_property("lastmodifieddate",
HTTP::Date::time2str($epochgmt));
}
}
( run in 0.629 second using v1.01-cache-2.11-cpan-39bf76dae61 )