Changeset 32512 for main/trunk/greenstone2/perllib/docprint.pm
- Timestamp:
- 2018-10-11T19:31:44+13:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/docprint.pm
r19214 r32512 30 30 package docprint; 31 31 32 use constant OUTPUT_META_ONLY => 1; 33 use constant OUTPUT_TEXT_ONLY => 2; 34 use constant OUTPUT_ALL => 3; 35 32 36 use strict; 33 37 34 38 sub get_section_xml { 39 return &get_section_xml_from_root(@_); 40 } 41 42 sub get_section_xml_from_root { 43 my ($doc_obj, $options) = @_; 44 return &recursive_get_section_xml($doc_obj,$doc_obj->get_top_section(), $options); 45 } 46 47 sub recursive_get_section_xml { 48 my ($doc_obj, $section, $options) = @_; 35 49 36 my ($doc_obj, $section) = @_; 37 50 # 'output' can be OUTPUT_ALL|OUTPUT_META_ONLY|OUTPUT_TEXT_ONLY 51 # If not provided, it defaults to OUTPUT_ALL. 52 # If OUTPUT_ALL, the metadata and full text both go into doc.xml 53 # If OUTPUT_META_ONLY, the metadata goes into doc.xml and full text goes elsewhere (mysql db). 54 # If OUTPUT_TEXT_ONLY, the full text goes into doc.xml and metadata goes elsewhere (mysql db). 55 # In the last two cases, an XML comment is left behind to indicate that the "missing" doc 56 # information is stored elsewhere. 57 if(!defined $options) { 58 $options = {'output' => OUTPUT_ALL }; 59 } 60 38 61 my $section_ptr = $doc_obj->_lookup_section ($section); 39 62 return "" unless defined $section_ptr; … … 41 64 my $all_text = "<Section>\n"; 42 65 $all_text .= " <Description>\n"; 43 44 # output metadata 45 foreach my $data (@{$section_ptr->{'metadata'}}) { 46 my $escaped_value = &escape_text($data->[1]); 47 $all_text .= ' <Metadata name="' . $data->[0] . '">' . $escaped_value . "</Metadata>\n"; 66 67 if($options->{'output'} == OUTPUT_ALL || $options->{'output'} == OUTPUT_META_ONLY) { 68 # output metadata 69 foreach my $data (@{$section_ptr->{'metadata'}}) { 70 my $escaped_value = &escape_text($data->[1]); 71 $all_text .= ' <Metadata name="' . $data->[0] . '">' . $escaped_value . "</Metadata>\n"; 72 } 73 } else { 74 $all_text .= "<!-- metadata is stored elsewhere (MySQL database) -->\n"; 48 75 } 49 76 … … 52 79 # output the text 53 80 $all_text .= " <Content>"; 54 $all_text .= &escape_text($section_ptr->{'text'}); 81 if($options->{'output'} == OUTPUT_ALL || $options->{'output'} == OUTPUT_TEXT_ONLY) { 82 $all_text .= &escape_text($section_ptr->{'text'}); 83 } else { 84 $all_text .= "<!-- full text is stored elsewhere (MySQL database) -->\n"; 85 } 55 86 $all_text .= "</Content>\n"; 56 87 57 88 # output all the subsections 58 89 foreach my $subsection (@{$section_ptr->{'subsection_order'}}) { 59 $all_text .= & get_section_xml($doc_obj, "$section.$subsection");90 $all_text .= &recursive_get_section_xml($doc_obj, "$section.$subsection"); 60 91 } 61 92
Note:
See TracChangeset
for help on using the changeset viewer.