1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # SectionList.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 | # Same as List classifier but includes all sections of document
|
---|
27 | # (excluding top level) rather than just top level document
|
---|
28 | # itself
|
---|
29 |
|
---|
30 | package SectionList;
|
---|
31 |
|
---|
32 | use sorttools;
|
---|
33 |
|
---|
34 | sub BEGIN {
|
---|
35 | @ISA = ('List');
|
---|
36 | }
|
---|
37 |
|
---|
38 | sub classify {
|
---|
39 | my $self = shift (@_);
|
---|
40 | my ($doc_obj, @options) = @_;
|
---|
41 |
|
---|
42 | my $thissection = undef;
|
---|
43 |
|
---|
44 | my $option;
|
---|
45 | foreach $option (@options)
|
---|
46 | {
|
---|
47 | if ($option =~ m/^section=(\d+)$/i)
|
---|
48 | {
|
---|
49 | $thissection = $1;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | my $sortmeta = "";
|
---|
54 | if (defined $self->{'sortname'}) {
|
---|
55 | if ($self->{'sortname'} =~ /^filename$/i) {
|
---|
56 | $sortmeta = $doc_obj->get_source_filename();
|
---|
57 | } else {
|
---|
58 | $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
|
---|
59 | $self->{'sortname'});
|
---|
60 | if ($self->{'sortname'} eq "Creator") {
|
---|
61 | &sorttools::format_string_name_english (\$sortmeta);
|
---|
62 | } else {
|
---|
63 | &sorttools::format_string_english (\$sortmeta);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | $sortmeta = "" unless defined $sortmeta;
|
---|
67 | }
|
---|
68 |
|
---|
69 | if (!defined $thissection)
|
---|
70 | {
|
---|
71 | $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
|
---|
72 | while (defined $thissection) {
|
---|
73 | $self->classify_section($thissection, $doc_obj, $sortmeta);
|
---|
74 | $thissection = $doc_obj->get_next_section ($thissection);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | else
|
---|
78 | {
|
---|
79 | $self->classify_section($thissection, $doc_obj, $sortmeta);
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | sub classify_section {
|
---|
84 | my $self = shift (@_);
|
---|
85 | my ($section, $doc_obj, $sortmeta) = @_;
|
---|
86 |
|
---|
87 | my $doc_OID = $doc_obj->get_OID();
|
---|
88 | $sortmeta = "" unless defined $sortmeta;
|
---|
89 |
|
---|
90 | if (defined $self->{'sortname'}) {
|
---|
91 | if (defined $self->{'metaname'}) {
|
---|
92 |
|
---|
93 | my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
|
---|
94 | if (defined $metavalue) {
|
---|
95 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
96 | print STDERR "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
|
---|
97 | }
|
---|
98 | $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
|
---|
99 | }
|
---|
100 | } else {
|
---|
101 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
102 | print STDERR "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
|
---|
103 | }
|
---|
104 | $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
|
---|
105 | }
|
---|
106 |
|
---|
107 | } else {
|
---|
108 | if (defined $self->{'metaname'}) {
|
---|
109 |
|
---|
110 | my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
|
---|
111 | if (defined $metavalue) {
|
---|
112 | push (@{$self->{'list'}}, "$doc_OID.$section");
|
---|
113 | }
|
---|
114 | } else {
|
---|
115 | push (@{$self->{'list'}}, "$doc_OID.$section");
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | 1;
|
---|