From 74927a08f548ed3ce6bc330ddce605abb9a02a07 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 8 Jan 2009 16:34:23 +0000 Subject: aggirato il problema dei titoli che in alcune lingue non esistono git-svn-id: svn://luxion/repos/WebCoso/trunk@407 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Common.pm | 20 +++++++++++++++++--- lib/WebCoso/XSLT.pm | 25 ++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'lib/WebCoso') diff --git a/lib/WebCoso/Common.pm b/lib/WebCoso/Common.pm index 6c9a433..f01e739 100644 --- a/lib/WebCoso/Common.pm +++ b/lib/WebCoso/Common.pm @@ -8,6 +8,7 @@ use DateTime; use DateTime::Format::DateParse; use Log::Log4perl ':easy'; use List::MoreUtils 'uniq'; +use List::Util 'first'; our $SRCPATH='src'; our $DSTPATH='dst'; @@ -91,10 +92,23 @@ sub isLang { sub getTitleFor { my ($fc,$lang,$path,$name)=@_; DEBUG("getTitleFor($lang,$path,$name)"); - my $doc_name=srcXMLFor($lang,$path,$name); - DEBUG("getTitleFor -> $doc_name"); + my ($doc_name,$doc); + + if (ref($lang)) { # assume it's an array + for my $l (@$lang) { + $doc_name=srcXMLFor($l,$path,$name); + DEBUG("getTitleFor -> try $doc_name"); + $doc=$fc->get($doc_name); + last if $doc; + } + } + else { + $doc_name=srcXMLFor($lang,$path,$name); + DEBUG("getTitleFor -> $doc_name"); + + $doc=$fc->get($doc_name); + } - my $doc=$fc->get($doc_name); unless ($doc) { LOGWARN("No document for <$doc_name>, returning <$name>"); return "$name"; # force it to a string, since it might be an XML Node diff --git a/lib/WebCoso/XSLT.pm b/lib/WebCoso/XSLT.pm index 9cbeab0..28643c5 100644 --- a/lib/WebCoso/XSLT.pm +++ b/lib/WebCoso/XSLT.pm @@ -20,7 +20,7 @@ sub new { $self->{xslt_proc}=XML::LibXSLT->new(); $self->{xslt_proc}->register_function($NS,'title-for', - sub{$self->getTitleXML(WebCoso::Common::getTitleFor($self->{fc},@_))}); + sub{$self->getTitleForXML(@_)}); $self->{xslt_proc}->register_function($NS,'dst-uri-for', sub{WebCoso::Common::dstUriFor(@_)}); $self->{xslt_proc}->register_function($NS,'tagged',sub{$self->getTagsXML}); @@ -158,6 +158,29 @@ sub getDatesXML { } } +sub getTitleForXML { + my ($self,$lang,$path,$name)=@_; + + my $lang_cleaned; + if (ref($lang) && $lang->can('get_nodelist')) { + DEBUG('getTitleForXML with multple languages'); + for my $node ($lang->get_nodelist) { + my $val=$node->findvalue('normalize-space(string(.))'); + DEBUG(" <$val>"); + push @{$lang_cleaned},$val if length($val)>0; + } + } + else { + DEBUG('getTitleForXML with a single language'); + $lang_cleaned=$lang; + } + return $self->getTitleXML(WebCoso::Common::getTitleFor( + $self->{fc}, + $lang_cleaned, + $path, + $name)); +} + sub getTitleXML { my ($self,$title)=@_; -- cgit v1.2.3