Changeset 15872 for gsdl/trunk/perllib/plugins/NulPlugin.pm
- Timestamp:
- 2008-06-05T09:29:32+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/NulPlugin.pm
r15865 r15872 1 1 ########################################################################### 2 2 # 3 # N ULPlug.pm -- Plugin for dummy (.nul) files3 # NulPlugin.pm -- Plugin for dummy (.nul) files 4 4 # 5 5 # A component of the Greenstone digital library software from the New … … 26 26 ########################################################################### 27 27 28 # N ULPlug- a plugin for dummy files28 # NulPlugin - a plugin for dummy files 29 29 30 30 # This is a simple Plugin for importing dummy files, along with … … 35 35 # databases 36 36 37 package N ULPlug;37 package NulPlugin; 38 38 39 use Bas Plug;39 use BasePlugin; 40 40 41 41 use strict; … … 43 43 44 44 sub BEGIN { 45 @N ULPlug::ISA = ('BasPlug');45 @NulPlugin::ISA = ('BasePlugin'); 46 46 } 47 47 48 48 my $arguments = 49 49 [ { 'name' => "process_exp", 50 'desc' => "{Bas Plug.process_exp}",50 'desc' => "{BasePlugin.process_exp}", 51 51 'type' => "regexp", 52 52 'reqd' => "no", 53 53 'deft' => &get_default_process_exp() }, 54 54 { 'name' => "assoc_field", 55 'desc' => "{N ULPlug.assoc_field}",55 'desc' => "{NulPlugin.assoc_field}", 56 56 'type' => "string", 57 'deft' => " ",57 'deft' => "null_file", 58 58 'reqd' => "no" }, 59 59 { 'name' => "add_metadata_as_text", 60 'desc' => "{N ULPlug.add_metadata_as_text}",60 'desc' => "{NulPlugin.add_metadata_as_text}", 61 61 'type' => "flag" }, 62 62 { 'name' => "remove_namespace_for_text", 63 'desc' => "{N ULPlug.remove_namespace_for_text}",63 'desc' => "{NulPlugin.remove_namespace_for_text}", 64 64 'type' => "flag" } 65 65 ]; 66 66 67 my $options = { 'name' => "N ULPlug",68 'desc' => "{N ULPlug.desc}",67 my $options = { 'name' => "NulPlugin", 68 'desc' => "{NulPlugin.desc}", 69 69 'abstract' => "no", 70 70 'inherits' => "yes", … … 77 77 push(@$pluginlist, $class); 78 78 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); 81 81 82 my $self = new Bas Plug($pluginlist, $inputargs, $hashArgOptLists);82 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists); 83 83 84 84 return bless $self, $class; … … 89 89 } 90 90 91 # The NULPlug read() function. This function does all the right92 # 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 process98 # 99 # Note that $base_dir might be "" and that $file might include directories 91 # NulPlugin specific processing of doc_obj. 92 sub 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); 100 100 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 etc108 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 document119 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 plugins126 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 plugins140 my $section = $doc_obj->get_top_section();141 $self->extra_metadata ($doc_obj, $section, $metadata);142 143 101 # format the metadata passed in (presumably from metadata.xml) 144 102 my $text = ""; 145 103 if ($self->{'add_metadata_as_text'}) { 146 104 $text = &metadatautil::format_metadata_as_table($metadata, $self->{'remove_namespace_for_text'}); 105 $doc_obj->add_utf8_text($topsection, $text); 147 106 } 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); 150 108 } 151 $self->title_fallback($doc_obj,$section,$file);152 153 # do plugin specific processing of doc_obj154 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 extraction160 $self->auto_extract_metadata ($doc_obj);161 162 # add an OID163 $doc_obj->set_OID();164 $doc_obj->add_utf8_text($section, $text);165 166 # process the document167 $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 do175 # 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'};181 109 182 110 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.