1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # 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 |
|
---|
28 | package doc;
|
---|
29 |
|
---|
30 | use basedoc;
|
---|
31 |
|
---|
32 | BEGIN {
|
---|
33 | @ISA = ('basedoc');
|
---|
34 | }
|
---|
35 |
|
---|
36 | # the document type may be indexed_doc, nonindexed_doc, or
|
---|
37 | # classification
|
---|
38 |
|
---|
39 | sub new {
|
---|
40 | my $class = shift (@_);
|
---|
41 | my ($source_filename, $doc_type) = @_;
|
---|
42 |
|
---|
43 | my $self = new basedoc();
|
---|
44 |
|
---|
45 | # $self->set_source_filename ($source_filename) if defined $source_filename;
|
---|
46 | push (@{$self->{'metadata'}}, ["gsdlsourcefilename", &unicode::ascii2utf8($source_filename)])
|
---|
47 | if defined $source_filename;
|
---|
48 | # $self->set_doc_type ($doc_type) if defined $doc_type;
|
---|
49 | push (@{$self->{'metadata'}}, ["gsdldoctype", &unicode::ascii2utf8($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 | # set_metadata_element assumes the value is in (extended) ascii form.
|
---|
63 | # For text which hash been already converted to the UTF-8 format use
|
---|
64 | # set_utf8_metadata_element.
|
---|
65 | sub set_metadata_element {
|
---|
66 | my $self = shift (@_);
|
---|
67 | my ($section, $field, $value) = @_;
|
---|
68 |
|
---|
69 | $self->set_utf8_metadata_element ($section, $field,
|
---|
70 | &unicode::ascii2utf8($value));
|
---|
71 | }
|
---|
72 |
|
---|
73 | # set_utf8_metadata_element assumes the text has already been
|
---|
74 | # converted to the UTF-8 encoding.
|
---|
75 | sub set_utf8_metadata_element {
|
---|
76 | my $self = shift (@_);
|
---|
77 | my ($section, $field, $value) = @_;
|
---|
78 |
|
---|
79 | $self->delete_metadata ($section, $field);
|
---|
80 | $self->add_utf8_metadata ($section, $field, $value);
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | # add_metadata assumes the text is in (extended) ascii form. For
|
---|
85 | # text which hash been already converted to the UTF-8 format use
|
---|
86 | # add_utf8_metadata.
|
---|
87 | sub add_metadata {
|
---|
88 | my $self = shift (@_);
|
---|
89 | my ($section, $field, $value) = @_;
|
---|
90 |
|
---|
91 | $self->add_utf8_metadata ($section, $field,
|
---|
92 | &unicode::ascii2utf8($value));
|
---|
93 | }
|
---|
94 |
|
---|
95 | # add_utf8_metadata assumes the text has already been converted
|
---|
96 | # to the UTF-8 encoding.
|
---|
97 | sub add_utf8_metadata {
|
---|
98 | my $self = shift (@_);
|
---|
99 | my ($section, $field, $value) = @_;
|
---|
100 |
|
---|
101 | my $section_ptr = $self->_lookup_section($section);
|
---|
102 | if (!defined $section_ptr) {
|
---|
103 | print STDERR "doc::add_utf8_metadata couldn't find section " .
|
---|
104 | "$section\n";
|
---|
105 | return;
|
---|
106 | }
|
---|
107 |
|
---|
108 | push (@{$section_ptr->{'metadata'}}, [$field, $value]);
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 | # methods for dealing with text
|
---|
113 |
|
---|
114 | # add_text assumes the text is in (extended) ascii form. For
|
---|
115 | # text which has been already converted to the UTF-8 format
|
---|
116 | # use add_utf8_text.
|
---|
117 | sub add_text {
|
---|
118 | my $self = shift (@_);
|
---|
119 | my ($section, $text) = @_;
|
---|
120 |
|
---|
121 | # convert the text to UTF-8 encoded unicode characters
|
---|
122 | # and add the text
|
---|
123 | $self->add_utf8_text($section, &unicode::ascii2utf8($text));
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | # add_utf8_text assumes the text to be added has already
|
---|
128 | # been converted to the UTF-8 encoding. For ascii text use
|
---|
129 | # add_text
|
---|
130 | sub add_utf8_text {
|
---|
131 | my $self = shift (@_);
|
---|
132 | my ($section, $text) = @_;
|
---|
133 |
|
---|
134 | my $section_ptr = $self->_lookup_section($section);
|
---|
135 | if (!defined $section_ptr) {
|
---|
136 | print STDERR "doc::add_utf8_text couldn't find section " .
|
---|
137 | "$section\n";
|
---|
138 | return;
|
---|
139 | }
|
---|
140 |
|
---|
141 | $section_ptr->{'text'} .= $text;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | 1;
|
---|