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

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

set_OIDtype now takes two arguments, the type and the metadata (used if type=assigned)

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