source: gsdl/trunk/perllib/plugins/NulPlugin.pm@ 15865

Last change on this file since 15865 was 15865, checked in by kjdon, 16 years ago

renaming plugins in preparation for my plugin overhaul

  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1###########################################################################
2#
3# NULPlug.pm -- Plugin for dummy (.nul) files
4#
5# A component of the Greenstone digital library software from the New
6# Zealand Digital Library Project at the University of Waikato, New
7# Zealand.
8#
9# Copyright (C) 2005 Katherine Don
10# Copyright (C) 2005 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful, but
18# WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28# NULPlug - a plugin for dummy files
29
30# This is a simple Plugin for importing dummy files, along with
31# their metadata. A fictional document will
32# be created for every such file, and the metadata added to it.
33
34# This is used mainly for the null files resulting from exploding metadata
35# databases
36
37package NULPlug;
38
39use BasPlug;
40
41use strict;
42no strict 'refs'; # allow filehandles to be variables and viceversa
43
44sub BEGIN {
45 @NULPlug::ISA = ('BasPlug');
46}
47
48my $arguments =
49 [ { 'name' => "process_exp",
50 'desc' => "{BasPlug.process_exp}",
51 'type' => "regexp",
52 'reqd' => "no",
53 'deft' => &get_default_process_exp() },
54 { 'name' => "assoc_field",
55 'desc' => "{NULPlug.assoc_field}",
56 'type' => "string",
57 'deft' => "",
58 'reqd' => "no" },
59 { 'name' => "add_metadata_as_text",
60 'desc' => "{NULPlug.add_metadata_as_text}",
61 'type' => "flag" },
62 { 'name' => "remove_namespace_for_text",
63 'desc' => "{NULPlug.remove_namespace_for_text}",
64 'type' => "flag" }
65 ];
66
67my $options = { 'name' => "NULPlug",
68 'desc' => "{NULPlug.desc}",
69 'abstract' => "no",
70 'inherits' => "yes",
71 'args' => $arguments };
72
73
74sub new {
75 my ($class) = shift (@_);
76 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
77 push(@$pluginlist, $class);
78
79 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
80 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
81
82 my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
83
84 return bless $self, $class;
85}
86
87sub get_default_process_exp {
88 return '(?i)\.nul$';
89}
90
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
100
101sub 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
143 # format the metadata passed in (presumably from metadata.xml)
144 my $text = "";
145 if ($self->{'add_metadata_as_text'}) {
146 $text = &metadatautil::format_metadata_as_table($metadata, $self->{'remove_namespace_for_text'});
147 } else {
148 #create an empty text string so we don't break downstream plugins
149 $text = &gsprintf::lookup_string("{BasPlug.dummy_text}",1);
150 }
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
177sub process {
178 my $self = shift (@_);
179 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
180 my $outhandle = $self->{'outhandle'};
181
182 return 1;
183}
184
185
1861;
187
188
189
190
191
192
193
194
195
196
197
Note: See TracBrowser for help on using the repository browser.