source: trunk/gsdl/perllib/plugins/GAPlug.pm@ 2812

Last change on this file since 2812 was 2812, checked in by sjboddie, 22 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1###########################################################################
2#
3# GAPlug.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) 2001 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# Processes GreenstoneArchive XML documents. Note that this plugin does no
27# syntax checking (though the XML::Parser module tests for
28# well-formedness). It's assumed that the GreenstoneArchive files conform
29# to their DTD.
30
31package GAPlug;
32
33use XMLPlug;
34
35sub BEGIN {
36 @ISA = ('XMLPlug');
37}
38
39sub new {
40 my $class = shift (@_);
41 my $self = new XMLPlug ($class, @_);
42
43 $self->{'section'} = "";
44 $self->{'section_level'} = 0;
45 $self->{'metadata_name'} = "";
46 $self->{'metadata_value'} = "";
47 $self->{'content'} = "";
48
49 return bless $self, $class;
50}
51
52sub xml_start_document {
53}
54
55sub xml_end_document {
56}
57
58sub xml_doctype {
59 my $self = shift(@_);
60 my ($expat, $name, $sysid, $pubid, $internal) = @_;
61
62 die "" if ($name ne "GreenstoneArchive");
63 my $outhandle = $self->{'outhandle'};
64 print $outhandle "GAPLug: processing $self->{'file'}\n";
65}
66
67
68sub xml_start_tag {
69 my $self = shift(@_);
70 my ($expat, $element) = @_;
71
72 $self->{'element'} = $element;
73 if ($element eq "Section") {
74 if ($self->{'section_level'} == 0) {
75 $self->open_document();
76 } else {
77 my $doc_obj = $self->{'doc_obj'};
78 $self->{'section'} =
79 $doc_obj->insert_section($doc_obj->get_end_child($self->{'section'}));
80 }
81 $self->{'section_level'} ++;
82 }
83 elsif ($element eq "Metadata") {
84 $self->{'metadata_name'} = $_{'name'};
85 }
86}
87
88sub xml_end_tag {
89 my $self = shift(@_);
90 my ($expat, $element) = @_;
91
92 if ($element eq "Section") {
93 $self->{'section_level'} --;
94 $self->{'section'} = $self->{'doc_obj'}->get_parent_section ($self->{'section'});
95 $self->close_document() if $self->{'section_level'} == 0;
96 }
97 elsif ($element eq "Metadata") {
98 $self->{'doc_obj'}->add_utf8_metadata($self->{'section'}, $self->{'metadata_name'},
99 $self->{'metadata_value'});
100 $self->{'metadata_name'} = "";
101 $self->{'metadata_value'} = "";
102 }
103 elsif ($element eq "Content" && $self->{'content'} ne "") {
104 $self->{'doc_obj'}->add_utf8_text($self->{'section'}, $self->{'content'});
105 $self->{'content'} = "";
106 }
107
108 $self->{'element'} = "";
109}
110
111sub xml_text {
112 my $self = shift(@_);
113 my ($expat) = @_;
114
115 if ($self->{'element'} eq "Metadata") {
116 $self->{'metadata_value'} .= $_;
117 }
118 elsif ($self->{'element'} eq "Content") {
119 $self->{'content'} .= $_;
120 }
121}
122
123sub open_document {
124 my $self = shift(@_);
125
126 # create a new document
127 $self->{'doc_obj'} = new doc ();
128 $self->{'section'} = "";
129}
130
131sub close_document {
132 my $self = shift(@_);
133
134 # add the associated files
135 my $assoc_files =
136 $self->{'doc_obj'}->get_metadata($self->{'doc_obj'}->get_top_section(), "gsdlassocfile");
137
138 my $parent_dir = $self->{'filename'};
139 $parent_dir =~ s/[^\\\/]*$//;
140
141 foreach my $assoc_file_info (@$assoc_files) {
142 my ($assoc_file, $mime_type, $dir) = split (":", $assoc_file_info);
143 my $real_dir = &util::filename_cat($parent_dir, $assoc_file),
144 my $assoc_dir = (defined $dir && $dir ne "")
145 ? &util::filename_cat($dir, $assoc_file) : $assoc_file;
146 $self->{'doc_obj'}->associate_file($real_dir, $assoc_dir, $mime_type);
147 }
148 $self->{'doc_obj'}->delete_metadata($self->{'doc_obj'}->get_top_section(), "gsdlassocfile");
149
150 # process the document
151 $self->{'processor'}->process($self->{'doc_obj'}, $self->{'file'});
152}
153
154
1551;
Note: See TracBrowser for help on using the repository browser.