aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/XSLT.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebCoso/XSLT.pm')
-rw-r--r--lib/WebCoso/XSLT.pm43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/WebCoso/XSLT.pm b/lib/WebCoso/XSLT.pm
index b52d596..73ba59d 100644
--- a/lib/WebCoso/XSLT.pm
+++ b/lib/WebCoso/XSLT.pm
@@ -27,6 +27,7 @@ sub new {
$self->{xslt_proc}->register_function($NS,'dst-uri-for',
sub{WebCoso::Common::dstUriFor(@_)});
$self->{xslt_proc}->register_function($NS,'tagged',sub{$self->getTagsXML});
+ $self->{xslt_proc}->register_function($NS,'changes',sub{$self->getChangesXML});
$self->{xslt_proc}->register_function($NS,'dates-for',
sub{$self->getDatesXML(WebCoso::Common::getDatesFor($self->{fc},@_))});
$self->{xslt_proc}->register_function($NS,'document',
@@ -57,6 +58,13 @@ sub new {
} else {
$self->setXMLTagsSource(undef);
}
+ if (@$deps>2) {
+ INFO("changes from $deps->[1]");
+ $self->setChangesSource($self->{fc}->get($deps->[1]));
+ }
+ else {
+ $self->setChangesSource(undef);
+ }
my $out=$xslt->transform($du,
XML::LibXSLT::xpath_to_string(
path => $matches->[0],
@@ -145,6 +153,41 @@ sub getTagsXML {
my %name_map=(creation=>'wc:creation-date',
last_change=>'wc:last-change');
my $format=DateTime::Format::Strptime->new(pattern=>'%F %T',time_zone=>'UTC');
+sub setChangesSource {
+ my ($self,$source)=@_;
+ # the weird copy seems to be needed, otherwise sometimes it looks empty
+ $self->{changes_source}=(defined $source) ? {%$source} : undef;
+ delete $self->{changes_document};
+}
+sub getChangesXML {
+ my ($self)=@_;
+ if (defined $self->{chasges_document}) {
+ DEBUG('returing cached ChangesXML');
+ return $self->{Changes_document}
+ }
+ DEBUG('building ChangesXML');
+ my $doc=XML::LibXML::Document->new();
+ return $doc unless defined $self->{changes_source};
+
+ my $de=$doc->createElementNS($NS,'wc:changes');
+ $doc->setDocumentElement($de);
+ my ($docpath,$dates);
+ while (($docpath,$dates)=each %{$self->{changes_source}}) {
+ my $te=$doc->createElementNS($NS,'wc:document');
+ $te->setAttribute('path',$docpath);
+ $te->setAttribute('uri',WebCoso::Common::dstUriFor($docpath));
+ $te->setAttribute('lang',WebCoso::Common::langOf($docpath));
+ $de->appendChild($te);
+ my ($type,$value);
+ while (($type,$value)=each %$dates) {
+ my $dle=$doc->createElementNS($NS,$name_map{$type});
+ $dle->appendTextNode($format->format_datetime($value));
+ $te->appendChild($dle);
+ }
+ }
+ return $self->{changes_document}=$doc;
+}
+
sub getDatesXML {
my ($self,$dates)=@_;
my $doc=XML::LibXML::Document->new();