1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # download.pm -- functions to handle using download modules
|
---|
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) 2005 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 download;
|
---|
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 |
|
---|
36 | sub load_download {
|
---|
37 | my ($download_name,$download_options) = @_;
|
---|
38 |
|
---|
39 | my ($download_obj);
|
---|
40 |
|
---|
41 | my $coldownloadname ="";
|
---|
42 |
|
---|
43 | if ($ENV{'GSDLCOLLECTDIR'}){
|
---|
44 |
|
---|
45 | $coldownloadname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},
|
---|
46 | "perllib/downloaders",
|
---|
47 | "${download_name}.pm");
|
---|
48 |
|
---|
49 | }
|
---|
50 |
|
---|
51 | my $maindownloadname = &util::filename_cat($ENV{'GSDLHOME'},
|
---|
52 | "perllib/downloaders",
|
---|
53 | "${download_name}.pm");
|
---|
54 |
|
---|
55 | if (-e $coldownloadname) { require $coldownloadname;}
|
---|
56 | elsif (-e $maindownloadname ) { require $maindownloadname; }
|
---|
57 | else {
|
---|
58 | &gsprintf(STDERR, "{download.could_not_find_download}\n",
|
---|
59 | $download_name);
|
---|
60 | die "\n";
|
---|
61 | }
|
---|
62 |
|
---|
63 | eval ("\$download_obj = new \$download_name([],\$download_options)");
|
---|
64 | die "$@" if $@;
|
---|
65 |
|
---|
66 | return $download_obj;
|
---|
67 | }
|
---|
68 |
|
---|
69 | sub process {
|
---|
70 | my ($download_obj,$options) = @_;
|
---|
71 | # options: This is a hash map which maps to
|
---|
72 | # downloadfrom's arguments
|
---|
73 | # $options->{'cache_dir'}
|
---|
74 | # $options->{'download_mode'}
|
---|
75 | # $options->{'gli_call'}
|
---|
76 | # $options->{'info'}
|
---|
77 | ($download_obj->download($options) == 1)?
|
---|
78 | return "true":
|
---|
79 | return "false";
|
---|
80 | }
|
---|
81 |
|
---|
82 | sub get_information {
|
---|
83 | my ($download_obj) = @_;
|
---|
84 |
|
---|
85 | $download_obj->url_information();
|
---|
86 | }
|
---|
87 |
|
---|
88 | 1;
|
---|