source: trunk/gsdl/perllib/classify/AZSectionList.pm@ 6111

Last change on this file since 6111 was 6111, checked in by jmt12, 20 years ago

Changed the description for the -metadata flag to foreshadow the coming enhancement. This commit also happens to include the prototype -ignore_arguments flag to AZList, that will never actually be used because of the aforementioned metadata enhancement.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
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
38package AZSectionList;
39
40use AZList;
41use sorttools;
42
43sub BEGIN {
44 @ISA = ('AZList');
45}
46
47my $arguments =
48 [ { 'name' => "metadata",
49 'desc' => "{List.metadata}",
50 'type' => "metadata",
51 'reqd' => "yes" },
52 { 'name' => "buttonname",
53 'desc' => "{AZList.buttonname}",
54 'type' => "string",
55 'deft' => "Metadata element specified with -metadata",
56 'reqd' => "no" } ];
57
58my $options = { 'name' => "AZSectionList",
59 'desc' => "{AZSectionList.desc}",
60 'inherits' => "Yes",
61 'args' => $arguments };
62
63# sub print_usage {
64# print STDERR "
65# usage: classify AZSectionList [options]
66# options:
67
68# -metadata X (required) Metadata field used for classification,
69# list will be sorted by this element.
70
71# -buttonname X (OPTIONAL) Title field for this classification.
72# if not included title field will be Metaname.
73
74# -removeprefix regex A prefix to ignore in the Metadata values
75# for the field when sorting.
76# This is very similar to AZList except it sorts by section level metadata
77# (excluding the top level) instead of just top level metadata.
78# ";
79# }
80
81sub new {
82 my $class = shift (@_);
83 my $self = new AZList($class, @_);
84
85 # 14-05-02 To allow for proper inheritance of arguments - John Thompson
86 my $option_list = $self->{'option_list'};
87 push( @{$option_list}, $options );
88
89 return bless $self, $class;
90}
91
92sub classify {
93 my $self = shift (@_);
94 my ($doc_obj) = @_;
95
96 my $doc_OID = $doc_obj->get_OID();
97 my $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
98
99 while (defined $thissection) {
100 $self->classify_section ($thissection, $doc_obj);
101 $thissection = $doc_obj->get_next_section ($thissection);
102 }
103}
104
105sub classify_section {
106 my $self = shift (@_);
107 my ($section, $doc_obj) = @_;
108
109 my $doc_OID = $doc_obj->get_OID();
110 my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
111
112 # if this section doesn't contain the metadata element we're
113 # sorting by we won't include it in this classification
114
115 if (defined $metavalue && $metavalue ne "") {
116 if ($self->{'removeprefix'}) {
117 $metavalue =~ s/^$self->{'removeprefix'}//;
118 }
119 if ($self->{'metaname'} eq 'Creator') {
120 &sorttools::format_string_name_english (\$metavalue);
121 } else {
122 &sorttools::format_string_english (\$metavalue);
123 }
124 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
125 my $outhandle = $self->{'outhandle'};
126 print $outhandle "WARNING: AZSectionList::classify called multiple times " .
127 "for $doc_OID.$section\n";
128 }
129 $self->{'list'}->{"$doc_OID.$section"} = $metavalue;
130 }
131}
132
133
1341;
Note: See TracBrowser for help on using the repository browser.