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

Last change on this file since 8915 was 8716, checked in by kjdon, 20 years ago

added some changes made by Emanuel Dejanu (Simple Words)

  • Property svn:keywords set to Author Date Id Revision
File size: 5.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 @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}
86
87
88sub xml_start_tag {
89 my $self = shift(@_);
90 my ($expat, $element) = @_;
91
92 $self->{'element'} = $element;
93 if ($element eq "Section") {
94 if ($self->{'section_level'} == 0) {
95 $self->open_document();
96 } else {
97 my $doc_obj = $self->{'doc_obj'};
98 $self->{'section'} =
99 $doc_obj->insert_section($doc_obj->get_end_child($self->{'section'}));
100 }
101
102 $self->{'section_level'} ++;
103 }
104 elsif ($element eq "Metadata") {
105 $self->{'metadata_name'} = $_{'name'};
106 }
107}
108
109sub xml_end_tag {
110 my $self = shift(@_);
111 my ($expat, $element) = @_;
112
113 if ($element eq "Section") {
114 $self->{'section_level'} --;
115 $self->{'section'} = $self->{'doc_obj'}->get_parent_section ($self->{'section'});
116 $self->close_document() if $self->{'section_level'} == 0;
117 }
118 elsif ($element eq "Metadata") {
119 $self->{'doc_obj'}->add_utf8_metadata($self->{'section'}, $self->{'metadata_name'},$self->{'metadata_value'});
120 $self->{'metadata_name'} = "";
121 $self->{'metadata_value'} = "";
122 }
123 elsif ($element eq "Content" && $self->{'content'} ne "") {
124 $self->{'doc_obj'}->add_utf8_text($self->{'section'}, $self->{'content'});
125 $self->{'content'} = "";
126 }
127
128 $self->{'element'} = "";
129}
130
131sub xml_text {
132 my $self = shift(@_);
133 my ($expat) = @_;
134
135 if ($self->{'element'} eq "Metadata") {
136 $self->{'metadata_value'} .= $_;
137 }
138 elsif ($self->{'element'} eq "Content") {
139 $self->{'content'} .= $_;
140 }
141}
142
143sub open_document {
144 my $self = shift(@_);
145
146 # create a new document
147 $self->{'doc_obj'} = new doc ();
148 $self->{'section'} = "";
149}
150
151sub close_document {
152 my $self = shift(@_);
153
154 # add the associated files
155 my $assoc_files =
156 $self->{'doc_obj'}->get_metadata($self->{'doc_obj'}->get_top_section(), "gsdlassocfile");
157
158 # for when "assocfilepath" isn't the same directory that doc.xml is in...
159 my $assoc_filepath_list= $self->{'doc_obj'}->get_metadata($self->{'doc_obj'}->get_top_section(), "assocfilepath");
160
161 my $assoc_filepath=shift (@$assoc_filepath_list);
162 if (defined ($assoc_filepath)) {
163 # make absolute rather than relative...
164 $self->{'filename'} =~ m@^(.*[\\/]archives)@;
165 $assoc_filepath = "$1/$assoc_filepath/";
166 } else {
167 $assoc_filepath = $self->{'filename'};
168 $assoc_filepath =~ s/[^\\\/]*$//;
169 }
170
171 foreach my $assoc_file_info (@$assoc_files) {
172 my ($assoc_file, $mime_type, $dir) = split (":", $assoc_file_info);
173 my $real_dir = &util::filename_cat($assoc_filepath, $assoc_file),
174 my $assoc_dir = (defined $dir && $dir ne "")
175 ? &util::filename_cat($dir, $assoc_file) : $assoc_file;
176 $self->{'doc_obj'}->associate_file($real_dir, $assoc_dir, $mime_type);
177 }
178 $self->{'doc_obj'}->delete_metadata($self->{'doc_obj'}->get_top_section(), "gsdlassocfile");
179
180 # process the document
181 $self->{'processor'}->process($self->{'doc_obj'}, $self->{'file'});
182}
183
184
1851;
186
187
Note: See TracBrowser for help on using the repository browser.