From 7e38f2229497e49f0c00f12e51f37d6942c0cfea Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 7 Feb 2006 17:24:37 +0000 Subject: raccolta meta-dati, con test. TODO collezioni git-svn-id: svn://luxion/repos/WebCoso/trunk@160 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Step/ReST/ToXml.pm | 57 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'lib/WebCoso') diff --git a/lib/WebCoso/Step/ReST/ToXml.pm b/lib/WebCoso/Step/ReST/ToXml.pm index f65e71c..f5cf5a9 100644 --- a/lib/WebCoso/Step/ReST/ToXml.pm +++ b/lib/WebCoso/Step/ReST/ToXml.pm @@ -17,7 +17,7 @@ l'xml, lo passa al parser, e salva il dom in suppone venga tutto da un solo file -Fa tutto alla prima passata +Fa tutto alla prima passata, e raccatta un po' di meta =cut @@ -41,31 +41,80 @@ sub process { my ($rst_doc,$xml_dom); $rst_doc=$resource->get_property_string($srckey); if (defined $rst_doc) { # monolingua + my $dom=rst2xml($rst_doc,$src_path); $resource->set_property( $dstkey, - rst2xml($rst_doc,$src_path) + $dom, ); + $self->_set_meta($resource,$dom); } else { # multilingua my @langs=$resource->get_axis_values('language'); for my $cur_lang (@langs) { $rst_doc=$resource->get_property_string({language=>$cur_lang},$srckey); + my $dom=rst2xml($rst_doc,$src_path,$cur_lang); $resource->set_property( {language=>$cur_lang}, $dstkey, - rst2xml($rst_doc,$src_path,$cur_lang) + $dom, ); + $self->_set_meta($resource,$cur_lang,$dom); } } return; } +{ +my %docinfo_fields=( + title => '/document/title', + subtitle => '/document/subtitle', + author => '/document/docinfo/author|/document/docinfo/authors/author', + version => '/document/docinfo/version', + status => '/document/docinfo/status', + date => '/document/docinfo/date', + creation_date => '/document/docinfo/field[field_name="CreationDate"]/field_body', +); +my $collections='/document/docinfo/field[field_name="Collection"]/field_body|/document/docinfo/field[field_name="Collections"]/field_body//list_item'; +sub _set_meta { + my ($self,$res,$lang,$dom)=@_; + + if ($dom) { # 4 parametri + $lang={language=>$lang}; + } + else { # 3 parametri: monolingua + $dom=$lang; + $lang={}; + } + + for my $meta (keys %docinfo_fields) { + my @nodes=$dom->findnodes($docinfo_fields{$meta}); + next unless @nodes; + @nodes=map {$_->textContent()} @nodes; + if (@nodes==1) { + $res->set_property($lang,$meta,$nodes[0]); + } + else { + $res->set_property($lang,$meta,[@nodes]); + } + } + + # per questo serve poter chiamare coll e res per nome TODO + #my @collections=$dom->findnodes($collections); + #return unless @collections; + #@collections=map {$_->textContent()} @collections; + + #$res->add_coll($_) for @collections; + + return; +} +} + sub rst2xml { my ($rst_string,$source_path,$language)=@_; $rst_string=Encode::encode('utf-8',$rst_string); - my $xml_string=_rst2xml($rst_string,$source_path,$language||'it'); + my $xml_string=_rst2xml($rst_string,$source_path,'en'); $xml_parser->base_uri($source_path); return $xml_parser->parse_string($xml_string); } -- cgit v1.2.3