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

Last change on this file since 11090 was 11090, checked in by kjdon, 18 years ago

made all plugins that implement read() call read_block to check process_exp, block_exp, smart blocking, cover image blocking etc

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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 { 'name' => "assoc_field",
51 'desc' => "{NULPlug.assoc_field}",
52 'type' => "string",
53 'deft' => "",
54 'reqd' => "no" }
55 ];
56
57my $options = { 'name' => "NULPlug",
58 'desc' => "{NULPlug.desc}",
59 'abstract' => "no",
60 'inherits' => "yes",
61 'args' => $arguments };
62
63
64sub new {
65 my ($class) = shift (@_);
66 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
67 push(@$pluginlist, $class);
68
69 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
70 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
71
72 my $self = (defined $hashArgOptLists)? new BasPlug($pluginlist,$inputargs,$hashArgOptLists): new BasPlug($pluginlist,$inputargs);
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 #check for associate_ext, blocking etc
98 my ($block_status,$filename) = $self->read_block(@_);
99 return $block_status if ((!defined $block_status) || ($block_status==0));
100
101 print STDERR "<Processing n='$file' p='NULPlug'>\n" if ($gli);
102 print $outhandle "NULPlug processing \"$filename\"\n"
103 if $self->{'verbosity'} > 1;
104
105 #if there's a leading directory name, eat it...
106 $file =~ s/^.*[\/\\]//;
107
108 # create a new document
109 my $doc_obj = new doc ($filename, "indexed_doc");
110 $doc_obj->set_OIDtype ($processor->{'OIDtype'});
111 #$doc_obj->set_OIDtype ("incremental");
112 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
113 $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
114
115 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "FileSize", (-s $filename));
116
117 my $assoc_field = $self->{'assoc_field'} || "null_file";
118 $doc_obj->add_metadata ($doc_obj->get_top_section(), $assoc_field, $file);
119
120 #create an empty text string so we don't break downstream plugins
121 my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}");
122
123 # include any metadata passed in from previous plugins
124 my $section = $doc_obj->get_top_section();
125 $self->extra_metadata ($doc_obj, $section, $metadata);
126
127 $self->title_fallback($doc_obj,$section,$file);
128
129 # do plugin specific processing of doc_obj
130 unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
131 print STDERR "<ProcessingError n='$file'>\n" if ($gli);
132 return -1;
133 }
134
135 # do any automatic metadata extraction
136 $self->auto_extract_metadata ($doc_obj);
137
138 # add an OID
139 $doc_obj->set_OID();
140 $doc_obj->add_text($section, $text);
141
142 # process the document
143 $processor->process($doc_obj);
144
145 $self->{'num_processed'} ++;
146 return 1;
147}
148
149
150# NULPlug processing of doc_obj. In practice we don't need to do
151# anything here because the read function takes care of everything.
152
153sub process {
154 my $self = shift (@_);
155 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
156 my $outhandle = $self->{'outhandle'};
157
158 return 1;
159}
160
161
1621;
163
164
165
166
167
168
169
170
171
172
173
Note: See TracBrowser for help on using the repository browser.