Ignore:
Timestamp:
2018-10-11T19:31:44+13:00 (4 years ago)
Author:
ak19
Message:

Refactoring some existing perl code as per Dr Bainbridge's ideas on this, so that MySQLPlugout, which inherits from GreenstoneXMLPlugout, can be structured better for reading.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/docprint.pm

    r19214 r32512  
    3030package docprint;
    3131
     32use constant OUTPUT_META_ONLY => 1;
     33use constant OUTPUT_TEXT_ONLY => 2;
     34use constant OUTPUT_ALL => 3;
     35
    3236use strict;
    3337
    3438sub get_section_xml {
     39    return &get_section_xml_from_root(@_);
     40}
     41
     42sub 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
     47sub recursive_get_section_xml {   
     48    my ($doc_obj, $section, $options) = @_;
    3549   
    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   
    3861    my $section_ptr = $doc_obj->_lookup_section ($section);
    3962    return "" unless defined $section_ptr;
     
    4164    my $all_text = "<Section>\n";
    4265    $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";
    4875    }
    4976
     
    5279    # output the text
    5380    $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    }
    5586    $all_text .= "</Content>\n";
    5687   
    5788    # output all the subsections
    5889    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");
    6091    }
    6192   
Note: See TracChangeset for help on using the changeset viewer.