1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # CSTRList.pm --
|
---|
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 | # hacked about version of List classifier for use with cstr collection.
|
---|
27 | # Creates list of Source's (ftp sites), each of which contains a list of
|
---|
28 | # those documents originating from Source.
|
---|
29 |
|
---|
30 | # note that 'Source' metadata contains entire path to document so
|
---|
31 | # we strip it down to get the ftp site.
|
---|
32 |
|
---|
33 | package CSTRList;
|
---|
34 |
|
---|
35 | use sorttools;
|
---|
36 |
|
---|
37 | sub new {
|
---|
38 | my ($class, @options) = @_;
|
---|
39 |
|
---|
40 | my $listname = &util::filename_cat($ENV{'GSDLHOME'},"perllib/classify/List.pm");
|
---|
41 | if (-e $listname) { require $listname; }
|
---|
42 | else { die "CSTRList ERROR - couldn't find classifier \"$listname\"\n"; }
|
---|
43 |
|
---|
44 | return bless {
|
---|
45 | 'list'=>{},
|
---|
46 | }, $class;
|
---|
47 | }
|
---|
48 |
|
---|
49 | sub init {
|
---|
50 | my $self = shift (@_);
|
---|
51 | $self->{'list'} = {};
|
---|
52 | }
|
---|
53 |
|
---|
54 | sub classify {
|
---|
55 | my $self = shift (@_);
|
---|
56 | my ($doc_obj) = @_;
|
---|
57 |
|
---|
58 | my $doc_OID = $doc_obj->get_OID();
|
---|
59 |
|
---|
60 | my $source = $doc_obj->get_metadata_element ($doc_obj->get_top_section(), 'Source');
|
---|
61 |
|
---|
62 | if (defined $source) {
|
---|
63 | my ($ftp_site) = $source =~ /^((ftp:\/\/)?([^\/\\]*))/;
|
---|
64 | print STDERR "CSTRList: Warning: ftp_site undefined\n" unless defined $ftp_site;
|
---|
65 | if (!defined ($self->{'list'}->{$ftp_site})) {
|
---|
66 | my ($listclassobj);
|
---|
67 | eval ("\$listclassobj = new List(\"sort=Date\", \"title=\$ftp_site\")");
|
---|
68 | die "$@" if $@;
|
---|
69 | $listclassobj->init();
|
---|
70 | $self->{'list'}->{$ftp_site} = $listclassobj;
|
---|
71 | $self->{'list'}->{$ftp_site}->classify ($doc_obj);
|
---|
72 | } else {
|
---|
73 | $self->{'list'}->{$ftp_site}->classify ($doc_obj);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | sub get_classify_info {
|
---|
79 | my $self = shift (@_);
|
---|
80 |
|
---|
81 | # organise into classification structure
|
---|
82 | my %classifyinfo = ('classifytype'=>'List',
|
---|
83 | 'Title'=>'Browse',
|
---|
84 | 'contains'=>[]);
|
---|
85 | foreach $ftp_site (sort keys %{$self->{'list'}}) {
|
---|
86 | push (@{$classifyinfo{'contains'}},
|
---|
87 | $self->{'list'}->{$ftp_site}->get_classify_info());
|
---|
88 | }
|
---|
89 |
|
---|
90 | return \%classifyinfo;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | 1;
|
---|