Changeset 28706

Show
Ignore:
Timestamp:
28.11.2013 15:28:43 (6 years ago)
Author:
kjdon
Message:

tidied this up a bit, can't really remember exactly what I have done and I am in a hurry

Files:
1 modified

Legend:

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

    r28562 r28706  
    2828use strict; 
    2929no strict 'refs'; 
     30no strict 'subs'; # allow barewords (eg STDERR) as function arguments 
    3031 
    3132eval {require bytes}; 
     
    4445           'desc' => "{MARCXMLPlugout.group}", 
    4546           'type' => "flag", 
    46                    'deft' => "0", 
    4747           'reqd' => "no",     
    4848           'hiddengli' => "no"}, 
     
    5151           'type' => "string", 
    5252           'deft' => "dc2marc-mapping.xml", 
    53            'reqd' => "yes",     
     53           'reqd' => "no",     
    5454           'hiddengli' => "no"}, 
    5555         { 'name' => "xslt_file",  
     
    8181    $self->{'buffered_output'} =""; 
    8282      
     83    # xslt_file is checked in BasePlugout 
     84    # check the mapping file here 
    8385    my $full_path_to_mapping_file = &util::locate_config_file($self->{'mapping_file'}); 
    8486    if (! defined $full_path_to_mapping_file) { 
    85     print STDERR "Can not find $self->{'mapping_file'}, please make sure you have supplied the correct file path\n"; 
     87    print STDERR "Can not find mapping file $self->{'mapping_file'}, please make sure you have supplied the correct file path or put the file into the collection's etc or greenstone's etc folder\n"; 
    8688    die "\n"; 
    8789    } 
    8890    $self->{'mapping_file'} = $full_path_to_mapping_file; 
    8991 
    90    return bless $self, $class; 
     92    return bless $self, $class; 
    9193} 
    9294 
    93 sub saveas { 
     95sub begin { 
     96 
     97    my $self= shift (@_); 
     98    if ($self->{'group'}) { 
     99    # all output goes into this file 
     100    my $output_dir = $self->get_output_dir(); 
     101    &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir; 
     102 
     103    $self->{'short_doc_file'} = "marc.xml"; 
     104    } 
     105} 
     106# override BasePlugout process 
     107sub process { 
    94108    my $self = shift (@_); 
    95     my ($doc_obj,$doc_dir) = @_; 
     109    my ($doc_obj) = @_; 
    96110 
    97     
     111    my $output_info = $self->{'output_info'}; 
     112    return if (!defined $output_info); 
     113 
     114    $self->process_metafiles_metadata ($doc_obj);   
     115     
    98116    if ($self->{'group'}){ 
    99117        $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";  
    100         return; 
    101118    } 
    102      
    103     $self->process_metafiles_metadata ($doc_obj); 
     119    else { 
     120    # find out which directory to save to 
     121    my $doc_dir = $self->get_doc_dir($doc_obj); 
     122    my $output_file = &FileUtils::filenameConcatenate ($self->get_output_dir(), $doc_dir, "marc.xml");     
     123    $self->open_xslt_pipe($output_file,$self->{'xslt_file'}); 
     124     
     125    my $outhandler = $self->{'xslt_writer'};  
     126    $self->output_xml_header($outhandler, "MARCXML", 1); 
     127    print $outhandler $self->get_top_metadata_list($doc_obj); 
     128    $self->output_xml_footer($outhandler,"MARCXML");   
     129    $self->close_xslt_pipe();  
     130    $self->{'short_doc_file'} = &FileUtils::filenameConcatenate ($doc_dir, "marc.xml");   
     131    } 
    104132 
    105     my $output_dir = $self->get_output_dir(); 
    106     &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir; 
    107      
    108     my $working_dir = &FileUtils::filenameConcatenate ($output_dir, $doc_dir);     
    109     &FileUtils::makeAllDirectories ($working_dir) unless -e $working_dir; 
    110133 
    111     my $output_file = &FileUtils::filenameConcatenate ($working_dir, "marc.xml"); 
    112   
    113     $self->open_xslt_pipe($output_file,$self->{'xslt_file'}); 
     134     # write out data to archiveinf-doc.db 
     135    if ($self->{'generate_databases'}) { 
     136    $self->store_output_info_reference($doc_obj);     
     137    $self->archiveinf_db($doc_obj);  
     138    } 
     139    if ($self->{'group'}){ 
     140    $self->{'gs_count'}++;  
     141    $self->{'group_position'}++; 
     142    } 
     143} 
    114144 
    115     my $outhandler = $self->{'xslt_writer'};  
    116  
    117     $self->output_xml_header($outhandler, "MARCXML", 1); 
    118     print $outhandler $self->get_top_metadata_list($doc_obj); 
    119     $self->output_xml_footer($outhandler,"MARCXML");   
    120     $self->close_xslt_pipe();  
    121  
    122     $self->{'short_doc_file'} = &FileUtils::filenameConcatenate ($doc_dir, "marc.xml");   
    123  
    124     $self->store_output_info_reference($doc_obj);               
    125 } 
    126145 
    127146# returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList> 
     
    154173    return unless $self->{'group'} and  $self->{buffered_output}; 
    155174 
    156     my $output_dir = $self->get_output_dir(); 
    157     &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir; 
     175    my $output_file = &FileUtils::filenameConcatenate($self->get_output_dir(), $self->{'short_doc_file'}); 
    158176 
    159     my $output_file = &FileUtils::filenameConcatenate($output_dir, "marc.xml"); 
    160   
    161177    $self->open_xslt_pipe($output_file,$self->{'xslt_file'}); 
    162178 
     
    175191} 
    176192 
     193 
    1771941;