Ignore:
Timestamp:
2004-08-06T16:34:02+12:00 (20 years ago)
Author:
chi
Message:

Saving of documents (in archive format) extended to generate METS format
as alternative to GreenstoneArchive (GA) format. Controlled through
'import.pl -saveas METS ...'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/docsave.pm

    r3834 r7902  
    9696    my $OID = $doc_obj->get_OID();
    9797    $OID = "NULL" unless defined $OID;
    98    
     98
     99
    99100    # get document's directory
    100101    my $doc_dir = $self->get_doc_dir ($OID);
    101    
     102     
     103   
    102104    # copy all the associated files, add this information as metadata
    103105    # to the document
     
    106108    my $doc_file
    107109        = &util::filename_cat ($self->{'archive_dir'}, $doc_dir, "doc.xml");
    108     my $short_doc_file = &util::filename_cat ($doc_dir, "doc.xml");
    109    
     110     
     111        #***define doctxt.xml file
     112        my $doc_txt_file
     113            = &util::filename_cat ($self->{'archive_dir'}, $doc_dir,"doctxt.xml");
     114    my $working_dir
     115            =&util::filename_cat ($self->{'archive_dir'}, $doc_dir);
     116       
     117        #***define docmets.xmlfile
     118        my $doc_mets_file
     119            = &util::filename_cat ($self->{'archive_dir'},$doc_dir, "docmets.xml");
     120 
     121        my $short_doc_file = &util::filename_cat ($doc_dir, "doc.xml");
     122    #my $short_txt_doc_file=&util::filename_cat ($doc_dir, "doctxt.xml");
     123        my $short_mets_doc_file=&util::filename_cat ($doc_dir, "docmets.xml");
     124   
     125
    110126    if (!open (OUTDOC, ">$doc_file")) {
    111         print $outhandle "docsave::process could not write to file $doc_file\n";
     127        print $outhandle "docsave::process could not write to file $doc_file\n";
    112128        return;
    113129    }
     
    117133    $doc_obj->output_section('docsave::OUTDOC', $doc_obj->get_top_section());
    118134    $self->output_xml_footer('docsave::OUTDOC');
    119     close OUTDOC;
     135
     136        #***save the document without metadata:doctxt.xml: Chi-Yu Huang
     137
     138    if (!open(OUTDOC_TXT, ">$doc_txt_file")){
     139            print $outhandle "docsave::process could not write to file $doc_mets_file\n";
     140            return;
     141        }
     142
     143        $self->output_txt_xml_header('docsave::OUTDOC_TXT');
     144        $doc_obj->output_txt_section('docsave::OUTDOC_TXT', $doc_obj->get_top_section());
     145    #$self->output_txt_xml_footer('docsave::OUTDOC_TXT');
     146               
     147        #***Convert doctxt.xml file to docmets.xml: Chi-Yu Huang
     148        if (!open(OUTDOC_METS,">$doc_mets_file")){
     149        print $outhandle "docsave::process could not write to file $doc_mets_file\n";
     150            return;
     151    }
     152         
     153        $self->output_mets_xml_header('docsave::OUTDOC_METS', $OID);
     154        $doc_obj->output_mets_section('docsave::OUTDOC_METS',$doc_obj->get_top_section(), $working_dir);
     155        $self->output_mets_xml_footer('docsave::OUTDOC_METS');
     156
     157        close OUTDOC;
     158        close OUTDOC_TXT;
     159    close OUTDOC_METS;
    120160
    121161    if ($self->{'gzip'}) {
     
    131171
    132172    # do the sortmeta thing
    133     my ($metadata);
    134     if (defined ($self->{'sortmeta'})) {
     173    my ($metadata); if (defined ($self->{'sortmeta'})) {
    135174        $metadata = $doc_obj->get_metadata_element ($doc_obj->get_top_section(), $self->{'sortmeta'});
    136175    }
    137176
    138177    # store reference in the archive_info
    139     $self->{'archive_info'}->add_info($OID, $short_doc_file, $metadata);
    140     }
    141 }
    142 
     178    if ($self->{'saveas'} eq "METS"){
     179        $self->{'archive_info'}->add_info($OID, $short_mets_doc_file, $metadata);
     180    } else {
     181        $self->{'archive_info'}->add_info($OID, $short_doc_file, $metadata);
     182    }
     183    }
     184}
     185
     186     
    143187sub group_process {
    144188    my $self = shift (@_);
     
    283327
    284328    # store reference in the archive_info
    285     $self->{'archive_info'}->add_info($OID, $short_doc_file);
    286 
     329    if ($self->{'saveas'} eq "METS"){
     330    $self->{'archive_info'}->add_info($OID, $short_mets_doc_file);
     331    } else {
     332    $self->{'archive_info'}->add_info($OID, $short_doc_file);
     333    }
     334   
    287335    return 1;
    288336}
     
    292340    my ($handle) = @_;
    293341
     342    print $handle '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
     343   
     344    print $handle '<!DOCTYPE Archive SYSTEM "http://greenstone.org/dtd/Archive/1.0/Archive.dtd">' . "\n";
     345    print $handle "<Archive>\n";
     346}
     347
     348sub output_xml_footer {
     349    my $self = shift (@_);
     350    my ($handle) = @_;
     351
     352    print $handle "</Archive>\n";
     353}
     354
     355sub output_txt_xml_header{
     356    my $self = shift (@_);
     357    my ($handle) = @_;
    294358    print $handle '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
    295359    print $handle '<!DOCTYPE Archive SYSTEM "http://greenstone.org/dtd/Archive/1.0/Archive.dtd">' . "\n";
    296     print $handle "<Archive>\n";
    297 }
    298 
    299 sub output_xml_footer {
    300     my $self = shift (@_);
    301     my ($handle) = @_;
    302 
    303     print $handle "</Archive>\n";
     360}
     361
     362sub output_txt_xml_footer{
     363    my $self = shift(@_);
     364    my ($handle) = @_;
     365    print $handle "<the end of the file>\n";
     366}
     367
     368sub output_mets_xml_header(){
     369    my $self = shift(@_);
     370    my ($handle, $OID) = @_;
     371    print $handle '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
     372    print $handle '<!DOCTYPE Archive SYSTEM "http://greenstone.org/dtd/Archive/1.0/Archive.dtd">' . "\n";
     373    print $handle '<mets:mets OBJID="'. $OID. ':2">' . "\n";
     374}
     375
     376sub output_mets_xml_footer() {
     377    my $self = shift(@_);
     378    my ($handle) = @_;
     379    print $handle '</mets:mets>' . "\n";
    304380}
    305381
    3063821;
     383
     384
     385
Note: See TracChangeset for help on using the changeset viewer.