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

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

added assoc_field option to NULPlug

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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 # 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
117 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "FileSize", (-s $filename));
118
119 my $assoc_field = $self->{'assoc_field'} || "null_file";
120 $doc_obj->add_metadata ($doc_obj->get_top_section(), $assoc_field, $file);
121
122 #create an empty text string so we don't break downstream plugins
123 my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}");
124
125 # include any metadata passed in from previous plugins
126 my $section = $doc_obj->get_top_section();
127 $self->extra_metadata ($doc_obj, $section, $metadata);
128
129 $self->title_fallback($doc_obj,$section,$file);
130
131 # do plugin specific processing of doc_obj
132 unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
133 print STDERR "<ProcessingError n='$file'>\n" if ($gli);
134 return -1;
135 }
136
137 # do any automatic metadata extraction
138 $self->auto_extract_metadata ($doc_obj);
139
140 # add an OID
141 $doc_obj->set_OID();
142 $doc_obj->add_text($section, $text);
143
144 # process the document
145 $processor->process($doc_obj);
146
147 $self->{'num_processed'} ++;
148 return 1;
149}
150
151
152# NULPlug processing of doc_obj. In practice we don't need to do
153# anything here because the read function takes care of everything.
154
155sub process {
156 my $self = shift (@_);
157 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
158 my $outhandle = $self->{'outhandle'};
159
160 return 1;
161}
162
163
1641;
165
166
167
168
169
170
171
172
173
174
175
Note: See TracBrowser for help on using the repository browser.