Changeset 24951

Show
Ignore:
Timestamp:
16.01.2012 17:47:14 (8 years ago)
Author:
ak19
Message:

All perlcode that accesses extrametakeys, extrametadata, extrametafile data structures has been moved into a new perl module called extrametautil.pm. The next step will be to ensure that the file_regexes used to index into these data structures are consistent (using consistent slashes, like URL style slashes).

Location:
main/trunk/greenstone2/perllib
Files:
1 added
8 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/DSpacePlugin.pm

    r24355 r24951  
    4747package DSpacePlugin; 
    4848 
     49use extrametautil; 
    4950use ReadTextFile; 
    5051use plugin; 
     
    298299    } 
    299300    } 
    300     push(@$extrametakeys,$file_re); 
     301    &extrametautil::addmetakey($extrametakeys, $file_re); 
    301302 
    302303    # See Format's Extent section in http://dublincore.org/documents/usageguide/qualifiers.shtml 
     
    331332    } 
    332333     
    333     $extrametadata->{$file_re} = $self->{'saved_metadata'}; 
     334    &extrametautil::setmetadata($extrametadata, $file_re, $self->{'saved_metadata'}); 
    334335 
    335336    return 1; 
  • main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm

    r24932 r24951  
    3030package DirectoryPlugin; 
    3131 
     32use extrametautil; 
    3233use PrintInfo; 
    3334use plugin; 
     
    443444        my $extrakeys_md  = $ek->{'md'}; 
    444445        my $extrakeys_mf  = $ek->{'mf'}; 
    445         push(@extrametakeys,$extrakeys_re); 
    446         $extrametadata{$extrakeys_re} = $extrakeys_md; 
    447         $extrametafile{$extrakeys_re} = $extrakeys_mf; 
     446        &extrametautil::addmetakey(\@extrametakeys, $extrakeys_re); 
     447        &extrametautil::setmetadata(\%extrametadata, $extrakeys_re, $extrakeys_md); 
     448        &extrametautil::setmetafile(\%extrametafile, $extrakeys_re, $extrakeys_mf); 
    448449        } 
    449450        delete($self->{'subdir_extrametakeys'}->{$local_dirname}); 
     
    489490    my $ek_non_re = &util::unregex_filename($ek); 
    490491    if ($ek_non_re =~ m/$dirsep_re/) { # specifies at least one directory 
    491         my $md = $extrametadata{$ek}; 
    492         my $mf = $extrametafile{$ek}; 
     492        my $md = &extrametautil::getmetadata(\%extrametadata, $ek); 
     493        my $mf = &extrametautil::getmetafile(\%extrametafile, $ek); 
    493494 
    494495        my $subdir_extrametakeys = $self->{'subdir_extrametakeys'}; 
     
    496497        my $subdir_rec = { 're' => $subdir_re, 'md' => $md, 'mf' => $mf }; 
    497498 
    498         # when its looked up, it must be relative to the base dir 
     499        # when it's looked up, it must be relative to the base dir 
    499500        push(@{$subdir_extrametakeys->{"$local_dirname$extrakey_dir"}},$subdir_rec); 
    500501        #push(@{$subdir_extrametakeys->{"$extrakey_dir"}},$subdir_rec); 
     
    606607            print $outhandle "File \"$subfile\" matches filespec \"$filespec\"\n"  
    607608            if ($verbosity > 2); 
    608             my $mdref = $extrametadata{$filespec}; 
    609             my $mfref = $extrametafile{$filespec}; 
     609            my $mdref = &extrametautil::getmetadata(\%extrametadata, $filespec); 
     610            my $mfref = &extrametautil::getmetafile(\%extrametafile, $filespec); 
    610611 
    611612            # Add the list files where the metadata came from 
  • main/trunk/greenstone2/perllib/plugins/EmbeddedMetadataPlugin.pm

    r24796 r24951  
    2929 
    3030use BasePlugin; 
     31use extrametautil; 
    3132 
    3233use Encode; 
     
    325326 
    326327    # Protect windows directory chars \ 
    327     $file = &util::filename_to_regex($file); 
     328    $file = &util::filename_to_regex($file); ####  
    328329     
    329330    # Associate the metadata now 
    330331 
    331     if (defined $extrametadata->{$file}) { 
     332    if (defined &extrametautil::getmetadata($extrametadata, $file)) { 
    332333    print STDERR "\n****  Need to merge new metadata with existing stored metadata: file = $file\n" if $verbosity > 2; 
    333334 
    334     my $file_metadata_table =     $extrametadata->{$file}; 
     335    my $file_metadata_table = &extrametautil::getmetadata($extrametadata, $file); 
    335336 
    336337    foreach my $metaname (keys %exif_metadata) { 
     
    342343    } 
    343344    else { 
    344     $extrametadata->{$file} = \%exif_metadata; 
    345     push(@$extrametakeys, $file); 
     345    &extrametautil::setmetadata($extrametadata, $file, \%exif_metadata); 
     346    &extrametautil::addmetakey($extrametakeys, $file); 
    346347    } 
    347348 
  • main/trunk/greenstone2/perllib/plugins/LOMPlugin.pm

    r24548 r24951  
    3232package LOMPlugin; 
    3333 
     34use extrametautil; 
    3435use ReadTextFile; 
    3536use MetadataPass; 
     
    168169    $self->{'lom_srcdoc'} = undef; # reset for next file to be processed 
    169170 
    170     push(@$extrametakeys,$file_re); 
    171     $extrametadata->{$file_re} = $self->{'saved_metadata'}; 
     171    &extrametautil::addmetakey($extrametakeys, $file_re); 
     172    &extrametautil::setmetadata($extrametadata, $file_re, $self->{'saved_metadata'}); 
    172173    if (defined $lom_srcdoc) { 
    173174    # copied from oaiplugin 
    174     if (!defined $extrametafile->{$file_re}) { 
    175         $extrametafile->{$file_re} = {}; 
     175    if (!defined &extrametautil::getmetafile($extrametafile, $file_re)) { 
     176        &extrametautil::setmetafile($extrametafile, $file_re, {}); 
    176177    } 
    177178     #maps the file to full path 
    178     $extrametafile->{$file_re}->{$file} = $filename_full_path; 
     179    &extrametautil::setmetafile_for_named_file($extrametafile, $file_re, $file, $filename_full_path); 
    179180    } 
    180181     
  • main/trunk/greenstone2/perllib/plugins/MetadataCSVPlugin.pm

    r24756 r24951  
    3333use strict; 
    3434no strict 'refs'; 
     35 
     36use extrametautil; 
    3537use multiread; 
    3638 
     
    205207    $csv_line_filename = &util::filename_to_regex($csv_line_filename); 
    206208 
    207     $extrametadata->{$csv_line_filename} = \%csv_line_metadata; 
    208     push(@$extrametakeys, $csv_line_filename); 
     209    &extrametautil::setmetadata($extrametadata, $csv_line_filename, \%csv_line_metadata); 
     210    &extrametautil::addmetakey($extrametakeys, $csv_line_filename); 
    209211    # record which file the metadata came from  
    210     if (!defined $extrametafile->{$csv_line_filename}) { 
    211         $extrametafile->{$csv_line_filename} = {}; 
     212    if (!defined &extrametautil::getmetafile($extrametafile, $csv_line_filename)) { 
     213        &extrametautil::setmetafile($extrametafile, $csv_line_filename, {}); 
    212214    } 
    213215    # maps the file to full path 
    214     $extrametafile->{$csv_line_filename}->{$file} = $filename; 
     216    &extrametautil::setmetafile_for_named_file($extrametafile, $csv_line_filename, $file, $filename); 
    215217    } 
    216218} 
  • main/trunk/greenstone2/perllib/plugins/MetadataXMLPlugin.pm

    r24060 r24951  
    9393 
    9494use BasePlugin; 
     95use extrametautil; 
    9596use util; 
    9697use metadatautil; 
     
    327328    if ($element eq "FileSet") { 
    328329    foreach my $target (@{$self->{'saved_targets'}}) { 
    329         my $file_metadata = $self->{'metadataref'}->{$target}; 
     330        my $file_metadata = &extrametautil::getmetadata($self->{'metadataref'}, $target); 
    330331        my $saved_metadata = $self->{'saved_metadata'}; 
    331332 
    332333        if (!defined $file_metadata) { 
    333         $self->{'metadataref'}->{$target} = $saved_metadata; 
     334        &extrametautil::setmetadata($self->{'metadataref'}, $target, $saved_metadata); 
    334335 
    335336        # not had target before 
    336         push (@{$self->{'metakeysref'}}, $target); 
     337        &extrametautil::addmetakey($self->{'metakeysref'}, $target); 
    337338        } 
    338339        else { 
     
    346347        my $filename = $self->{'metadata-filename'}; 
    347348 
    348         if (!defined $self->{'metafileref'}->{$target}) { 
    349             $self->{'metafileref'}->{$target} = {}; 
     349        if (!defined &extrametautil::getmetafile($self->{'metafileref'}, $target)) { 
     350            &extrametautil::setmetafile($self->{'metafileref'}, $target, {}); 
    350351        } 
    351352 
    352         $self->{'metafileref'}->{$target}->{$file} = $filename 
     353        &extrametautil::setmetafile_for_named_file($self->{'metafileref'}, $target, $file, $filename); 
    353354    } 
    354355    } 
  • main/trunk/greenstone2/perllib/plugins/OAIMetadataXMLPlugin.pm

    r23212 r24951  
    3333no strict 'refs'; 
    3434 
     35use extrametautil; 
    3536use MetadataXMLPlugin; 
    3637 
     
    125126  { 
    126127    # Don't harvest file sets that don't have dc.Identifier set, "dc.Identifier" is usde as the key between Greenstone and OAI Server! 
    127     next if (!defined($extrametadata->{$one_file}->{"dc.Identifier"}->[0]) || $extrametadata->{$one_file}->{"dc.Identifier"}->[0] eq ""); 
     128    my $dc_identifier = &extrametautil::getmetadata_for_named_pos($extrametadata, $one_file, "dc.Identifier", 0); 
     129    next if (!defined($dc_identifier) || $dc_identifier eq ""); 
    128130 
    129131    #======================================================================# 
     
    131133    #======================================================================# 
    132134    # The dc.Identifier has to be the same as the OAI record identifier  
    133     my $oai_identifier = $extrametadata->{$one_file}->{"dc.Identifier"}->[0]; 
     135    my $oai_identifier = $dc_identifier; 
    134136     
    135137    # Now, let's get the OAI metadata 
     
    195197        # This might need change over once they update the Koha OAI server 
    196198        $value =~ s/\/opac\/opac\-detail\.pl\?bib\=/\/catalogue\/detail\.pl\?biblionumber\=/; 
    197       } 
    198       $extrametadata->{$one_file}->{$field_name} = [] if (!defined($extrametadata->{$one_file}->{$field_name})); 
    199       push(@{$extrametadata->{$one_file}->{$field_name}}, $value);  
     199      }    
     200       
     201      &extrametautil::setmetadata_for_named_metaname($extrametadata, $one_file, $field_name, []) if (!defined (&extrametautil::getmetadata_for_named_metaname($extrametadata, $one_file, $field_name))); 
     202      &extrametautil::addmetadata_for_named_metaname($extrametadata, $one_file, $field_name, $value); 
    200203    } 
    201204    #======================================================================# 
  • main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm

    r24547 r24951  
    2727package OAIPlugin; 
    2828 
     29use extrametautil; 
    2930use unicode; 
    3031use util; 
     
    256257    # extrametadata keys should be regular expressions 
    257258    $filename_for_metadata = &util::filename_to_regex($filename_for_metadata); 
    258     $extrametadata->{$filename_for_metadata} = $new_metadata; 
    259     push(@$extrametakeys, $filename_for_metadata); 
    260     if ($srcdoc_exists) { 
    261     if (!defined $extrametafile->{$filename_for_metadata}) { 
    262         $extrametafile->{$filename_for_metadata} = {}; 
     259    &extrametautil::setmetadata($extrametadata, $filename_for_metadata, $new_metadata); 
     260    &extrametautil::addmetakey($extrametakeys, $filename_for_metadata); 
     261    if ($srcdoc_exists) {    
     262    if (!defined &extrametautil::getmetafile($extrametafile, $filename_for_metadata)) { 
     263        &extrametautil::setmetafile($extrametafile, $filename_for_metadata, {}); 
    263264    } 
    264265     #maps the file to full path 
    265     $extrametafile->{$filename_for_metadata}->{$file} = $filename_full_path; 
     266    &extrametautil::setmetafile_for_named_file($extrametafile, $filename_for_metadata, $file, $filename_full_path); 
     267     
    266268    } 
    267269    return 1;