source: trunk/gsdl/perllib/plugins/NULPlug.pm@ 9853

Last change on this file since 9853 was 9853, checked in by kjdon, 19 years ago

fixed up maxdocs - now pass an extra parameter to the read function

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 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;
40use parsargv;
41
42
43sub BEGIN {
44 @NULPlug::ISA = ('BasPlug');
45}
46
47#my $arguments =
48# [
49# ];
50
51my $options = { 'name' => "NULPlug",
52 'desc' => "{NULPlug.desc}",
53 'abstract' => "no",
54 'inherits' => "yes" };
55 # 'args' => $arguments };
56
57
58sub new {
59 my ($class) = @_;
60 my $self = new BasPlug ($class, @_);
61 $self->{'plugin_type'} = "NULPlug";
62 # 14-05-02 To allow for proper inheritance of arguments - John Thompson
63 my $option_list = $self->{'option_list'};
64 push( @{$option_list}, $options );
65
66 if (!parsargv::parse(\@_,
67 "allow_extra_options")) {
68 print STDERR "\nIncorrect options passed to NULPlug, check your collect.cfg configuration file\n";
69 $self->print_txt_usage(""); # Use default resource bundle
70 die "\n";
71 }
72
73
74 return bless $self, $class;
75}
76
77sub get_default_process_exp {
78 return '(?i)\.nul$';
79}
80
81# The NULPlug read() function. This function does all the right
82# things to make general options work for a given plugin. NULPlug
83# overrides read() because there is no need to read the actual text of
84# the file in, because the contents of the file is not text...
85#
86#
87# Return number of files processed, undef if can't process
88#
89# Note that $base_dir might be "" and that $file might include directories
90
91sub read {
92 my $self = shift (@_);
93 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
94
95 my $outhandle = $self->{'outhandle'};
96
97 # Make sure we're processing the correct file
98 my $filename = &util::filename_cat($base_dir, $file);
99 return 0 if $self->{'block_exp'} ne "" && $filename =~ /$self->{'block_exp'}/;
100 if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
101 return undef;
102 }
103 print STDERR "<Processing n='$file' p='NULPlug'>\n" if ($gli);
104 print $outhandle "NULPlug processing \"$filename\"\n"
105 if $self->{'verbosity'} > 1;
106
107 #if there's a leading directory name, eat it...
108 $file =~ s/^.*[\/\\]//;
109
110 # create a new document
111 my $doc_obj = new doc ($filename, "indexed_doc");
112 $doc_obj->set_OIDtype ($processor->{'OIDtype'});
113 #$doc_obj->set_OIDtype ("incremental");
114 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
115 $doc_obj->add_metadata($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($file)); # set the filename as Source metadata to be consistent with other plugins
116 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "FileSize", (-s $filename));
117
118 #create an empty text string so we don't break downstream plugins
119 my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}");
120
121 # include any metadata passed in from previous plugins
122 my $section = $doc_obj->get_top_section();
123 $self->extra_metadata ($doc_obj, $section, $metadata);
124
125 $self->title_fallback($doc_obj,$section,$file);
126
127 # do plugin specific processing of doc_obj
128 unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
129 print STDERR "<ProcessingError n='$file'>\n" if ($gli);
130 return -1;
131 }
132
133 # do any automatic metadata extraction
134 $self->auto_extract_metadata ($doc_obj);
135
136 # add an OID
137 $doc_obj->set_OID();
138 $doc_obj->add_text($section, $text);
139
140 # process the document
141 $processor->process($doc_obj);
142
143 $self->{'num_processed'} ++;
144 return 1;
145}
146
147
148# NULPlug processing of doc_obj. In practice we don't need to do
149# anything here because the read function takes care of everything.
150
151sub process {
152 my $self = shift (@_);
153 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
154 my $outhandle = $self->{'outhandle'};
155
156 return 1;
157}
158
159
1601;
161
162
163
164
165
166
167
168
169
170
171
Note: See TracBrowser for help on using the repository browser.