Ignore:
Timestamp:
2008-06-05T09:29:32+12:00 (16 years ago)
Author:
kjdon
Message:

plugin overhaul: plugins renamed to xxPlugin, and in some cases the names are made more sensible. They now use the new base plugins. Hopefully we have better code reuse. Some of the plugins still need work done as I didn't want to spend another month doing this before committing it. Alos, I haven't really tested anything yet...

File:
1 edited

Legend:

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

    r15865 r15872  
    11###########################################################################
    22#
    3 # NULPlug.pm -- Plugin for dummy (.nul) files
     3# NulPlugin.pm -- Plugin for dummy (.nul) files
    44#
    55# A component of the Greenstone digital library software from the New
     
    2626###########################################################################
    2727
    28 # NULPlug - a plugin for dummy files
     28# NulPlugin - a plugin for dummy files
    2929
    3030# This is a simple Plugin for importing dummy files, along with
     
    3535# databases
    3636
    37 package NULPlug;
     37package NulPlugin;
    3838
    39 use BasPlug;
     39use BasePlugin;
    4040
    4141use strict;
     
    4343
    4444sub BEGIN {
    45     @NULPlug::ISA = ('BasPlug');
     45    @NulPlugin::ISA = ('BasePlugin');
    4646}
    4747
    4848my $arguments =
    4949    [ { 'name' => "process_exp",
    50     'desc' => "{BasPlug.process_exp}",
     50    'desc' => "{BasePlugin.process_exp}",
    5151    'type' => "regexp",
    5252    'reqd' => "no",
    5353    'deft' => &get_default_process_exp() },
    5454      { 'name' => "assoc_field",
    55     'desc' => "{NULPlug.assoc_field}",
     55    'desc' => "{NulPlugin.assoc_field}",
    5656    'type' => "string",
    57     'deft' => "",
     57    'deft' => "null_file",
    5858    'reqd' => "no" },
    5959      { 'name' => "add_metadata_as_text",
    60     'desc' => "{NULPlug.add_metadata_as_text}",
     60    'desc' => "{NulPlugin.add_metadata_as_text}",
    6161    'type' => "flag" },
    6262      { 'name' => "remove_namespace_for_text",
    63     'desc' => "{NULPlug.remove_namespace_for_text}",
     63    'desc' => "{NulPlugin.remove_namespace_for_text}",
    6464    'type' => "flag" }
    6565      ];
    6666
    67 my $options = { 'name'     => "NULPlug",
    68         'desc'     => "{NULPlug.desc}",
     67my $options = { 'name'     => "NulPlugin",
     68        'desc'     => "{NulPlugin.desc}",
    6969        'abstract' => "no",
    7070        'inherits' => "yes",
     
    7777    push(@$pluginlist, $class);
    7878
    79     if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
    80     if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
     79    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
     80    push(@{$hashArgOptLists->{"OptList"}},$options);
    8181
    82     my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
     82    my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
    8383   
    8484    return bless $self, $class;
     
    8989}
    9090
    91 # The NULPlug read() function. This function does all the right
    92 # things to make general options work for a given plugin.  NULPlug
    93 # overrides read() because there is no need to read the actual text of
    94 # the file in, because the contents of the file is not text...
    95 #
    96 #
    97 # Return number of files processed, undef if can't process
    98 #
    99 # Note that $base_dir might be "" and that $file might include directories
     91# NulPlugin specific processing of doc_obj.
     92sub process {
     93    my $self = shift (@_);
     94    my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
     95   
     96    my $topsection = $doc_obj->get_top_section();
     97     
     98    my $assoc_field = $self->{'assoc_field'}; # || "null_file"; TODO, check this
     99    $doc_obj->add_metadata ($topsection, $assoc_field, $file);
    100100
    101 sub read {
    102     my $self = shift (@_);
    103     my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
    104 
    105     my $outhandle = $self->{'outhandle'};
    106 
    107     #check for associate_ext, blocking etc
    108     my ($block_status,$filename) = $self->read_block(@_);   
    109     return $block_status if ((!defined $block_status) || ($block_status==0));
    110 
    111     print STDERR "<Processing n='$file' p='NULPlug'>\n" if ($gli);
    112     print $outhandle "NULPlug processing \"$filename\"\n"
    113         if $self->{'verbosity'} > 1;
    114 
    115     #if there's a leading directory name, eat it...
    116     $file =~ s/^.*[\/\\]//;
    117    
    118     # create a new document
    119     my $doc_obj = new doc ($filename, "indexed_doc");
    120     my $top_section = $doc_obj->get_top_section();
    121 
    122     $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});   
    123     #$doc_obj->set_OIDtype ("incremental");
    124     $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}");
    125     $doc_obj->add_metadata($top_section, "Source", $file); # set the filename as Source metadata to be consistent with other plugins
    126 
    127     $doc_obj->add_utf8_metadata($top_section, "FileSize", (-s $filename));
    128 
    129     # the metadata NoText is used to suppress the dummy text 'This document has no text.'
    130     $doc_obj->add_metadata ($top_section, "NoText",    "1");
    131 
    132     my $assoc_field = $self->{'assoc_field'} || "null_file";
    133     $doc_obj->add_metadata ($top_section, $assoc_field, $file);
    134    
    135      if ($self->{'cover_image'}) {
    136     $self->associate_cover_image($doc_obj, $filename);
    137     }
    138 
    139     # include any metadata passed in from previous plugins
    140     my $section = $doc_obj->get_top_section();
    141     $self->extra_metadata ($doc_obj, $section, $metadata);
    142    
    143101    # format the metadata passed in (presumably from metadata.xml)
    144102    my $text = "";
    145103    if ($self->{'add_metadata_as_text'}) {
    146104    $text = &metadatautil::format_metadata_as_table($metadata, $self->{'remove_namespace_for_text'});
     105    $doc_obj->add_utf8_text($topsection, $text);
    147106    } else {
    148     #create an empty text string so we don't break downstream plugins
    149     $text = &gsprintf::lookup_string("{BasPlug.dummy_text}",1);
     107    $self->add_dummy_text($doc_obj, $topsection);
    150108    }
    151     $self->title_fallback($doc_obj,$section,$file);
    152    
    153     # do plugin specific processing of doc_obj
    154     unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
    155     print STDERR "<ProcessingError n='$file'>\n" if ($gli);
    156     return -1;
    157     }
    158 
    159     # do any automatic metadata extraction
    160     $self->auto_extract_metadata ($doc_obj);
    161 
    162     # add an OID
    163     $doc_obj->set_OID();
    164     $doc_obj->add_utf8_text($section, $text);
    165    
    166     # process the document
    167     $processor->process($doc_obj);
    168 
    169     $self->{'num_processed'} ++;
    170     return 1;
    171 }
    172 
    173 
    174 # NULPlug processing of doc_obj.  In practice we don't need to do
    175 # anything here because the read function takes care of everything.
    176 
    177 sub process {
    178     my $self = shift (@_);
    179     my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
    180     my $outhandle = $self->{'outhandle'};
    181109   
    182110    return 1;
Note: See TracChangeset for help on using the changeset viewer.