source: trunk/gsdl/perllib/classify/SectionList.pm@ 5646

Last change on this file since 5646 was 5645, checked in by mdewsnip, 21 years ago

Moved classifier descriptions into the resource bundle (perllib/strings.rb).

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
RevLine 
[537]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
[425]26# Same as List classifier but includes all sections of document
27# (excluding top level) rather than just top level document
28# itself
29
[3540]30# 12/05/02 Added usage datastructure - John Thompson
31
[425]32package SectionList;
33
[1483]34use List;
[425]35use sorttools;
36
[1250]37sub BEGIN {
38 @ISA = ('List');
[425]39}
40
[4759]41my $options = { 'name' => "SectionList",
[5645]42 'desc' => "{SectionList.desc}",
[4873]43 'inherits' => "Yes" };
[3540]44
[4786]45# sub print_usage {
46# print STDERR "
47# usage: classify SectionList [options]
48# options:
[1839]49
[4786]50# -metadata X Metadata field used for classification,
51# list will be sorted by this element.
[1839]52
[4786]53# -buttonname X (optional) Title field for this classification.
54# if not included title field will be Metaname.
[1839]55
[4786]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.
[1839]59
[4786]60# Same as List classifier but includes all sections of document
61# (excluding top level) rather than just top level document.
62# ";
63# }
[1839]64
[1483]65sub new {
[1839]66 my $class = shift (@_);
67 my $self = new List($class, @_);
[3540]68
[4786]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
[1611]73 return bless $self, $class;
[1483]74}
75
[425]76sub classify {
77 my $self = shift (@_);
[1250]78 my ($doc_obj, @options) = @_;
[838]79
80 my $thissection = undef;
[425]81
[838]82 my $option;
83 foreach $option (@options)
84 {
85 if ($option =~ m/^section=(\d+)$/i)
86 {
87 $thissection = $1;
88 }
89 }
[425]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
[838]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 {
[425]117 $self->classify_section($thissection, $doc_obj, $sortmeta);
118 }
119}
120
121sub 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
[545]128 if (defined $self->{'sortname'}) {
129 if (defined $self->{'metaname'}) {
[425]130
[545]131 my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
132 if (defined $metavalue) {
133 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
[1483]134 my $outhandle = $self->{'outhandle'};
135 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
[545]136 }
137 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
138 }
139 } else {
[425]140 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
[1483]141 my $outhandle = $self->{'outhandle'};
142 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
[425]143 }
144 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
145 }
[545]146
[425]147 } else {
[545]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 }
[425]157 }
158}
159
1601;
Note: See TracBrowser for help on using the repository browser.