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

Last change on this file since 6408 was 6408, checked in by jmt12, 20 years ago

Added two new attributes for script arguments. HiddenGLI controls whether the argument will be visible at all in GLI, while ModeGLI defines the lowest detail mode under which the argument will be visible (only really for import and buildcol). Also ensured that the scripts were reporting their correct default process expressions, and further refined argument types by adding the catagory regexp for any regular expression (which can then be hidden under lower detail modes in GLI)

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