source: main/trunk/greenstone2/perllib/plugins/NulPlugin.pm@ 22705

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

plugin overhaul: plugins renamed to xxPlugin, and in some cases the names are made more sensible. They now use the new base plugins. Hopefully we have better code reuse. Some of the plugins still need work done as I didn't want to spend another month doing this before committing it. Alos, I haven't really tested anything yet...

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1###########################################################################
2#
3# NulPlugin.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# NulPlugin - 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 NulPlugin;
38
39use BasePlugin;
40
41use strict;
42no strict 'refs'; # allow filehandles to be variables and viceversa
43
44sub BEGIN {
45 @NulPlugin::ISA = ('BasePlugin');
46}
47
48my $arguments =
49 [ { 'name' => "process_exp",
50 'desc' => "{BasePlugin.process_exp}",
51 'type' => "regexp",
52 'reqd' => "no",
53 'deft' => &get_default_process_exp() },
54 { 'name' => "assoc_field",
55 'desc' => "{NulPlugin.assoc_field}",
56 'type' => "string",
57 'deft' => "null_file",
58 'reqd' => "no" },
59 { 'name' => "add_metadata_as_text",
60 'desc' => "{NulPlugin.add_metadata_as_text}",
61 'type' => "flag" },
62 { 'name' => "remove_namespace_for_text",
63 'desc' => "{NulPlugin.remove_namespace_for_text}",
64 'type' => "flag" }
65 ];
66
67my $options = { 'name' => "NulPlugin",
68 'desc' => "{NulPlugin.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 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
80 push(@{$hashArgOptLists->{"OptList"}},$options);
81
82 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
83
84 return bless $self, $class;
85}
86
87sub get_default_process_exp {
88 return '(?i)\.nul$';
89}
90
91# NulPlugin specific processing of doc_obj.
92sub process {
93 my $self = shift (@_);
94 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
95
96 my $topsection = $doc_obj->get_top_section();
97
98 my $assoc_field = $self->{'assoc_field'}; # || "null_file"; TODO, check this
99 $doc_obj->add_metadata ($topsection, $assoc_field, $file);
100
101 # format the metadata passed in (presumably from metadata.xml)
102 my $text = "";
103 if ($self->{'add_metadata_as_text'}) {
104 $text = &metadatautil::format_metadata_as_table($metadata, $self->{'remove_namespace_for_text'});
105 $doc_obj->add_utf8_text($topsection, $text);
106 } else {
107 $self->add_dummy_text($doc_obj, $topsection);
108 }
109
110 return 1;
111}
112
113
1141;
115
116
117
118
119
120
121
122
123
124
125
Note: See TracBrowser for help on using the repository browser.