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

Last change on this file since 9468 was 9468, checked in by kjdon, 19 years ago

added a gli processing message

  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 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 @GAPlug::ISA = ('XMLPlug');
37}
38
39
40sub get_default_process_exp {
41 my $self = shift (@_);
42
43 return q^(?i)doc\.xml$^;
44}
45
46my $options = { 'name' => "GAPlug",
47 'desc' => "{GAPlug.desc}",
48 'abstract' => "no",
49 'inherits' => "yes" };
50
51sub new {
52 my $class = shift (@_);
53 my $self = new XMLPlug ($class, @_);
54
55 # 14-05-02 To allow for proper inheritance of arguments - John Thompson
56 my $option_list = $self->{'option_list'};
57 push( @{$option_list}, $options );
58
59 $self->{'section'} = "";
60 $self->{'section_level'} = 0;
61 $self->{'metadata_name'} = "";
62 $self->{'metadata_value'} = "";
63 $self->{'content'} = "";
64
65 return bless $self, $class;
66}
67
68sub xml_start_document {
69}
70
71sub xml_end_document {
72}
73
74sub xml_doctype {
75 my $self = shift(@_);
76
77 my ($expat, $name, $sysid, $pubid, $internal) = @_;
78
79 # allow the short-lived and badly named "GreenstoneArchive" files to be processed
80 # as well as the "Archive" files which should now be created by import.pl
81 die "" if ($name !~ /^(Greenstone)?Archive$/);
82
83 my $outhandle = $self->{'outhandle'};
84 print $outhandle "GAPlug: processing $self->{'file'}\n" if $self->{'verbosity'} > 1;
85 print STDERR "<Processing n='$self->{'file'}' p='GAPlug'>\n" if $self->{'gli'};
86
87}
88
89
90sub xml_start_tag {
91 my $self = shift(@_);
92 my ($expat, $element) = @_;
93
94 $self->{'element'} = $element;
95 if ($element eq "Section") {
96 if ($self->{'section_level'} == 0) {
97 $self->open_document();
98 } else {
99 my $doc_obj = $self->{'doc_obj'};
100 $self->{'section'} =
101 $doc_obj->insert_section($doc_obj->get_end_child($self->{'section'}));
102 }
103
104 $self->{'section_level'} ++;
105 }
106 elsif ($element eq "Metadata") {
107 $self->{'metadata_name'} = $_{'name'};
108 }
109}
110
111sub xml_end_tag {
112 my $self = shift(@_);
113 my ($expat, $element) = @_;
114
115 if ($element eq "Section") {
116 $self->{'section_level'} --;
117 $self->{'section'} = $self->{'doc_obj'}->get_parent_section ($self->{'section'});
118 $self->close_document() if $self->{'section_level'} == 0;
119 }
120 elsif ($element eq "Metadata") {
121 $self->{'doc_obj'}->add_utf8_metadata($self->{'section'}, $self->{'metadata_name'},$self->{'metadata_value'});
122 $self->{'metadata_name'} = "";
123 $self->{'metadata_value'} = "";
124 }
125 elsif ($element eq "Content" && $self->{'content'} ne "") {
126 $self->{'doc_obj'}->add_utf8_text($self->{'section'}, $self->{'content'});
127 $self->{'content'} = "";
128 }
129
130 $self->{'element'} = "";
131}
132
133sub xml_text {
134 my $self = shift(@_);
135 my ($expat) = @_;
136
137 if ($self->{'element'} eq "Metadata") {
138 $self->{'metadata_value'} .= $_;
139 }
140 elsif ($self->{'element'} eq "Content") {
141 $self->{'content'} .= $_;
142 }
143}
144
145sub open_document {
146 my $self = shift(@_);
147
148 # create a new document
149 $self->{'doc_obj'} = new doc ();
150 $self->{'section'} = "";
151}
152
153sub close_document {
154 my $self = shift(@_);
155
156 # add the associated files
157 my $assoc_files =
158 $self->{'doc_obj'}->get_metadata($self->{'doc_obj'}->get_top_section(), "gsdlassocfile");
159
160 # for when "assocfilepath" isn't the same directory that doc.xml is in...
161 my $assoc_filepath_list= $self->{'doc_obj'}->get_metadata($self->{'doc_obj'}->get_top_section(), "assocfilepath");
162
163 my $assoc_filepath=shift (@$assoc_filepath_list);
164 if (defined ($assoc_filepath)) {
165 # make absolute rather than relative...
166 $self->{'filename'} =~ m@^(.*[\\/]archives)@;
167 $assoc_filepath = "$1/$assoc_filepath/";
168 } else {
169 $assoc_filepath = $self->{'filename'};
170 $assoc_filepath =~ s/[^\\\/]*$//;
171 }
172
173 foreach my $assoc_file_info (@$assoc_files) {
174 my ($assoc_file, $mime_type, $dir) = split (":", $assoc_file_info);
175 my $real_dir = &util::filename_cat($assoc_filepath, $assoc_file),
176 my $assoc_dir = (defined $dir && $dir ne "")
177 ? &util::filename_cat($dir, $assoc_file) : $assoc_file;
178 $self->{'doc_obj'}->associate_file($real_dir, $assoc_dir, $mime_type);
179 }
180 $self->{'doc_obj'}->delete_metadata($self->{'doc_obj'}->get_top_section(), "gsdlassocfile");
181
182 # process the document
183 $self->{'processor'}->process($self->{'doc_obj'}, $self->{'file'});
184}
185
186
1871;
188
189
Note: See TracBrowser for help on using the repository browser.