Ignore:
Timestamp:
2008-08-27T20:40:20+12:00 (16 years ago)
Author:
kjdon
Message:

OID generation modifications: OIDtype and OIDmetadata options now available for plugins as well as import. OIDtype for plugins defaults to auto - if set to auto, then use the values from import. All plugins now call self->add_OID instead of doc_obj->set_OID. This sets the doc_obj OIDtype so that doesn't need to be donein other places any more. all plugins have the get_oid_hash_type method - normally returns hash_on_file, but can be overridden to return hash_on_ga_xml for those plugins that don't want hashing on file (MP3,OggVorbis...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/plugins/BasePlugin.pm

    r16997 r17026  
    7979
    8080our $oidtype_list =
    81     [ { 'name' => "hash",
     81    [ { 'name' => "auto",
     82    'desc' => "{BasePlugin.OIDtype.auto}" },
     83      { 'name' => "hash",
    8284        'desc' => "{import.OIDtype.hash}" },
    8385      { 'name' => "assigned",
     
    116118    'list' => $oidtype_list,
    117119    # leave default empty so we can tell if its been set or not - if not set will use option from import.pl
    118     #'deft' => "hash",
     120    'deft' => "auto",
    119121    'reqd' => "no",
    120122    'modegli' => "2" },
     
    282284    my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
    283285
     286    if ($self->{'OIDtype'} eq "auto") {
     287    # hasn't been set in the plugin, use the processor values
     288    $self->{'OIDtype'} = $processor->{'OIDtype'};
     289    $self->{'OIDmetadata'} = $processor->{'OIDmetadata'};
     290    }
     291    if ($self->{'OIDtype'} eq "hash") {
     292    # should we hash on the file or on the doc xml??
     293    $self->{'OIDtype'} = $self->get_oid_hash_type();
     294    if ($self->{'OIDtype'} !~ /^(hash_on_file|hash_on_ga_xml)$/) {
     295        $self->{'OIDtype'} = "hash_on_file";
     296    }
     297    }
    284298}
    285299
     
    295309
    296310    my ($self) = @_;
     311}
     312
     313# default hashing type is to hash on the original file (or converted file)
     314# override this to return hash_on_ga_xml for filetypes where hashing on the
     315# file is no good eg video
     316sub get_oid_hash_type {
     317
     318    my $self = shift (@_);
     319
     320    return "hash_on_file";
    297321}
    298322
     
    715739    my ($doc_obj, $filename_no_path, $file_encoding) = @_;
    716740
     741
    717742    my $top_section = $doc_obj->get_top_section();
    718743   
     
    729754    $doc_obj->set_utf8_metadata_element($top_section, "SourceFile", $filemeta);
    730755}
    731      
     756   
     757# this should be called by all plugins to set the oid of the doc obj, rather
     758# than calling doc_obj->set_OID directly
    732759sub add_OID {
    733760    my $self = shift (@_); 
    734761    my ($doc_obj) = @_;
    735762
    736     # See if a metadata field is specified as the field
    737     if ((defined $self->{'use_as_doc_identifier'}) && ($self->{'use_as_doc_identifier'} ne "")) {
    738     my $metadata_doc_id = $self->{'use_as_doc_identifier'};
    739 
    740     # Consider "tidying" up metadata_doc_id to be something
    741     # suitable in a URL
    742     # Could even support a user specified plugin RE for this.
    743 
    744     my $top_section = $doc_obj->get_top_section();
    745     my $oid = $doc_obj->get_metadata_element($top_section,$metadata_doc_id);
    746         $doc_obj->set_OID($oid);
    747     }
    748     # See if there is a plugin-specific set_OID function...
    749     elsif (defined ($self->can('set_OID'))) {
    750     # it will need $doc_obj to set the Identifier metadata...
    751     $self->set_OID(@_); # pass through any extra arguments supplied
    752     } else {
     763    $doc_obj->set_OIDtype($self->{'OIDtype'}, $self->{'OIDmetadata'});
     764
     765    # see if there is a plugin specific set_OID function
     766    if (defined ($self->can('set_OID'))) {
     767    $self->set_OID(@_); # pass through doc_obj and any extra arguments
     768    }
     769    else {
    753770    # use the default set_OID() in doc.pm
    754771    $doc_obj->set_OID();
    755772    }
    756 }
    757 
    758 
    759 
     773
     774}
     775 
    760776# The BasePlugin read_into_doc_obj() function. This function does all the
    761777# right things to make general options work for a given plugin.  It doesn't do anything with the file other than setting reads in
     
    791807    my $top_section = $doc_obj->get_top_section();
    792808
    793     # this should look at the plugin option too...
    794     $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});   
    795809    $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}");
    796810    $doc_obj->add_utf8_metadata($top_section, "FileSize", (-s $filename_full_path));
Note: See TracChangeset for help on using the changeset viewer.