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

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

added 'use strict' to all plugins, and made modifications (mostly adding 'my') to make them compile

  • Property svn:keywords set to Author Date Id Revision
File size: 5.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 ];
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) = shift (@_);
60 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
61 push(@$pluginlist, $class);
62
63 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
64 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
65
66 my $self = (defined $hashArgOptLists)? new BasPlug($pluginlist,$inputargs,$hashArgOptLists): new BasPlug($pluginlist,$inputargs);
67
68 return bless $self, $class;
69}
70
71sub get_default_process_exp {
72 return '(?i)\.nul$';
73}
74
75# The NULPlug read() function. This function does all the right
76# things to make general options work for a given plugin. NULPlug
77# overrides read() because there is no need to read the actual text of
78# the file in, because the contents of the file is not text...
79#
80#
81# Return number of files processed, undef if can't process
82#
83# Note that $base_dir might be "" and that $file might include directories
84
85sub read {
86 my $self = shift (@_);
87 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
88
89 my $outhandle = $self->{'outhandle'};
90
91 # Make sure we're processing the correct file
92 my $filename = &util::filename_cat($base_dir, $file);
93 return 0 if $self->{'block_exp'} ne "" && $filename =~ /$self->{'block_exp'}/;
94 if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
95 return undef;
96 }
97 print STDERR "<Processing n='$file' p='NULPlug'>\n" if ($gli);
98 print $outhandle "NULPlug processing \"$filename\"\n"
99 if $self->{'verbosity'} > 1;
100
101 #if there's a leading directory name, eat it...
102 $file =~ s/^.*[\/\\]//;
103
104 # create a new document
105 my $doc_obj = new doc ($filename, "indexed_doc");
106 $doc_obj->set_OIDtype ($processor->{'OIDtype'});
107 #$doc_obj->set_OIDtype ("incremental");
108 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
109 $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
110 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "FileSize", (-s $filename));
111
112 #create an empty text string so we don't break downstream plugins
113 my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}");
114
115 # include any metadata passed in from previous plugins
116 my $section = $doc_obj->get_top_section();
117 $self->extra_metadata ($doc_obj, $section, $metadata);
118
119 $self->title_fallback($doc_obj,$section,$file);
120
121 # do plugin specific processing of doc_obj
122 unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
123 print STDERR "<ProcessingError n='$file'>\n" if ($gli);
124 return -1;
125 }
126
127 # do any automatic metadata extraction
128 $self->auto_extract_metadata ($doc_obj);
129
130 # add an OID
131 $doc_obj->set_OID();
132 $doc_obj->add_text($section, $text);
133
134 # process the document
135 $processor->process($doc_obj);
136
137 $self->{'num_processed'} ++;
138 return 1;
139}
140
141
142# NULPlug processing of doc_obj. In practice we don't need to do
143# anything here because the read function takes care of everything.
144
145sub process {
146 my $self = shift (@_);
147 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
148 my $outhandle = $self->{'outhandle'};
149
150 return 1;
151}
152
153
1541;
155
156
157
158
159
160
161
162
163
164
165
Note: See TracBrowser for help on using the repository browser.