source: main/tags/2.30/gsdl/perllib/classify/SectionList.pm@ 23841

Last change on this file since 23841 was 1611, checked in by sjboddie, 24 years ago

Minor bug fix

  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
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
30package SectionList;
31
32use List;
33use sorttools;
34
35sub BEGIN {
36 @ISA = ('List');
37}
38
39sub new {
40 my ($class, @options) = @_;
41 my $self = new List ($class, @_);
42 return bless $self, $class;
43}
44
45sub classify {
46 my $self = shift (@_);
47 my ($doc_obj, @options) = @_;
48
49 my $thissection = undef;
50
51 my $option;
52 foreach $option (@options)
53 {
54 if ($option =~ m/^section=(\d+)$/i)
55 {
56 $thissection = $1;
57 }
58 }
59
60 my $sortmeta = "";
61 if (defined $self->{'sortname'}) {
62 if ($self->{'sortname'} =~ /^filename$/i) {
63 $sortmeta = $doc_obj->get_source_filename();
64 } else {
65 $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
66 $self->{'sortname'});
67 if ($self->{'sortname'} eq "Creator") {
68 &sorttools::format_string_name_english (\$sortmeta);
69 } else {
70 &sorttools::format_string_english (\$sortmeta);
71 }
72 }
73 $sortmeta = "" unless defined $sortmeta;
74 }
75
76 if (!defined $thissection)
77 {
78 $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
79 while (defined $thissection) {
80 $self->classify_section($thissection, $doc_obj, $sortmeta);
81 $thissection = $doc_obj->get_next_section ($thissection);
82 }
83 }
84 else
85 {
86 $self->classify_section($thissection, $doc_obj, $sortmeta);
87 }
88}
89
90sub classify_section {
91 my $self = shift (@_);
92 my ($section, $doc_obj, $sortmeta) = @_;
93
94 my $doc_OID = $doc_obj->get_OID();
95 $sortmeta = "" unless defined $sortmeta;
96
97 if (defined $self->{'sortname'}) {
98 if (defined $self->{'metaname'}) {
99
100 my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
101 if (defined $metavalue) {
102 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
103 my $outhandle = $self->{'outhandle'};
104 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
105 }
106 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
107 }
108 } else {
109 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
110 my $outhandle = $self->{'outhandle'};
111 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
112 }
113 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
114 }
115
116 } else {
117 if (defined $self->{'metaname'}) {
118
119 my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
120 if (defined $metavalue) {
121 push (@{$self->{'list'}}, "$doc_OID.$section");
122 }
123 } else {
124 push (@{$self->{'list'}}, "$doc_OID.$section");
125 }
126 }
127}
128
1291;
Note: See TracBrowser for help on using the repository browser.