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

Last change on this file since 13727 was 13727, checked in by shaoqun, 17 years ago

added the support to cover images

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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 if ($self->{'cover_image'}) {
131 $self->associate_cover_image($doc_obj, $filename);
132 }
133
134 # include any metadata passed in from previous plugins
135 my $section = $doc_obj->get_top_section();
136 $self->extra_metadata ($doc_obj, $section, $metadata);
137
138 # format the metadata passed in (presumably from metadata.xml)
139 my $text = "";
140 if ($self->{'add_metadata_as_text'}) {
141 $text = &metadatautil::format_metadata_as_table($metadata, $self->{'remove_namespace_for_text'});
142 } else {
143 #create an empty text string so we don't break downstream plugins
144 $text = &gsprintf::lookup_string("{BasPlug.dummy_text}",1);
145 }
146 $self->title_fallback($doc_obj,$section,$file);
147
148 # do plugin specific processing of doc_obj
149 unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
150 print STDERR "<ProcessingError n='$file'>\n" if ($gli);
151 return -1;
152 }
153
154 # do any automatic metadata extraction
155 $self->auto_extract_metadata ($doc_obj);
156
157 # add an OID
158 $doc_obj->set_OID();
159 $doc_obj->add_utf8_text($section, $text);
160
161 # process the document
162 $processor->process($doc_obj);
163
164 $self->{'num_processed'} ++;
165 return 1;
166}
167
168
169# NULPlug processing of doc_obj. In practice we don't need to do
170# anything here because the read function takes care of everything.
171
172sub process {
173 my $self = shift (@_);
174 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
175 my $outhandle = $self->{'outhandle'};
176
177 return 1;
178}
179
180
1811;
182
183
184
185
186
187
188
189
190
191
192
Note: See TracBrowser for help on using the repository browser.