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