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 | # 12/05/02 Added usage datastructure - John Thompson
|
---|
31 |
|
---|
32 | package SectionList;
|
---|
33 |
|
---|
34 | use List;
|
---|
35 | use sorttools;
|
---|
36 |
|
---|
37 | sub BEGIN {
|
---|
38 | @ISA = ('List');
|
---|
39 | }
|
---|
40 |
|
---|
41 | my $options = { 'name' => "SectionList",
|
---|
42 | 'desc' => "{SectionList.desc}",
|
---|
43 | 'inherits' => "Yes" };
|
---|
44 |
|
---|
45 | # sub print_usage {
|
---|
46 | # print STDERR "
|
---|
47 | # usage: classify SectionList [options]
|
---|
48 | # options:
|
---|
49 |
|
---|
50 | # -metadata X Metadata field used for classification,
|
---|
51 | # list will be sorted by this element.
|
---|
52 |
|
---|
53 | # -buttonname X (optional) Title field for this classification.
|
---|
54 | # if not included title field will be Metaname.
|
---|
55 |
|
---|
56 | # -sort X (optional) Sort documents in list by this metadata field.
|
---|
57 | # By default it will sort by Metaname, or (if this is not
|
---|
58 | # set) in build (random) order.
|
---|
59 |
|
---|
60 | # Same as List classifier but includes all sections of document
|
---|
61 | # (excluding top level) rather than just top level document.
|
---|
62 | # ";
|
---|
63 | # }
|
---|
64 |
|
---|
65 | sub new {
|
---|
66 | my $class = shift (@_);
|
---|
67 | my $self = new List($class, @_);
|
---|
68 |
|
---|
69 | # 14-05-02 To allow for proper inheritance of arguments - John Thompson
|
---|
70 | my $option_list = $self->{'option_list'};
|
---|
71 | push( @{$option_list}, $options );
|
---|
72 |
|
---|
73 | return bless $self, $class;
|
---|
74 | }
|
---|
75 |
|
---|
76 | sub classify {
|
---|
77 | my $self = shift (@_);
|
---|
78 | my ($doc_obj, @options) = @_;
|
---|
79 |
|
---|
80 | my $thissection = undef;
|
---|
81 |
|
---|
82 | my $option;
|
---|
83 | foreach $option (@options)
|
---|
84 | {
|
---|
85 | if ($option =~ m/^section=(\d+)$/i)
|
---|
86 | {
|
---|
87 | $thissection = $1;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | my $sortmeta = "";
|
---|
92 | if (defined $self->{'sortname'}) {
|
---|
93 | if ($self->{'sortname'} =~ /^filename$/i) {
|
---|
94 | $sortmeta = $doc_obj->get_source_filename();
|
---|
95 | } else {
|
---|
96 | $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
|
---|
97 | $self->{'sortname'});
|
---|
98 | if ($self->{'sortname'} eq "Creator") {
|
---|
99 | &sorttools::format_string_name_english (\$sortmeta);
|
---|
100 | } else {
|
---|
101 | &sorttools::format_string_english (\$sortmeta);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | $sortmeta = "" unless defined $sortmeta;
|
---|
105 | }
|
---|
106 |
|
---|
107 | if (!defined $thissection)
|
---|
108 | {
|
---|
109 | $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
|
---|
110 | while (defined $thissection) {
|
---|
111 | $self->classify_section($thissection, $doc_obj, $sortmeta);
|
---|
112 | $thissection = $doc_obj->get_next_section ($thissection);
|
---|
113 | }
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | $self->classify_section($thissection, $doc_obj, $sortmeta);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | sub classify_section {
|
---|
122 | my $self = shift (@_);
|
---|
123 | my ($section, $doc_obj, $sortmeta) = @_;
|
---|
124 |
|
---|
125 | my $doc_OID = $doc_obj->get_OID();
|
---|
126 | $sortmeta = "" unless defined $sortmeta;
|
---|
127 |
|
---|
128 | if (defined $self->{'sortname'}) {
|
---|
129 | if (defined $self->{'metaname'}) {
|
---|
130 |
|
---|
131 | my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
|
---|
132 | if (defined $metavalue) {
|
---|
133 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
134 | my $outhandle = $self->{'outhandle'};
|
---|
135 | print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
|
---|
136 | }
|
---|
137 | $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
|
---|
138 | }
|
---|
139 | } else {
|
---|
140 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
141 | my $outhandle = $self->{'outhandle'};
|
---|
142 | print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
|
---|
143 | }
|
---|
144 | $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
|
---|
145 | }
|
---|
146 |
|
---|
147 | } else {
|
---|
148 | if (defined $self->{'metaname'}) {
|
---|
149 |
|
---|
150 | my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
|
---|
151 | if (defined $metavalue) {
|
---|
152 | push (@{$self->{'list'}}, "$doc_OID.$section");
|
---|
153 | }
|
---|
154 | } else {
|
---|
155 | push (@{$self->{'list'}}, "$doc_OID.$section");
|
---|
156 | }
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | 1;
|
---|