Changeset 8504


Ignore:
Timestamp:
2004-11-10T11:14:18+13:00 (19 years ago)
Author:
chi
Message:

Modification of METS format in order to be compatible with GS3. Also, add some new methods for the use of DSpace.

File:
1 edited

Legend:

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

    r8502 r8504  
    286286 
    287287   
    288     my $filePath = $doc_Dir . '/doctxt.xml';
    289    
     288    #my $filePath = $doc_Dir . '/doctxt.xml';
     289
     290    my $filePath = 'doctxt.xml';
     291
    290292    #**output the fileSection details
    291293    my $all_text = '  <mets:fileGrp ID="FILEGROUP_PRELUDE' . $section_num . '">'. "\n";
     
    331333       my $escaped_value = &_escape_text($data->[1]);
    332334       if ($data->[0] eq "gsdlsourcefilename") {
    333           ($dirPath) = $escaped_value =~ m/^(.*)[\/\\][^\/\\]*$/; 
    334          
     335          ($dirPath) = $escaped_value =~ m/^(.*)[\/\\][^\/\\]*$/;
     336     
    335337      $all_text .= '  <mets:fileGrp ID="default">'."\n";
    336338          ++$fileID;
    337339          $all_text .= '    <mets:file MIMETYPE="text/xml" ID="default.'.$fileID.'">'. "\n";
    338           $all_text .= '      <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$data->[1].'" ID="default.'.$fileID.'" />'."\n";
    339 
     340       
     341      $all_text .= '      <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$data->[1].'" ID="default.'.$fileID.'" />'."\n";
     342     
    340343          $all_text .= "    </mets:file>\n";
    341344       }
     
    346349      my $assfilePath = $dirPath . '/'. $1;
    347350          ++$fileID;
     351
    348352      $all_text .= '    <mets:file MIMETYPE="'.$2.'" ID="default.'.$fileID. '">'. "\n";
    349353      $all_text .= '      <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$assfilePath.'" ID="default.'. $fileID.'" />'."\n";
     
    366370    $section="" unless defined $section;
    367371   
    368 
     372   
    369373    my $section_ptr=$self->_lookup_section($section);
    370374    return "" unless defined $section_ptr;
    371375
    372     #**output fileSection by sections
    373     my $section_num ="1". $section;
    374    
     376
     377    #***output fileSection by Sections
     378    my $section_num ="1". $section;
     379    my $dmd_num = $section_num;
     380
     381    #**output the dmdSection details 
     382    if ($section_num eq "1") {
     383    $dmd_num = "0";
     384    }
     385
    375386    #**output the StruMap details
    376387 
    377388    my $all_text = '  <mets:div ID="DS'. $section_num .'" TYPE="Section" ORDER="'.$$order_numref++.'" ORDERLABEL="'. $section_num .'" LABEL="';
    378     $all_text .= $section_num . '" DMDID="DM'.$section_num.'">'. "\n";
     389
     390    $all_text .= $section_num . '" DMDID="DM'.$dmd_num.'">'. "\n";
    379391   
    380392    $all_text .= '    <mets:fptr FILEID="FILEGROUP_PRELUDE'.$section_num.'" />'. "\n";
     
    442454    #***convert section number
    443455    my $section_num ="1". $section;
    444      
     456    my $dmd_num = $section_num;
     457
    445458    #**output the dmdSection details 
    446     my $all_text = '<mets:dmdSec ID="DM'.$section_num.'" GROUPID="'.$section_num.'">'. "\n";
    447     $all_text .= '  <mets:mdWrap MDType="gsdl" ID="'.$section_num.'">'."\n";
     459    if ($section_num eq "1") {
     460    $dmd_num = "0";
     461    }
     462    my $all_text = '<mets:dmdSec ID="DM'.$dmd_num.'" GROUPID="'.$section_num.'">'. "\n";
     463    $all_text .= '  <mets:mdWrap MDType="gsdl3" ID="'.$section_num.'">'."\n";
    448464    $all_text .= "    <mets:xmlData>\n";
    449465    foreach my $data (@{$section_ptr->{'metadata'}}){
    450466       my $escaped_value = &_escape_text($data->[1]);
    451        $all_text .= '      <gsdl:Metadata name="'. $data->[0].'">'. $escaped_value. "</gsdl:Metadata>\n";
    452     }
     467       $all_text .= '      <gsdl3:Metadata name="'. $data->[0].'">'. $escaped_value. "</gsdl3:Metadata>\n";
     468       if ($data->[0] eq "dc.Title") {
     469       $all_text .= '      <gsdl3:Metadata name="Title">'. $escaped_value."</gsdl3:Metadata>\n";
     470       }
     471    }
     472   
    453473    $all_text .= "    </mets:xmlData>\n";
    454474    $all_text .= "  </mets:mdWrap>\n";
     
    471491}
    472492
     493#*** print out DSpace dublin_core metadata section
     494sub output_dspace_section {
     495    my $self = shift (@_);
     496    my ($handle, $section) = @_;
     497
     498    my $section_ptr = $self->_lookup_section ($section);
     499    return "" unless defined $section_ptr;
     500
     501    my $all_text = "<Section>\n";
     502    $all_text .= "  <Description>\n";
     503   
     504    # output metadata
     505    foreach my $data (@{$section_ptr->{'metadata'}}) {
     506    my $escaped_value = &_escape_text($data->[1]);
     507    $all_text .= '    <Metadata name="' . $data->[0] . '">' . $escaped_value . "</Metadata>\n";
     508    }
     509
     510    $all_text .= "  </Description>\n";
     511    $all_text .=  "</Section>\n";
     512
     513    # make sure no nasty control characters have snuck through
     514    # (XML::Parser will barf on anything it doesn't consider to be
     515    # valid UTF-8 text, including things like \c@, \cC etc.)
     516    $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
     517
     518    return $all_text;
     519}
    473520
    474521#*** print out doctxt.xml file
     
    491538    print $handle "<mets:fileSec>\n";
    492539    print $handle $self->buffer_mets_fileSection_section_xml($section,$doc_Dir);
     540
    493541    #***print out the whole fileSection
    494542    print $handle $self->buffer_mets_fileWhole_section_xml($section);
     
    504552}
    505553
     554#*** print out dublin_core.xml file
     555sub output_dc_section {
     556    my $self = shift(@_);
     557    my ($handle, $section, $doc_Dir) = @_;
     558   
     559    #***print out the dublin_core
     560    $section="" unless defined $section;
     561   
     562    my $section_ptr=$self->_lookup_section($section);
     563    return "" unless defined $section_ptr;
     564    my $all_text="";
     565    foreach my $data (@{$section_ptr->{'metadata'}}){
     566    my $escaped_value = &_escape_text($data->[1]);
     567    if ($data->[0]=~ /^dc/) {
     568        #$all_text .= '   <dcvalue element="'. $data->[0].'" qualifier="#####">'. $escaped_value. "</dcvalue>\n";
     569        $all_text .= '   <dcvalue element="'. $data->[0].'">'. $escaped_value. "</dcvalue>\n";
     570    }
     571    }
     572    if ($all_text eq "") {
     573    $all_text .= "   There is no Dublin Core metatdata in this document\n";
     574    }   
     575    $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
     576
     577    print $handle $all_text;
     578}
    506579
    507580# look up the reference to the a particular section
     
    537610    my $hashfile_exe = &util::filename_cat($ENV{'GSDLHOME'},"bin",
    538611                       $ENV{'GSDLOS'},"hashfile$osexe");
     612
    539613    my $result = "NULL";
    540614   
     
    547621    print STDERR "doc::_calc_OID $hashfile_exe could not be found\n";
    548622    }
    549 
    550623    return "HASH$result";
    551624}
     
    557630    my $self = shift (@_);
    558631    my ($OID) = @_;
    559 
     632   
    560633    # if an OID wasn't provided claculate one
    561634    if (!defined $OID) {
     
    572645        # cos its quicker
    573646        my $filename = $self->get_filename_for_hashing();
     647
    574648        if (defined($filename) && -e $filename) {
    575649        $OID = $self->_calc_OID ($filename);
     
    583657            close (OUTFILE);
    584658        }
    585        
    586659        $OID = $self->_calc_OID ($filename);
    587660        &util::rm ($filename);
     
    11881261    # remove all associated files with the same name
    11891262    $self->delete_assoc_file ($assoc_filename);
    1190 
     1263   
    11911264    push (@{$self->{'associated_files'}},
    11921265      [$real_filename, $assoc_filename, $mime_type, $section]);
Note: See TracChangeset for help on using the changeset viewer.