1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # BasPlug.pm -- base class for all the import plugins
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 | package BasPlug;
|
---|
27 |
|
---|
28 |
|
---|
29 | sub new {
|
---|
30 | my ($class) = @_;
|
---|
31 |
|
---|
32 | return bless {}, $class;
|
---|
33 | }
|
---|
34 |
|
---|
35 | sub begin {
|
---|
36 | my $self = shift (@_);
|
---|
37 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
38 | }
|
---|
39 |
|
---|
40 | sub end {
|
---|
41 | my ($self) = @_;
|
---|
42 | }
|
---|
43 |
|
---|
44 | # return 1 if this class might recurse using $pluginfo
|
---|
45 | sub is_recursive {
|
---|
46 | my $self = shift (@_);
|
---|
47 |
|
---|
48 | die "BasPlug::is_recursive function must be implemented in sub classes\n";
|
---|
49 | }
|
---|
50 |
|
---|
51 | # return number of files processed, undef if can't process
|
---|
52 | # Note that $base_dir might be "" and that $file might
|
---|
53 | # include directories
|
---|
54 | sub read {
|
---|
55 | my $self = shift (@_);
|
---|
56 | my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs) = @_;
|
---|
57 |
|
---|
58 | die "BasPlug::read function must be implemented in sub classes\n";
|
---|
59 |
|
---|
60 | return undef; # will never get here
|
---|
61 | }
|
---|
62 |
|
---|
63 | sub extra_metadata
|
---|
64 | {
|
---|
65 | my ($self,$doc_obj,$cursection, $metadata) = @_;
|
---|
66 |
|
---|
67 | foreach $field (keys(%$metadata)) {
|
---|
68 | # $metadata->{$field} may be an array reference
|
---|
69 | if (ref ($metadata->{$field}) eq "ARRAY") {
|
---|
70 | map {
|
---|
71 | $doc_obj->add_metadata ($cursection, $field, $_);
|
---|
72 | } @{$metadata->{$field}};
|
---|
73 | } else {
|
---|
74 | $doc_obj->add_metadata ($cursection, $field, $metadata->{$field});
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | 1;
|
---|