1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # AZSectionList.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 | # classifier plugin for sorting sections alphabetically
|
---|
27 |
|
---|
28 | # this is very similar to AZList except it sorts by
|
---|
29 | # section level metadata (excluding the top level)
|
---|
30 | # instead of just top level metadata
|
---|
31 |
|
---|
32 | # the only change is to the classify() subroutine which
|
---|
33 | # must now iterate through each section, adding each
|
---|
34 | # to the classification
|
---|
35 |
|
---|
36 | # 12/05/02 Added usage datastructure - John Thompson
|
---|
37 |
|
---|
38 | package AZSectionList;
|
---|
39 |
|
---|
40 | use AZList;
|
---|
41 | use sorttools;
|
---|
42 |
|
---|
43 | use strict;
|
---|
44 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
45 |
|
---|
46 | sub BEGIN {
|
---|
47 | @AZSectionList::ISA = ('AZList');
|
---|
48 | }
|
---|
49 |
|
---|
50 | my $arguments = [
|
---|
51 | ];
|
---|
52 | my $options = { 'name' => "AZSectionList",
|
---|
53 | 'desc' => "{AZSectionList.desc}",
|
---|
54 | 'abstract' => "no",
|
---|
55 | 'inherits' => "yes" };
|
---|
56 |
|
---|
57 |
|
---|
58 | sub new {
|
---|
59 | my ($class) = shift (@_);
|
---|
60 | my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
|
---|
61 | push(@$classifierslist, $class);
|
---|
62 |
|
---|
63 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
64 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
65 |
|
---|
66 | my $self = new AZList($classifierslist, $inputargs, $hashArgOptLists);
|
---|
67 |
|
---|
68 | return bless $self, $class;
|
---|
69 | }
|
---|
70 |
|
---|
71 | sub classify {
|
---|
72 | my $self = shift (@_);
|
---|
73 | my ($doc_obj) = @_;
|
---|
74 |
|
---|
75 | my $doc_OID = $doc_obj->get_OID();
|
---|
76 | my $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
|
---|
77 |
|
---|
78 | while (defined $thissection) {
|
---|
79 | $self->classify_section ($thissection, $doc_obj);
|
---|
80 | $thissection = $doc_obj->get_next_section ($thissection);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | sub classify_section {
|
---|
85 | my $self = shift (@_);
|
---|
86 | my ($section, $doc_obj) = @_;
|
---|
87 |
|
---|
88 | my $doc_OID = $doc_obj->get_OID();
|
---|
89 |
|
---|
90 | my $metavalue;
|
---|
91 | my $metaname;
|
---|
92 |
|
---|
93 | if (!defined $self->{'meta_list'}) {
|
---|
94 | # just in case
|
---|
95 | return;
|
---|
96 | }
|
---|
97 |
|
---|
98 | # find the first available metadata
|
---|
99 | foreach my $m (@{$self->{'meta_list'}}) {
|
---|
100 | $metavalue = $doc_obj->get_metadata_element($section, $m);
|
---|
101 | $metaname = $m;
|
---|
102 | last if defined $metavalue;
|
---|
103 | }
|
---|
104 |
|
---|
105 | # if this section doesn't contain the metadata element we're
|
---|
106 | # sorting by we won't include it in this classification
|
---|
107 |
|
---|
108 | if (defined $metavalue && $metavalue ne "") {
|
---|
109 | if ($self->{'removeprefix'}) {
|
---|
110 | $metavalue =~ s/^$self->{'removeprefix'}//;
|
---|
111 | }
|
---|
112 |
|
---|
113 | $metavalue = &sorttools::format_metadata_for_sorting($metaname, $metavalue, $doc_obj) unless $self->{'no_metadata_formatting'};
|
---|
114 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
115 | my $outhandle = $self->{'outhandle'};
|
---|
116 | print $outhandle "WARNING: AZSectionList::classify called multiple times " .
|
---|
117 | "for $doc_OID.$section\n";
|
---|
118 | }
|
---|
119 | $self->{'list'}->{"$doc_OID.$section"} = $metavalue;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | 1;
|
---|