Ignore:
Timestamp:
2013-11-19T12:06:05+13:00 (10 years ago)
Author:
kjdon
Message:

group processing code was GreenstoneXML format so moved it into GreenstoneXMLPlugout. tidying up the code. reordered options. group processing now writes out the correct archivesinf databases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugouts/GreenstoneXMLPlugout.pm

    r27522 r28642  
    4040}
    4141
    42 my $arguments = [];
    43 
     42my $arguments = [
     43       { 'name' => "group_size",
     44    'desc' => "{BasePlugout.group_size}",
     45    'type' => "int",
     46        'deft' =>  "1",
     47    'reqd' => "no",
     48    'hiddengli' => "no"}
     49    ];
    4450my $options = { 'name'     => "GreenstoneXMLPlugout",
    4551        'desc'     => "{GreenstoneXMLPlugout.desc}",
    4652        'abstract' => "no",
    47         'inherits' => "yes" };
     53        'inherits' => "yes",
     54        'args'     => $arguments };
    4855
    4956sub new {
     
    6067}
    6168
     69sub is_group {
     70    my $self = shift (@_);
     71    return ($self->{'group_size'} > 1);
     72}
     73
    6274sub saveas {
    6375    my $self = shift (@_);
    64     my ($doc_obj,$doc_dir) = @_;
    65 
     76    my ($doc_obj, $doc_dir) = @_;
    6677    my $outhandler;
    6778    my $output_file;
    6879    if ($self->{'debug'}) {
    6980    $outhandler = STDOUT;
    70     # can we do the xslt and still do debug mode?
    7181    }
    7282    else {
    73     my $output_dir = $self->get_output_dir();
    74         if (!&FileUtils::directoryExists($output_dir))
    75         {
    76           &FileUtils::makeAllDirectories($output_dir);
    77         }
     83       
     84    $self->process_assoc_files($doc_obj, $doc_dir, '');
     85    $self->process_metafiles_metadata ($doc_obj);
     86   
     87    # open up the outhandler   
     88    if ($self->is_group() && !$self->{'new_doc_dir'}) {
     89        # we already have a handle open ??
     90        $outhandler = $self->{'group_outhandler'};
     91    } else {
     92        $output_file = &FileUtils::filenameConcatenate($self->{'output_dir'}, $doc_dir, "doc.xml");
     93        # open the new handle
     94        $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
    7895
    79     my $working_dir = &FileUtils::filenameConcatenate($output_dir, $doc_dir);
    80         if (!&FileUtils::directoryExists($working_dir))
    81         {
    82           &FileUtils::makeAllDirectories($working_dir);
    83         }
     96        if (defined $self->{'xslt_writer'}){
     97        $outhandler = $self->{'xslt_writer'};
     98        }
     99        else{
     100        $outhandler = $self->get_output_handler($output_file);
     101        }
     102       
     103        if ($self->is_group()) {
     104        $self->{'group_outhandler'} = $outhandler;
     105        }
     106    }
     107    } # else not debug
     108    binmode($outhandler,":utf8");
    84109
    85     $self->process_assoc_files ($doc_obj, $doc_dir, '');
    86 
    87     $self->process_metafiles_metadata ($doc_obj);
    88 
    89     $output_file = &FileUtils::filenameConcatenate($working_dir, "doc.xml");
    90 
    91     $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
    92 
    93     if (defined $self->{'xslt_writer'}){
    94         $outhandler = $self->{'xslt_writer'};
    95     }
    96     else{
    97         $outhandler = $self->get_output_handler($output_file);
    98     }
     110    # only output the header if we have started a new doc
     111    if (!$self->is_group() || $self->{'new_doc_dir'}) {
     112    $self->output_xml_header($outhandler);
    99113    }
    100114
    101     binmode($outhandler,":utf8");
     115    my $section_text = &docprint::get_section_xml($doc_obj,$doc_obj->get_top_section());
     116    print $outhandler $section_text;
     117 
     118    # only output the footer if we are not doing group stuff. The group file will be finished in close_group_output
     119    if (!$self->is_group()) {
     120    $self->output_xml_footer($outhandler);
     121    }
    102122
    103     $self->output_xml_header($outhandler,"Archive");
    104     my $section_output = &docprint::get_section_xml($doc_obj, $doc_obj->get_top_section());
    105     print $outhandler $section_output;
    106     $self->output_xml_footer($outhandler,"Archive");
    107 
    108     if (!$self->{'debug'}) {
     123    # close off the output - in a group process situation, this will be done by close_group_output
     124    if (!$self->is_group() && !$self->{'debug'}) {
    109125    if (defined $self->{'xslt_writer'}){     
    110126        $self->close_xslt_pipe();
     
    113129        &FileUtils::closeFileHandle($output_file, \$outhandler) if defined $output_file;
    114130    }
    115    
    116     $self->{'short_doc_file'} = &FileUtils::filenameConcatenate($doc_dir, "doc.xml"); 
    117    
    118     $self->store_output_info_reference($doc_obj);
    119131    }
     132    $self->{'short_doc_file'} = &FileUtils::filenameConcatenate($doc_dir, "doc.xml"); 
     133   
     134    $self->store_output_info_reference($doc_obj);
     135   
    120136}
    121137
     138sub output_xml_header {
     139    my $self = shift (@_);
     140    my ($outhandle) = @_;
     141
     142    print $outhandle '<?xml version="1.0" encoding="utf-8" standalone="no"?>' . "\n";
     143    print $outhandle "<!DOCTYPE Archive SYSTEM \"http://greenstone.org/dtd/Archive/1.0/Archive.dtd\">\n";
     144    print $outhandle "<Archive>\n";
     145}
     146
     147sub output_xml_footer {
     148    my $self = shift (@_);
     149    my ($outhandle) = @_;
     150
     151    print $outhandle "</Archive>\n";
     152}
     153
     154sub close_group_output
     155{
     156    my $self = shift(@_);
     157 
     158    # make sure that the handle has been opened - it won't be if we failed
     159    # to import any documents...
     160    my $outhandle = $self->{'group_outhandler'};
     161    if (defined(fileno($outhandle))) {
     162    $self->output_xml_footer($outhandle);   
     163    &FileUtils::closeFileHandle("", \$outhandle);
     164    undef $self->{'group_outhandler'}
     165    }
     166
     167    my $OID = $self->{'gs_OID'};
     168    my $short_doc_file = $self->{'short_doc_file'};
     169   
     170    ### TODO - from here is old code. check that it is still valid.
     171    if ($self->{'gzip'}) {
     172    my $doc_file = $self->{'gs_filename'};
     173    `gzip $doc_file`;
     174    $doc_file .= ".gz";
     175    $short_doc_file .= ".gz";
     176    if (!&FileUtils::fileExists($doc_file)) {
     177         my $outhandle = $self->{'output_handle'};
     178        print $outhandle "error while gzipping: $doc_file doesn't exist\n";
     179        return 0;
     180    }
     181    }
     182
     183    return 1;
     184}
    122185
    123186
Note: See TracChangeset for help on using the changeset viewer.