source: trunk/gsdl/perllib/ascii_doc.pm@ 833

Last change on this file since 833 was 833, checked in by davidb, 24 years ago

new doc type for ascii only documents (lots faster the doc.pm)

  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1###########################################################################
2#
3# ascii_doc.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# class to hold documents
27
28package ascii_doc;
29
30use basedoc;
31
32
33BEGIN {
34 @ISA = ('basedoc');
35}
36
37# the document type may be indexed_doc, nonindexed_doc, or
38# classification
39
40sub new {
41 my $class = shift (@_);
42 my ($source_filename, $doc_type) = @_;
43
44 my $self = new basedoc();
45
46 push (@{$self->{'metadata'}}, ["gsdlsourcefilename", $source_filename])
47 if defined $source_filename;
48
49 push (@{$self->{'metadata'}}, ["gsdldoctype", $doc_type])
50 if defined $doc_type;
51
52 bless ($self, $class);
53 return $self;
54}
55
56# methods for dealing with metadata
57
58# set_metadata_element and get_metadata_element are for metadata
59# which should only have one value. add_meta_data and get_metadata
60# are for metadata which can have more than one value.
61
62
63# set_metadata_element assumes the text is in ASCII form (subset of UTF8)
64sub set_metadata_element {
65 my $self = shift (@_);
66 my ($section, $field, $value) = @_;
67
68 $self->delete_metadata ($section, $field);
69 $self->add_metadata ($section, $field, $value);
70}
71
72# add_metadata assumes the text is in ASCII form (subset of UTF8)
73sub add_metadata {
74 my $self = shift (@_);
75 my ($section, $field, $value) = @_;
76
77 my $section_ptr = $self->_lookup_section($section);
78 if (!defined $section_ptr) {
79 print STDERR "doc::add_metadata couldn't find section " .
80 "$section\n";
81 return;
82 }
83
84 push (@{$section_ptr->{'metadata'}}, [$field, $value]);
85}
86
87
88# methods for dealing with text
89
90# add_text assumes the text is in ASCII form (subset of UTF8)
91sub add_text {
92 my $self = shift (@_);
93 my ($section, $text) = @_;
94
95 my $section_ptr = $self->_lookup_section($section);
96 if (!defined $section_ptr) {
97 print STDERR "doc::add_text couldn't find section " .
98 "$section\n";
99 return;
100 }
101
102 $section_ptr->{'text'} .= $text;
103}
104
1051;
106
Note: See TracBrowser for help on using the repository browser.