source: gs2-extensions/parallel-building/trunk/src/perllib/plugins/NulPlugin.pm@ 24626

Last change on this file since 24626 was 24626, checked in by jmt12, 13 years ago

An (almost) complete copy of the perllib directory from a (circa SEP2011) head checkout from Greenstone 2 trunk - in order to try and make merging in this extension a little easier later on (as there have been some major changes to buildcol.pl commited in the main trunk but not in the x64 branch)

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