1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # GreenstoneMETSPlugout.pm -- the plugout module for METS archives
|
---|
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) 2006 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 | package GreenstoneMETSPlugout;
|
---|
27 |
|
---|
28 | use strict;
|
---|
29 | no strict 'refs';
|
---|
30 |
|
---|
31 | #eval {require bytes};
|
---|
32 | #use util;
|
---|
33 | use METSPlugout;
|
---|
34 | #use docprint; # for escape_text
|
---|
35 |
|
---|
36 | sub BEGIN {
|
---|
37 | @GreenstoneMETSPlugout::ISA = ('METSPlugout');
|
---|
38 | }
|
---|
39 |
|
---|
40 | my $arguments = [
|
---|
41 | ];
|
---|
42 |
|
---|
43 | my $options = { 'name' => "GreenstoneMETSPlugout",
|
---|
44 | 'desc' => "{GreenstoneMETSPlugout.desc}",
|
---|
45 | 'abstract' => "no",
|
---|
46 | 'inherits' => "yes",
|
---|
47 | 'args' => $arguments
|
---|
48 | };
|
---|
49 |
|
---|
50 | sub new {
|
---|
51 | my ($class) = shift (@_);
|
---|
52 | my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
|
---|
53 | push(@$plugoutlist, $class);
|
---|
54 |
|
---|
55 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
56 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
57 |
|
---|
58 | my $self = new METSPlugout($plugoutlist,$inputargs,$hashArgOptLists);
|
---|
59 |
|
---|
60 | if ($self->{'info_only'}) {
|
---|
61 | # don't worry about any options etc
|
---|
62 | return bless $self, $class;
|
---|
63 | }
|
---|
64 |
|
---|
65 | return bless $self, $class;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | sub output_mets_xml_header
|
---|
70 | {
|
---|
71 | my $self = shift(@_);
|
---|
72 | my ($handle, $OID, $doc_title) = @_;
|
---|
73 |
|
---|
74 | my $extra_attr = "OBJID=\"$OID:2\"";
|
---|
75 |
|
---|
76 | $self->output_mets_xml_header_extra_attribute($handle,$extra_attr);
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | #
|
---|
81 | # Print out docmets.xml file
|
---|
82 | #
|
---|
83 | sub output_mets_section
|
---|
84 | {
|
---|
85 | my $self = shift(@_);
|
---|
86 | my ($handle, $doc_obj, $section, $working_dir) = @_;
|
---|
87 |
|
---|
88 | # print out the dmdSection
|
---|
89 | print $handle $self->buffer_mets_dmdSection_section_xml($doc_obj,$section);
|
---|
90 |
|
---|
91 | print $handle "<mets:fileSec>\n";
|
---|
92 |
|
---|
93 | # print out the fileSection by sections
|
---|
94 | print $handle $self->buffer_mets_fileSection_section_xml($doc_obj,$section,$working_dir);
|
---|
95 |
|
---|
96 | # print out the whole fileSection
|
---|
97 | print $handle $self->buffer_mets_fileWhole_section_xml($doc_obj,$section,$working_dir);
|
---|
98 |
|
---|
99 | print $handle "</mets:fileSec>\n";
|
---|
100 |
|
---|
101 | # print out the StructMapSection by sections
|
---|
102 |
|
---|
103 | my $struct_type = "Section";
|
---|
104 |
|
---|
105 |
|
---|
106 | # consider making the following its own subroutine
|
---|
107 |
|
---|
108 | print $handle "<mets:structMap ID=\"Section\" TYPE=\"$struct_type\" LABEL=\"Section\">\n";
|
---|
109 | my $order_num=0;
|
---|
110 | print $handle $self->buffer_mets_StructMapSection_section_xml($doc_obj,$section, \$order_num);
|
---|
111 | print $handle "</mets:structMap>\n";
|
---|
112 |
|
---|
113 | print $handle '<mets:structMap ID="All" TYPE="Whole Document" LABEL="All">'."\n";
|
---|
114 | print $handle $self->buffer_mets_StructMapWhole_section_xml($doc_obj,$section);
|
---|
115 | print $handle "</mets:structMap>\n";
|
---|
116 |
|
---|
117 |
|
---|
118 | }
|
---|
119 |
|
---|
120 | sub buffer_mets_dmdSection_section_xml
|
---|
121 | {
|
---|
122 | my $self = shift(@_);
|
---|
123 | my ($doc_obj,$section) = @_;
|
---|
124 |
|
---|
125 | $section="" unless defined $section;
|
---|
126 |
|
---|
127 | my $section_ptr=$doc_obj->_lookup_section($section);
|
---|
128 | return "" unless defined $section_ptr;
|
---|
129 |
|
---|
130 | # convert section number
|
---|
131 | my $section_num ="1". $section;
|
---|
132 | my $dmd_num = $section_num;
|
---|
133 |
|
---|
134 | my $all_text = "";
|
---|
135 |
|
---|
136 | my $label_attr = "";
|
---|
137 | # TODO::
|
---|
138 | #print STDERR "***** Check that GROUPID in dmdSec is valid!!!\n";
|
---|
139 | #print STDERR "***** Check to see if <techMD> required\n";
|
---|
140 | # if it isn't allowed, go back and set $mdTag = dmdSec/amdSec
|
---|
141 |
|
---|
142 | $all_text .= "<mets:dmdSec ID=\"DM$dmd_num\" GROUPID=\"$section_num\">\n";
|
---|
143 |
|
---|
144 | $all_text .= " <mets:mdWrap $label_attr MDTYPE=\"OTHER\" OTHERMDTYPE=\"gsdl3\" ID=\"gsdl$section_num\">\n";
|
---|
145 | $all_text .= " <mets:xmlData>\n";
|
---|
146 |
|
---|
147 | foreach my $data (@{$section_ptr->{'metadata'}}){
|
---|
148 | my $escaped_value = &docprint::escape_text($data->[1]);
|
---|
149 | $all_text .= ' <gsdl3:Metadata name="'. $data->[0].'">'. $escaped_value. "</gsdl3:Metadata>\n";
|
---|
150 | if ($data->[0] eq "dc.Title") {
|
---|
151 | $all_text .= ' <gsdl3:Metadata name="Title">'. $escaped_value."</gsdl3:Metadata>\n";
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | $all_text .= " </mets:xmlData>\n";
|
---|
156 | $all_text .= " </mets:mdWrap>\n";
|
---|
157 |
|
---|
158 | $all_text .= "</mets:dmdSec>\n";
|
---|
159 |
|
---|
160 |
|
---|
161 | foreach my $subsection (@{$section_ptr->{'subsection_order'}}){
|
---|
162 | $all_text .= $self->buffer_mets_dmdSection_section_xml($doc_obj,"$section.$subsection");
|
---|
163 | }
|
---|
164 |
|
---|
165 | $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
|
---|
166 |
|
---|
167 | return $all_text;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 | sub doctxt_to_xlink
|
---|
173 | {
|
---|
174 | my $self = shift @_;
|
---|
175 | my ($fname,$working_dir) = @_;
|
---|
176 |
|
---|
177 | my $xlink_href = "file:$fname";
|
---|
178 |
|
---|
179 | return $xlink_href;
|
---|
180 |
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | sub buffer_mets_fileSection_section_xml
|
---|
186 | {
|
---|
187 | my $self = shift(@_);
|
---|
188 | my ($doc_obj,$section,$working_dir,$is_recursive) = @_;
|
---|
189 |
|
---|
190 | my $is_txt_split = undef;
|
---|
191 |
|
---|
192 | my $all_text
|
---|
193 | = $self->SUPER::buffer_mets_fileSection_section_xml($doc_obj,$section,$working_dir,$is_txt_split);
|
---|
194 |
|
---|
195 | return $all_text;
|
---|
196 | }
|
---|
197 |
|
---|
198 | sub buffer_mets_fileWhole_section_xml
|
---|
199 | {
|
---|
200 | my $self = shift(@_);
|
---|
201 | my ($doc_obj,$section,$working_dir) = @_;
|
---|
202 |
|
---|
203 | my $section_ptr = $doc_obj-> _lookup_section($section);
|
---|
204 | return "" unless defined $section_ptr;
|
---|
205 |
|
---|
206 | my $all_text="";
|
---|
207 |
|
---|
208 | my $fileID=0;
|
---|
209 |
|
---|
210 | # Output the fileSection for the whole section
|
---|
211 | # => get the sourcefile and associative file
|
---|
212 |
|
---|
213 | my $id_root = "default";
|
---|
214 | my $opt_owner_id = "";
|
---|
215 |
|
---|
216 | $all_text .= " <mets:fileGrp ID=\"$id_root\">\n";
|
---|
217 |
|
---|
218 |
|
---|
219 | foreach my $data (@{$section_ptr->{'metadata'}}){
|
---|
220 | my $escaped_value = &docprint::escape_text($data->[1]);
|
---|
221 |
|
---|
222 | if ($data->[0] eq "gsdlsourcefilename") {
|
---|
223 | my ($dirPath) = $escaped_value =~ m/^(.*)[\/\\][^\/\\]*$/;
|
---|
224 |
|
---|
225 | ++$fileID;
|
---|
226 | $all_text .= " <mets:file MIMETYPE=\"text/xml\" ID=\"$id_root.$fileID\" $opt_owner_id >\n";
|
---|
227 |
|
---|
228 | $all_text .= ' <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$data->[1].'" />'."\n";
|
---|
229 |
|
---|
230 | $all_text .= " </mets:file>\n";
|
---|
231 | }
|
---|
232 |
|
---|
233 | if ($data->[0] eq "gsdlassocfile"){
|
---|
234 |
|
---|
235 | $escaped_value =~ m/^(.*?):(.*):(.*)$/;
|
---|
236 | my $assoc_file = $1;
|
---|
237 | my $mime_type = $2;
|
---|
238 | my $assoc_dir = $3;
|
---|
239 |
|
---|
240 | my $assfilePath = ($assoc_dir eq "") ? $assoc_file : "$assoc_dir/$assoc_file";
|
---|
241 | ++$fileID;
|
---|
242 |
|
---|
243 | my $mime_attr = "MIMETYPE=\"$mime_type\"";
|
---|
244 | my $xlink_title = "xlink:title=\"$assoc_file\"";
|
---|
245 |
|
---|
246 | my $id_attr;
|
---|
247 | my $xlink_href;
|
---|
248 |
|
---|
249 | $id_attr = "ID=\"$id_root.$fileID\"";
|
---|
250 | $xlink_href = "xlink:href=\"$assfilePath\"";
|
---|
251 |
|
---|
252 | $all_text .= " <mets:file $mime_attr $id_attr $opt_owner_id >\n";
|
---|
253 | $all_text .= " <mets:FLocat LOCTYPE=\"URL\" $xlink_href $xlink_title />\n";
|
---|
254 |
|
---|
255 | $all_text .= " </mets:file>\n";
|
---|
256 |
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | $all_text .= " </mets:fileGrp>\n";
|
---|
261 |
|
---|
262 | $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
|
---|
263 |
|
---|
264 | return $all_text;
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | 1;
|
---|