[9043] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # NulPlugin.pm -- Plugin for dummy (.nul) files
|
---|
[9043] | 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 | #
|
---|
[9044] | 9 | # Copyright (C) 2005 Katherine Don
|
---|
| 10 | # Copyright (C) 2005 New Zealand Digital Library Project
|
---|
[9043] | 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 |
|
---|
[15872] | 28 | # NulPlugin - a plugin for dummy files
|
---|
[9043] | 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 |
|
---|
[15872] | 37 | package NulPlugin;
|
---|
[9043] | 38 |
|
---|
[15872] | 39 | use BasePlugin;
|
---|
[9043] | 40 |
|
---|
[10254] | 41 | use strict;
|
---|
| 42 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[9043] | 43 |
|
---|
| 44 | sub BEGIN {
|
---|
[15872] | 45 | @NulPlugin::ISA = ('BasePlugin');
|
---|
[9043] | 46 | }
|
---|
| 47 |
|
---|
[10978] | 48 | my $arguments =
|
---|
[11390] | 49 | [ { 'name' => "process_exp",
|
---|
[15872] | 50 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[11390] | 51 | 'type' => "regexp",
|
---|
| 52 | 'reqd' => "no",
|
---|
| 53 | 'deft' => &get_default_process_exp() },
|
---|
| 54 | { 'name' => "assoc_field",
|
---|
[15872] | 55 | 'desc' => "{NulPlugin.assoc_field}",
|
---|
[11390] | 56 | 'type' => "string",
|
---|
[15872] | 57 | 'deft' => "null_file",
|
---|
[13420] | 58 | 'reqd' => "no" },
|
---|
| 59 | { 'name' => "add_metadata_as_text",
|
---|
[15872] | 60 | 'desc' => "{NulPlugin.add_metadata_as_text}",
|
---|
[13420] | 61 | 'type' => "flag" },
|
---|
| 62 | { 'name' => "remove_namespace_for_text",
|
---|
[15872] | 63 | 'desc' => "{NulPlugin.remove_namespace_for_text}",
|
---|
[13420] | 64 | 'type' => "flag" }
|
---|
| 65 | ];
|
---|
[9043] | 66 |
|
---|
[15872] | 67 | my $options = { 'name' => "NulPlugin",
|
---|
| 68 | 'desc' => "{NulPlugin.desc}",
|
---|
[9043] | 69 | 'abstract' => "no",
|
---|
[10978] | 70 | 'inherits' => "yes",
|
---|
| 71 | 'args' => $arguments };
|
---|
[9043] | 72 |
|
---|
| 73 |
|
---|
| 74 | sub new {
|
---|
[10218] | 75 | my ($class) = shift (@_);
|
---|
| 76 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 77 | push(@$pluginlist, $class);
|
---|
[9043] | 78 |
|
---|
[15872] | 79 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 80 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[9043] | 81 |
|
---|
[15872] | 82 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10218] | 83 |
|
---|
[9043] | 84 | return bless $self, $class;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | sub get_default_process_exp {
|
---|
| 88 | return '(?i)\.nul$';
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[15872] | 91 | # NulPlugin specific processing of doc_obj.
|
---|
| 92 | sub process {
|
---|
[9043] | 93 | my $self = shift (@_);
|
---|
[15872] | 94 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[9043] | 95 |
|
---|
[15872] | 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);
|
---|
[14962] | 100 |
|
---|
[13420] | 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'});
|
---|
[15872] | 105 | $doc_obj->add_utf8_text($topsection, $text);
|
---|
[13420] | 106 | } else {
|
---|
[15872] | 107 | $self->add_dummy_text($doc_obj, $topsection);
|
---|
[13420] | 108 | }
|
---|
[9043] | 109 |
|
---|
| 110 | return 1;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | 1;
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 |
|
---|