[26960] | 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 gsprintf 'gsprintf';
|
---|
| 34 |
|
---|
| 35 | # global variables
|
---|
| 36 | my $stats = {'num_processed' => 0,
|
---|
| 37 | 'num_blocked' => 0,
|
---|
| 38 | 'num_not_processed' => 0,
|
---|
| 39 | 'num_not_recognised' => 0,
|
---|
| 40 | 'num_archives' => 0
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | #globaloptions contains any options that should be passed to all plugouts
|
---|
| 44 | my ($verbosity, $outhandle, $failhandle, $globaloptions);
|
---|
| 45 |
|
---|
| 46 | sub load_plugout{
|
---|
| 47 | my ($plugout) = shift @_;
|
---|
| 48 | my $plugout_name = shift @$plugout;
|
---|
| 49 | my $plugout_suffix = &util::filename_cat('perllib', 'plugouts', $plugout_name . '.pm');
|
---|
| 50 | my $plugout_found = 0;
|
---|
| 51 |
|
---|
| 52 | # To find the plugout we check a number of possible locations
|
---|
| 53 | # - any plugout found in the collection itself is our first choice, with
|
---|
| 54 | # those located in 'custom' having precedence
|
---|
| 55 | if (defined($ENV{'GSDLCOLLECTION'}))
|
---|
| 56 | {
|
---|
| 57 | my $collect_dir = $ENV{'GSDLCOLLECTION'};
|
---|
| 58 |
|
---|
| 59 | # (needed for Veridian?)
|
---|
| 60 | my $custom_plugout = &util::filename_cat($collect_dir, "custom", $collect_dir, $plugout_suffix);
|
---|
| 61 | if (&util::file_exists($custom_plugout))
|
---|
| 62 | {
|
---|
| 63 | require $custom_plugout;
|
---|
| 64 | $plugout_found = 1;
|
---|
| 65 | }
|
---|
| 66 | else
|
---|
| 67 | {
|
---|
| 68 | # typical collection override
|
---|
| 69 | my $collection_plugout = &util::filename_cat($collect_dir, $plugout_suffix);
|
---|
| 70 | if (&util::file_exists($collection_plugout))
|
---|
| 71 | {
|
---|
| 72 | require $custom_plugout;
|
---|
| 73 | $plugout_found = 1;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | # - we then search for overridden version provided by any registered GS3
|
---|
| 78 | # extensions (check in order of extension definition)
|
---|
| 79 | if (!$plugout_found && defined $ENV{'GSDL3EXTS'})
|
---|
| 80 | {
|
---|
| 81 | my $ext_prefix = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "ext");
|
---|
| 82 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 83 | foreach my $e (@extensions)
|
---|
| 84 | {
|
---|
| 85 | my $extension_plugout = &util::filename_cat($ext_prefix, $e, $plugout_suffix);
|
---|
| 86 | if (&util::file_exists($extension_plugout))
|
---|
| 87 | {
|
---|
| 88 | require $extension_plugout;
|
---|
| 89 | $plugout_found = 1;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | # - similar for GS2 extensions
|
---|
| 94 | if (!$plugout_found && defined $ENV{'GSDLEXTS'})
|
---|
| 95 | {
|
---|
| 96 | my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'}, "ext");
|
---|
| 97 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 98 | foreach my $e (@extensions)
|
---|
| 99 | {
|
---|
| 100 | my $extension_plugout = &util::filename_cat($ext_prefix, $e, $plugout_suffix);
|
---|
| 101 | if (&util::file_exists($extension_plugout))
|
---|
| 102 | {
|
---|
| 103 | require $extension_plugout;
|
---|
| 104 | $plugout_found = 1;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | # - and the default is the main Greenstone version of the plugout
|
---|
| 109 | if (!$plugout_found)
|
---|
| 110 | {
|
---|
| 111 | my $main_plugout = &util::filename_cat($ENV{'GSDLHOME'}, $plugout_suffix);
|
---|
| 112 | if (&util::file_exists($main_plugout))
|
---|
| 113 | {
|
---|
| 114 | require $main_plugout;
|
---|
| 115 | $plugout_found = 1;
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | # - no plugout found with this name
|
---|
| 120 | if (!$plugout_found)
|
---|
| 121 | {
|
---|
| 122 | gsprintf($outhandle, "{plugout.could_not_find_plugout}\n", $plugout_name);
|
---|
| 123 | die "\n";
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | # - create a plugout object
|
---|
| 127 | my ($plugobj);
|
---|
| 128 |
|
---|
| 129 | eval ("\$plugobj = new \$plugout_name([],\$plugout)");
|
---|
| 130 | die "$@" if $@;
|
---|
| 131 |
|
---|
| 132 | return $plugobj;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | 1;
|
---|