########################################################################### # # SectionList.pm -- # A component of the Greenstone digital library software # from the New Zealand Digital Library Project at the # University of Waikato, New Zealand. # # Copyright (C) 1999 New Zealand Digital Library Project # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ########################################################################### # Same as List classifier but includes all sections of document # (excluding top level) rather than just top level document # itself # 12/05/02 Added usage datastructure - John Thompson package SectionList; use List; use sorttools; sub BEGIN { @ISA = ('List'); } my $options = { 'name' => "SectionList", 'desc' => "{SectionList.desc}", 'abstract' => "no", 'inherits' => "yes" }; sub new { my $class = shift (@_); my $self = new List($class, @_); # 14-05-02 To allow for proper inheritance of arguments - John Thompson my $option_list = $self->{'option_list'}; push( @{$option_list}, $options ); #if ($self->{'info_only'}) { # created from classinfo.pl - don't need to parse the arguments # return bless $self, $class; #} return bless $self, $class; } sub classify { my $self = shift (@_); my ($doc_obj, @options) = @_; # @options used by AZCompactList when is uses SectionList internally # are we sorting the list?? my $nosort = 0; if (defined $self->{'sortname'} && $self->{'sortname'} eq "nosort") { $nosort = 1; } my $thissection = undef; my $option; foreach $option (@options) { if ($option =~ m/^section=(\d+)$/i) { $thissection = $1; } } my $sortmeta = ""; if (!$nosort && defined $self->{'sortname'}) { if ($self->{'sortname'} =~ /^filename$/i) { $sortmeta = $doc_obj->get_source_filename(); } else { $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'sortname'}); if (defined $sortmeta) { $sortmeta = $self->format_metadata_for_sorting($self->{'sortname'}, $sortmeta, $doc_obj); } } $sortmeta = "" unless defined $sortmeta; } if (defined $thissection) { # just classify the one section $self->classify_section($thissection, $doc_obj, $sortmeta, $nosort); } else { $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section()); while (defined $thissection) { $self->classify_section($thissection, $doc_obj, $sortmeta, $nosort); $thissection = $doc_obj->get_next_section ($thissection); } } } sub classify_section { my $self = shift (@_); my ($section, $doc_obj, $sortmeta, $nosort) = @_; my $doc_OID = $doc_obj->get_OID(); $nosort = 0 unless defined $nosort; $sortmeta = "" unless defined $sortmeta; my $metavalue; my $metaname; if (defined $self->{'meta_list'}) { # find the first available metadata foreach $m (@{$self->{'meta_list'}}) { $metavalue = $doc_obj->get_metadata_element($section, $m); $metaname = $m; last if defined $metavalue; } #if we haven't found a metavalue here, then the section shouldn't be included return unless defined $metavalue; } # we know the section should be included, add it now if we are not sorting if ($nosort) { push (@{$self->{'list'}}, "$doc_OID.$section"); return; } # check that it hasn't been added already if (defined $self->{'list'}->{"$doc_OID.$section"}) { my $outhandle = $self->{'outhandle'}; print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n"; } if (defined $self->{'sortname'}) { # sorting on alternative metadata $self->{'list'}->{"$doc_OID.$section"} = $sortmeta; } else { # sortingon the classification metadata # do the same formatting on the meta value as for sort meta $metavalue = $self->format_metadata_for_sorting($metaname, $metavalue, $doc_obj); $self->{'list'}->{"$doc_OID.$section"} = $metavalue; } } 1;