1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # plugout.pm -- functions to handle using plugouts
|
---|
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 plugout;
|
---|
27 |
|
---|
28 | use strict; # to pick up typos and undeclared variables...
|
---|
29 | no strict 'refs'; # ...but allow filehandles to be variables and vice versa
|
---|
30 | no strict 'subs';
|
---|
31 |
|
---|
32 | require util;
|
---|
33 | use FileUtils;
|
---|
34 | use gsprintf 'gsprintf';
|
---|
35 |
|
---|
36 | # global variables
|
---|
37 | my $stats = {'num_processed' => 0,
|
---|
38 | 'num_blocked' => 0,
|
---|
39 | 'num_not_processed' => 0,
|
---|
40 | 'num_not_recognised' => 0,
|
---|
41 | 'num_archives' => 0
|
---|
42 | };
|
---|
43 |
|
---|
44 | #globaloptions contains any options that should be passed to all plugouts
|
---|
45 | my ($verbosity, $outhandle, $failhandle, $globaloptions);
|
---|
46 |
|
---|
47 | # - significantly rewritten to support plugouts in extensions [jmt12]
|
---|
48 | sub load_plugout{
|
---|
49 | my ($plugout) = shift @_;
|
---|
50 | my $plugout_name = shift @$plugout;
|
---|
51 | my $plugout_suffix = &FileUtils::filenameConcatenate('perllib', 'plugouts', $plugout_name . '.pm');
|
---|
52 | my $plugout_found = 0;
|
---|
53 |
|
---|
54 | # add collection plugout directory to INC unless it is already there
|
---|
55 | my $colplugdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},'perllib','plugouts');
|
---|
56 | if (-d $colplugdir)
|
---|
57 | {
|
---|
58 | my $found_colplugdir = 0;
|
---|
59 | foreach my $path (@INC)
|
---|
60 | {
|
---|
61 | if ($path eq $colplugdir)
|
---|
62 | {
|
---|
63 | $found_colplugdir = 1;
|
---|
64 | last;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | if (!$found_colplugdir)
|
---|
68 | {
|
---|
69 | unshift (@INC, $colplugdir);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | # To find the plugout we check a number of possible locations
|
---|
74 | # - any plugout found in the collection itself is our first choice, with
|
---|
75 | # those located in 'custom' having precedence
|
---|
76 | if (defined($ENV{'GSDLCOLLECTION'}))
|
---|
77 | {
|
---|
78 | my $collect_dir = $ENV{'GSDLCOLLECTION'};
|
---|
79 |
|
---|
80 | # (needed for Veridian?)
|
---|
81 | my $custom_plugout = &FileUtils::filenameConcatenate($collect_dir, "custom", $collect_dir, $plugout_suffix);
|
---|
82 | if (&FileUtils::fileExists($custom_plugout))
|
---|
83 | {
|
---|
84 | require $custom_plugout;
|
---|
85 | $plugout_found = 1;
|
---|
86 | }
|
---|
87 | else
|
---|
88 | {
|
---|
89 | # typical collection override
|
---|
90 | my $collection_plugout = &FileUtils::filenameConcatenate($collect_dir, $plugout_suffix);
|
---|
91 | if (&FileUtils::fileExists($collection_plugout))
|
---|
92 | {
|
---|
93 | require $custom_plugout;
|
---|
94 | $plugout_found = 1;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | # - we then search for overridden version provided by any registered GS3
|
---|
99 | # extensions (check in order of extension definition)
|
---|
100 | if (!$plugout_found && defined $ENV{'GSDL3EXTS'})
|
---|
101 | {
|
---|
102 | my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "ext");
|
---|
103 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
104 | foreach my $e (@extensions)
|
---|
105 | {
|
---|
106 | my $extension_plugout = &FileUtils::filenameConcatenate($ext_prefix, $e, $plugout_suffix);
|
---|
107 | if (&FileUtils::fileExists($extension_plugout))
|
---|
108 | {
|
---|
109 | require $extension_plugout;
|
---|
110 | $plugout_found = 1;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 | # - similar for GS2 extensions
|
---|
115 | if (!$plugout_found && defined $ENV{'GSDLEXTS'})
|
---|
116 | {
|
---|
117 | my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "ext");
|
---|
118 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
119 | foreach my $e (@extensions)
|
---|
120 | {
|
---|
121 | my $extension_plugout = &FileUtils::filenameConcatenate($ext_prefix, $e, $plugout_suffix);
|
---|
122 | if (&FileUtils::fileExists($extension_plugout))
|
---|
123 | {
|
---|
124 | require $extension_plugout;
|
---|
125 | $plugout_found = 1;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | # - and the default is the main Greenstone version of the plugout
|
---|
130 | if (!$plugout_found)
|
---|
131 | {
|
---|
132 | my $main_plugout = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, $plugout_suffix);
|
---|
133 | if (&FileUtils::fileExists($main_plugout))
|
---|
134 | {
|
---|
135 | require $main_plugout;
|
---|
136 | $plugout_found = 1;
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | # - no plugout found with this name
|
---|
141 | if (!$plugout_found)
|
---|
142 | {
|
---|
143 | gsprintf($outhandle, "{plugout.could_not_find_plugout}\n", $plugout_name);
|
---|
144 | die "\n";
|
---|
145 | }
|
---|
146 |
|
---|
147 | # - create a plugout object
|
---|
148 | my ($plugobj);
|
---|
149 |
|
---|
150 | eval ("\$plugobj = new \$plugout_name([],\$plugout)");
|
---|
151 | die "$@" if $@;
|
---|
152 |
|
---|
153 | return $plugobj;
|
---|
154 | }
|
---|
155 |
|
---|
156 | 1;
|
---|