Ignore:
Timestamp:
2018-10-11T19:31:44+13:00 (6 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/plugouts/GreenstoneXMLPlugout.pm

    r32511 r32512  
    7676}
    7777
    78 sub saveas {
     78sub old_unused_saveas {
    7979    my $self = shift (@_);
    8080    my ($doc_obj, $doc_dir) = @_;
     
    117117    }
    118118
    119     my $section_text = &docprint::get_section_xml($doc_obj,$doc_obj->get_top_section());
     119    my $section_text = &docprint::get_section_xml($doc_obj);
    120120    print $outhandler $section_text;
    121121 
     
    138138    $self->store_output_info_reference($doc_obj);
    139139   
     140}
     141
     142sub pre_saveas {
     143    my $self = shift (@_);
     144    my ($doc_obj, $doc_dir) = @_;
     145    my $outhandler;
     146    my $output_file;
     147    if ($self->{'debug'}) {
     148    $outhandler = STDOUT;
     149    }
     150    else {
     151       
     152    $self->process_assoc_files($doc_obj, $doc_dir, '');
     153    $self->process_metafiles_metadata ($doc_obj);
     154   
     155    # open up the outhandler   
     156    if ($self->is_group() && !$self->{'new_doc_dir'}) {
     157        # we already have a handle open ??
     158        $outhandler = $self->{'group_outhandler'};
     159    } else {
     160        $output_file = &FileUtils::filenameConcatenate($self->{'output_dir'}, $doc_dir, "doc.xml");
     161        # open the new handle
     162        $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
     163
     164        if (defined $self->{'xslt_writer'}){
     165        $outhandler = $self->{'xslt_writer'};
     166        }
     167        else{
     168        $outhandler = $self->get_output_handler($output_file);
     169        }
     170       
     171        if ($self->is_group()) {
     172        $self->{'group_outhandler'} = $outhandler;
     173        }
     174    }
     175    } # else not debug
     176    binmode($outhandler,":utf8");
     177
     178    # only output the header if we have started a new doc
     179    if (!$self->is_group() || $self->{'new_doc_dir'}) {
     180    $self->output_xml_header($outhandler);
     181    }
     182 
     183    return ($outhandler, $output_file);
     184}
     185
     186sub saveas {
     187    my $self = shift (@_);
     188    my ($doc_obj, $doc_dir) = @_;
     189
     190    # pre
     191    my ($outhandler, $output_file) = $self->pre_saveas(@_);
     192    push(@_, $outhandler, $output_file);
     193
     194    # write out the doc xml file for the current document
     195    my $section_text = &docprint::get_section_xml($doc_obj);
     196    print $outhandler $section_text;
     197
     198    # post
     199    $self->post_saveas(@_);
     200}
     201
     202sub post_saveas {
     203    my $self = shift (@_);   
     204    my ($doc_obj, $doc_dir, $outhandler, $output_file) = @_;
     205   
     206    # only output the footer if we are not doing group stuff. The group file will be finished in close_group_output
     207    if (!$self->is_group()) {
     208    $self->output_xml_footer($outhandler);
     209    }
     210
     211    # close off the output - in a group process situation, this will be done by close_group_output
     212    if (!$self->is_group() && !$self->{'debug'}) {
     213    if (defined $self->{'xslt_writer'}){     
     214        $self->close_xslt_pipe();
     215    }
     216    else {
     217        &FileUtils::closeFileHandle($output_file, \$outhandler) if defined $output_file;
     218    }
     219    }
     220    $self->{'short_doc_file'} = &FileUtils::filenameConcatenate($doc_dir, "doc.xml"); 
     221   
     222    $self->store_output_info_reference($doc_obj);   
    140223}
    141224
Note: See TracChangeset for help on using the changeset viewer.