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

Last change on this file since 13420 was 13420, checked in by kjdon, 17 years ago

added a option to add a table of metadata as the documnet text, rather than the dummy string 'this document has no text'

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