1 | /**
|
---|
2 | *############################################################################
|
---|
3 | * A component of the Greenstone Librarian Interface, part of the Greenstone
|
---|
4 | * digital library suite from the New Zealand Digital Library Project at the
|
---|
5 | * University of Waikato, New Zealand.
|
---|
6 | *
|
---|
7 | * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
|
---|
8 | *
|
---|
9 | * Copyright (C) 2004 New Zealand Digital Library Project
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | *############################################################################
|
---|
25 | */
|
---|
26 |
|
---|
27 | package org.greenstone.gatherer.metadata;
|
---|
28 |
|
---|
29 |
|
---|
30 | import java.io.*;
|
---|
31 | import java.util.*;
|
---|
32 | import java.net.URLDecoder;
|
---|
33 | import org.greenstone.gatherer.DebugStream;
|
---|
34 | import org.greenstone.gatherer.util.Utility;
|
---|
35 |
|
---|
36 |
|
---|
37 | /** This class represents one doc.xml file */
|
---|
38 |
|
---|
39 | public abstract class DocXMLFile extends File
|
---|
40 | {
|
---|
41 | protected HashMap source_file_name_to_description_elements_mapping = new HashMap();
|
---|
42 |
|
---|
43 | protected static String MetadataWrap = null;
|
---|
44 | protected static String MetadataItem = null;
|
---|
45 |
|
---|
46 | public DocXMLFile(String doc_xml_file_path)
|
---|
47 | {
|
---|
48 | super(doc_xml_file_path);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | public ArrayList getMetadataExtractedFromFile(File file)
|
---|
53 | {
|
---|
54 | // Build up a list of metadata extracted from this file
|
---|
55 | ArrayList metadata_values = new ArrayList();
|
---|
56 |
|
---|
57 | String file_relative_path = file.getAbsolutePath();
|
---|
58 | int import_index = file_relative_path.indexOf("import");
|
---|
59 | if (import_index != -1) {
|
---|
60 | file_relative_path = file_relative_path.substring(import_index + "import".length() + 1);
|
---|
61 | }
|
---|
62 |
|
---|
63 | // Check whether this file (i.e. doc.xml or docmets.xml on inheritance) file contains extracted metadata for the specified file
|
---|
64 | ArrayList description_elements_list = (ArrayList) source_file_name_to_description_elements_mapping.get(file_relative_path);
|
---|
65 | if (description_elements_list == null) {
|
---|
66 | // ...it doesn't
|
---|
67 | return metadata_values;
|
---|
68 | }
|
---|
69 |
|
---|
70 | MetadataSet extracted_metadata_set = MetadataSetManager.getMetadataSet(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE);
|
---|
71 |
|
---|
72 | // Parse the file
|
---|
73 | DebugStream.println("Applicable file: " + this);
|
---|
74 | try {
|
---|
75 | BufferedReader buffered_reader = new BufferedReader(new FileReader(this));
|
---|
76 |
|
---|
77 | int description_element_num = 0;
|
---|
78 | int next_description_element_start = ((Integer) description_elements_list.get(description_element_num)).intValue();
|
---|
79 | boolean in_relevant_description_element = false;
|
---|
80 |
|
---|
81 | String line = null;
|
---|
82 | for (int line_num = 0; (line = buffered_reader.readLine()) != null; line_num++) {
|
---|
83 | // Check if this line contains the start of a relevant "Description" element
|
---|
84 | // (mets:xmlData in METS parlance, Description in GreenstoneArchive format)
|
---|
85 | if (line_num == next_description_element_start) {
|
---|
86 | in_relevant_description_element = true;
|
---|
87 | continue;
|
---|
88 | }
|
---|
89 |
|
---|
90 | // If we're not in a relevant Description element we don't care about anything
|
---|
91 | if (in_relevant_description_element == false) {
|
---|
92 | continue;
|
---|
93 | }
|
---|
94 |
|
---|
95 | // Check if this line contains the end of the relevant Description element
|
---|
96 | if (line.indexOf("</"+MetadataWrap+">") != -1) {
|
---|
97 | description_element_num++;
|
---|
98 | if (description_element_num == description_elements_list.size()) {
|
---|
99 | break;
|
---|
100 | }
|
---|
101 |
|
---|
102 | next_description_element_start = ((Integer) description_elements_list.get(description_element_num)).intValue();
|
---|
103 | in_relevant_description_element = false;
|
---|
104 | continue;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // If this line doesn't contain a complete Metadata element, we're not interested
|
---|
108 | if (line.indexOf("<"+MetadataItem+" ") == -1 || line.indexOf("</"+MetadataItem+">") == -1) {
|
---|
109 | continue;
|
---|
110 | }
|
---|
111 |
|
---|
112 | // Extract the metadata element name
|
---|
113 | int name_index = line.indexOf(" name=\"") + " name=\"".length();
|
---|
114 | String metadata_element_name_full = line.substring(name_index, line.indexOf("\"", name_index));
|
---|
115 |
|
---|
116 | // If the metadata has a namespace it isn't extracted metadata, so we're not interested
|
---|
117 | String metadata_set_namespace = MetadataTools.getMetadataSetNamespace(metadata_element_name_full);
|
---|
118 | if (!metadata_set_namespace.equals("")) {
|
---|
119 | continue;
|
---|
120 | }
|
---|
121 |
|
---|
122 | // Extracted metadata!
|
---|
123 | String metadata_element_name = metadata_element_name_full;
|
---|
124 |
|
---|
125 | // We completely ignore bibliographic data
|
---|
126 | if (metadata_element_name.equals("SourceSegment")) {
|
---|
127 | buffered_reader.close();
|
---|
128 | return new ArrayList();
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Ignore metadata starting with gsdl (used to be lowercase metadata and /metadata)
|
---|
132 | if (metadata_element_name.startsWith("gsdl")) {
|
---|
133 | continue;
|
---|
134 | }
|
---|
135 |
|
---|
136 | MetadataElement metadata_element = extracted_metadata_set.getMetadataElementWithName(metadata_element_name);
|
---|
137 |
|
---|
138 | // Value trees are not stored for extracted metadata, so create a new value tree node now
|
---|
139 | int value_index = line.indexOf(">", name_index) + ">".length();
|
---|
140 | String metadata_element_value = line.substring(value_index, line.lastIndexOf("</"+MetadataItem+">"));
|
---|
141 |
|
---|
142 | metadata_element.addMetadataValue(metadata_element_value);
|
---|
143 | MetadataValueTreeNode metadata_value_tree_node = metadata_element.getMetadataValueTreeNode(metadata_element_value);
|
---|
144 |
|
---|
145 | // Add the new metadata value to the list
|
---|
146 | MetadataValue metadata_value = new MetadataValue(metadata_element, metadata_value_tree_node);
|
---|
147 | metadata_values.add(metadata_value);
|
---|
148 | }
|
---|
149 |
|
---|
150 | buffered_reader.close();
|
---|
151 | }
|
---|
152 | catch (FileNotFoundException exception) {
|
---|
153 | DebugStream.printStackTrace(exception);
|
---|
154 | }
|
---|
155 | catch (IOException exception) {
|
---|
156 | DebugStream.printStackTrace(exception);
|
---|
157 | }
|
---|
158 |
|
---|
159 | return metadata_values;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Every file must be skimmed when a collection is opened, for two reasons:
|
---|
167 | * - To build a mapping from source file to its corresponding doc.xml file
|
---|
168 | * - To get a complete list of all extracted metadata elements
|
---|
169 | */
|
---|
170 | public void skimFile()
|
---|
171 | {
|
---|
172 | MetadataSet extracted_metadata_set = MetadataSetManager.getMetadataSet(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE);
|
---|
173 |
|
---|
174 | // Skim the file as quickly as possible (don't parse as XML), looking at the Metadata elements
|
---|
175 | DebugStream.println("Skimming " + this + "...");
|
---|
176 | try {
|
---|
177 | BufferedReader buffered_reader = new BufferedReader(new FileReader(this));
|
---|
178 | int description_element_start = -1;
|
---|
179 |
|
---|
180 | String line = null;
|
---|
181 | for (int line_num = 0; (line = buffered_reader.readLine()) != null; line_num++) {
|
---|
182 | // This line contains the start of a "MetadataWrap" element
|
---|
183 | // (mets:xmlData in METS parlance, Description in GreenstoneArchive format)
|
---|
184 | if (line.indexOf("<"+MetadataWrap+">") != -1) {
|
---|
185 | if (description_element_start != -1) {
|
---|
186 | System.err.println("Parse error: previous " + MetadataWrap + " element unfinished!");
|
---|
187 | }
|
---|
188 | description_element_start = line_num;
|
---|
189 | continue;
|
---|
190 | }
|
---|
191 |
|
---|
192 | // This line contains the end of a "MetadataWrap" element
|
---|
193 | if (line.indexOf("</"+MetadataWrap+">") != -1) {
|
---|
194 | if (description_element_start == -1) {
|
---|
195 | System.err.println("Parse error: "+MetadataWrap+" element unstarted!");
|
---|
196 | }
|
---|
197 | description_element_start = -1;
|
---|
198 | continue;
|
---|
199 | }
|
---|
200 |
|
---|
201 | // If we're not in a"MetadataWrap" element there shouldn't be any Metadata elements
|
---|
202 | if (description_element_start == -1) {
|
---|
203 | continue;
|
---|
204 | }
|
---|
205 |
|
---|
206 | // This line doesn't contain a Metadata element, so we're not interested
|
---|
207 | if (line.indexOf("<"+MetadataItem+" ") == -1) {
|
---|
208 | DebugStream.println("Warning: "+MetadataWrap+" element line doesn't contain Metadata element.");
|
---|
209 | continue;
|
---|
210 | }
|
---|
211 |
|
---|
212 | // Extract the metadata element name
|
---|
213 | int name_index = line.indexOf(" name=\"") + " name=\"".length();
|
---|
214 | String metadata_element_name_full = line.substring(name_index, line.indexOf("\"", name_index));
|
---|
215 |
|
---|
216 | // If the metadata has a namespace it isn't extracted metadata, so we're not interested
|
---|
217 | String metadata_set_namespace = MetadataTools.getMetadataSetNamespace(metadata_element_name_full);
|
---|
218 | if (!metadata_set_namespace.equals("")) {
|
---|
219 | continue;
|
---|
220 | }
|
---|
221 |
|
---|
222 | // Extracted metadata!
|
---|
223 | String metadata_element_name = metadata_element_name_full;
|
---|
224 |
|
---|
225 | // Note which file this is for
|
---|
226 | if (metadata_element_name.equals("gsdlsourcefilename")) {
|
---|
227 | // Extract the gsdlsourcefilename element value
|
---|
228 | int value_index = line.indexOf(">", name_index) + ">".length();
|
---|
229 | String gsdlsourcefilename_value = line.substring(value_index, line.indexOf("<", value_index));
|
---|
230 |
|
---|
231 | // We're only interested in the path relative to the import folder
|
---|
232 | int import_index = gsdlsourcefilename_value.indexOf("import");
|
---|
233 | if (import_index != -1) {
|
---|
234 | gsdlsourcefilename_value = gsdlsourcefilename_value.substring(import_index + "import".length());
|
---|
235 |
|
---|
236 | boolean is_unix_path = gsdlsourcefilename_value.startsWith("/");
|
---|
237 | gsdlsourcefilename_value = gsdlsourcefilename_value.substring(1);
|
---|
238 |
|
---|
239 | // URL decode gsdlsourcefilename. Need to set the decoder to use the default system encoding
|
---|
240 | // This is stored in the System's file.encoding property.
|
---|
241 | gsdlsourcefilename_value = URLDecoder.decode(gsdlsourcefilename_value, System.getProperty("file.encoding"));
|
---|
242 |
|
---|
243 | // Make sure the path matches the OS that is running
|
---|
244 | if (is_unix_path && Utility.isWindows()) {
|
---|
245 | // Convert path from Unix to Windows
|
---|
246 | gsdlsourcefilename_value = gsdlsourcefilename_value.replaceAll("\\/", "\\\\");
|
---|
247 | }
|
---|
248 | else if (!is_unix_path && !Utility.isWindows()) {
|
---|
249 | // Convert path from Windows to Unix
|
---|
250 | gsdlsourcefilename_value = gsdlsourcefilename_value.replaceAll("\\\\", "/");
|
---|
251 | }
|
---|
252 |
|
---|
253 | // Remember this for quick access later
|
---|
254 | if (source_file_name_to_description_elements_mapping.get(gsdlsourcefilename_value) == null) {
|
---|
255 | source_file_name_to_description_elements_mapping.put(gsdlsourcefilename_value, new ArrayList());
|
---|
256 | }
|
---|
257 |
|
---|
258 | ((ArrayList) source_file_name_to_description_elements_mapping.get(gsdlsourcefilename_value)).add(new Integer(description_element_start));
|
---|
259 | }
|
---|
260 |
|
---|
261 | // Warn about an odd gsdlsourcefilename, except if it is the Greenstone "tmp" directory
|
---|
262 | // This is true when the source files come from a zip file processed by ZIPPlug, for example
|
---|
263 | else if (gsdlsourcefilename_value.indexOf("tmp") == -1) {
|
---|
264 | // We don't really know what is going on...
|
---|
265 | System.err.println("Warning: Could not understand gsdlsourcefilename " + gsdlsourcefilename_value);
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | // Ignore metadata starting with gsdl (used to be lowercase metadata and /metadata)
|
---|
270 | if (metadata_element_name.startsWith("gsdl")) {
|
---|
271 | continue;
|
---|
272 | }
|
---|
273 |
|
---|
274 | MetadataElement metadata_element = extracted_metadata_set.getMetadataElementWithName(metadata_element_name);
|
---|
275 | if (metadata_element == null) {
|
---|
276 | // This element isn't defined in ex.mds, so create it for this session
|
---|
277 | DebugStream.println("Extracted metadata element not defined: " + metadata_element_name);
|
---|
278 | extracted_metadata_set.addMetadataElementForThisSession(metadata_element_name);
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | buffered_reader.close();
|
---|
283 | }
|
---|
284 | catch (FileNotFoundException exception) {
|
---|
285 | DebugStream.printStackTrace(exception);
|
---|
286 | }
|
---|
287 | catch (IOException exception) {
|
---|
288 | DebugStream.printStackTrace(exception);
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 |
|
---|
293 | /*
|
---|
294 | public ArrayList getMetadataExtractedFromFile(File file)
|
---|
295 | {
|
---|
296 | // Build up a list of metadata extracted from this file
|
---|
297 | ArrayList metadata_values = new ArrayList();
|
---|
298 |
|
---|
299 | String file_relative_path = file.getAbsolutePath();
|
---|
300 | int import_index = file_relative_path.indexOf("import");
|
---|
301 | if (import_index != -1) {
|
---|
302 | file_relative_path = file_relative_path.substring(import_index + "import".length() + 1);
|
---|
303 | }
|
---|
304 |
|
---|
305 | // Check whether this doc.xml file contains extracted metadata for the specified file
|
---|
306 | ArrayList description_elements_list = (ArrayList) source_file_name_to_description_elements_mapping.get(file_relative_path);
|
---|
307 | if (description_elements_list == null) {
|
---|
308 | // ...it doesn't
|
---|
309 | return metadata_values;
|
---|
310 | }
|
---|
311 |
|
---|
312 | MetadataSet extracted_metadata_set = MetadataSetManager.getMetadataSet(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE);
|
---|
313 |
|
---|
314 | // Parse the doc.xml file
|
---|
315 | DebugStream.println("Applicable doc.xml file: " + this);
|
---|
316 | try {
|
---|
317 | BufferedReader buffered_reader = new BufferedReader(new FileReader(this));
|
---|
318 |
|
---|
319 | int description_element_num = 0;
|
---|
320 | int next_description_element_start = ((Integer) description_elements_list.get(description_element_num)).intValue();
|
---|
321 | boolean in_relevant_description_element = false;
|
---|
322 |
|
---|
323 | String line = null;
|
---|
324 | for (int line_num = 0; (line = buffered_reader.readLine()) != null; line_num++) {
|
---|
325 | // Check if this line contains the start of a relevant Description element
|
---|
326 | if (line_num == next_description_element_start) {
|
---|
327 | in_relevant_description_element = true;
|
---|
328 | continue;
|
---|
329 | }
|
---|
330 |
|
---|
331 | // If we're not in a relevant Description element we don't care about anything
|
---|
332 | if (in_relevant_description_element == false) {
|
---|
333 | continue;
|
---|
334 | }
|
---|
335 |
|
---|
336 | // Check if this line contains the end of the relevant Description element
|
---|
337 | if (line.indexOf("</Description>") != -1) {
|
---|
338 | description_element_num++;
|
---|
339 | if (description_element_num == description_elements_list.size()) {
|
---|
340 | break;
|
---|
341 | }
|
---|
342 |
|
---|
343 | next_description_element_start = ((Integer) description_elements_list.get(description_element_num)).intValue();
|
---|
344 | in_relevant_description_element = false;
|
---|
345 | continue;
|
---|
346 | }
|
---|
347 |
|
---|
348 | // If this line doesn't contain a complete Metadata element, we're not interested
|
---|
349 | if (line.indexOf("<Metadata ") == -1 || line.indexOf("</Metadata>") == -1) {
|
---|
350 | continue;
|
---|
351 | }
|
---|
352 |
|
---|
353 | // Extract the metadata element name
|
---|
354 | int name_index = line.indexOf(" name=\"") + " name=\"".length();
|
---|
355 | String metadata_element_name_full = line.substring(name_index, line.indexOf("\"", name_index));
|
---|
356 |
|
---|
357 | // If the metadata has a namespace it isn't extracted metadata, so we're not interested
|
---|
358 | String metadata_set_namespace = MetadataTools.getMetadataSetNamespace(metadata_element_name_full);
|
---|
359 | if (!metadata_set_namespace.equals("")) {
|
---|
360 | continue;
|
---|
361 | }
|
---|
362 |
|
---|
363 | // Extracted metadata!
|
---|
364 | String metadata_element_name = metadata_element_name_full;
|
---|
365 |
|
---|
366 | // We completely ignore bibliographic data
|
---|
367 | if (metadata_element_name.equals("SourceSegment")) {
|
---|
368 | buffered_reader.close();
|
---|
369 | return new ArrayList();
|
---|
370 | }
|
---|
371 |
|
---|
372 | // Ignore metadata starting with gsdl (used to be lowercase metadata and /metadata)
|
---|
373 | if (metadata_element_name.startsWith("gsdl")) {
|
---|
374 | continue;
|
---|
375 | }
|
---|
376 |
|
---|
377 | MetadataElement metadata_element = extracted_metadata_set.getMetadataElementWithName(metadata_element_name);
|
---|
378 |
|
---|
379 | // Value trees are not stored for extracted metadata, so create a new value tree node now
|
---|
380 | int value_index = line.indexOf(">", name_index) + ">".length();
|
---|
381 | String metadata_element_value = line.substring(value_index, line.lastIndexOf("</Metadata>"));
|
---|
382 |
|
---|
383 | metadata_element.addMetadataValue(metadata_element_value);
|
---|
384 | MetadataValueTreeNode metadata_value_tree_node = metadata_element.getMetadataValueTreeNode(metadata_element_value);
|
---|
385 |
|
---|
386 | // Add the new metadata value to the list
|
---|
387 | MetadataValue metadata_value = new MetadataValue(metadata_element, metadata_value_tree_node);
|
---|
388 | metadata_values.add(metadata_value);
|
---|
389 | }
|
---|
390 |
|
---|
391 | buffered_reader.close();
|
---|
392 | }
|
---|
393 | catch (FileNotFoundException exception) {
|
---|
394 | DebugStream.printStackTrace(exception);
|
---|
395 | }
|
---|
396 | catch (IOException exception) {
|
---|
397 | DebugStream.printStackTrace(exception);
|
---|
398 | }
|
---|
399 |
|
---|
400 | return metadata_values;
|
---|
401 | }
|
---|
402 |
|
---|
403 | */
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Every doc.xml file must be skimmed when a collection is opened, for two reasons:
|
---|
407 | * - To build a mapping from source file to its corresponding doc.xml file
|
---|
408 | * - To get a complete list of all extracted metadata elements
|
---|
409 | */
|
---|
410 | /*
|
---|
411 | public void skimFile()
|
---|
412 | {
|
---|
413 | MetadataSet extracted_metadata_set = MetadataSetManager.getMetadataSet(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE);
|
---|
414 |
|
---|
415 | // Skim the doc.xml file as quickly as possible (don't parse as XML), looking at the Metadata elements
|
---|
416 | DebugStream.println("Skimming " + this + "...");
|
---|
417 | try {
|
---|
418 | BufferedReader buffered_reader = new BufferedReader(new FileReader(this));
|
---|
419 | int description_element_start = -1;
|
---|
420 |
|
---|
421 | String line = null;
|
---|
422 | for (int line_num = 0; (line = buffered_reader.readLine()) != null; line_num++) {
|
---|
423 | // This line contains the start of a Description element
|
---|
424 | if (line.indexOf("<Description>") != -1) {
|
---|
425 | if (description_element_start != -1) {
|
---|
426 | System.err.println("Parse error: previous Description element unfinished!");
|
---|
427 | }
|
---|
428 | description_element_start = line_num;
|
---|
429 | continue;
|
---|
430 | }
|
---|
431 |
|
---|
432 | // This line contains the end of a Description element
|
---|
433 | if (line.indexOf("</Description>") != -1) {
|
---|
434 | if (description_element_start == -1) {
|
---|
435 | System.err.println("Parse error: Description element unstarted!");
|
---|
436 | }
|
---|
437 | description_element_start = -1;
|
---|
438 | continue;
|
---|
439 | }
|
---|
440 |
|
---|
441 | // If we're not in a Description element there shouldn't be any Metadata elements
|
---|
442 | if (description_element_start == -1) {
|
---|
443 | continue;
|
---|
444 | }
|
---|
445 |
|
---|
446 | // This line doesn't contain a Metadata element, so we're not interested
|
---|
447 | if (line.indexOf("<Metadata ") == -1) {
|
---|
448 | DebugStream.println("Warning: Description element line doesn't contain Metadata element.");
|
---|
449 | continue;
|
---|
450 | }
|
---|
451 |
|
---|
452 | // Extract the metadata element name
|
---|
453 | int name_index = line.indexOf(" name=\"") + " name=\"".length();
|
---|
454 | String metadata_element_name_full = line.substring(name_index, line.indexOf("\"", name_index));
|
---|
455 |
|
---|
456 | // If the metadata has a namespace it isn't extracted metadata, so we're not interested
|
---|
457 | String metadata_set_namespace = MetadataTools.getMetadataSetNamespace(metadata_element_name_full);
|
---|
458 | if (!metadata_set_namespace.equals("")) {
|
---|
459 | continue;
|
---|
460 | }
|
---|
461 |
|
---|
462 | // Extracted metadata!
|
---|
463 | String metadata_element_name = metadata_element_name_full;
|
---|
464 |
|
---|
465 | // Note which file this doc.xml is for
|
---|
466 | if (metadata_element_name.equals("gsdlsourcefilename")) {
|
---|
467 | // Extract the gsdlsourcefilename element value
|
---|
468 | int value_index = line.indexOf(">", name_index) + ">".length();
|
---|
469 | String gsdlsourcefilename_value = line.substring(value_index, line.indexOf("<", value_index));
|
---|
470 |
|
---|
471 | // We're only interested in the path relative to the import folder
|
---|
472 | int import_index = gsdlsourcefilename_value.indexOf("import");
|
---|
473 | if (import_index != -1) {
|
---|
474 | gsdlsourcefilename_value = gsdlsourcefilename_value.substring(import_index + "import".length());
|
---|
475 |
|
---|
476 | boolean is_unix_path = gsdlsourcefilename_value.startsWith("/");
|
---|
477 | gsdlsourcefilename_value = gsdlsourcefilename_value.substring(1);
|
---|
478 |
|
---|
479 | // URL decode gsdlsourcefilename. Need to set the decoder to use the default system encoding
|
---|
480 | // This is stored in the System's file.encoding property.
|
---|
481 | gsdlsourcefilename_value = URLDecoder.decode(gsdlsourcefilename_value, System.getProperty("file.encoding"));
|
---|
482 |
|
---|
483 | // Make sure the path matches the OS that is running
|
---|
484 | if (is_unix_path && Utility.isWindows()) {
|
---|
485 | // Convert path from Unix to Windows
|
---|
486 | gsdlsourcefilename_value = gsdlsourcefilename_value.replaceAll("\\/", "\\\\");
|
---|
487 | }
|
---|
488 | else if (!is_unix_path && !Utility.isWindows()) {
|
---|
489 | // Convert path from Windows to Unix
|
---|
490 | gsdlsourcefilename_value = gsdlsourcefilename_value.replaceAll("\\\\", "/");
|
---|
491 | }
|
---|
492 |
|
---|
493 | // Remember this for quick access later
|
---|
494 | if (source_file_name_to_description_elements_mapping.get(gsdlsourcefilename_value) == null) {
|
---|
495 | source_file_name_to_description_elements_mapping.put(gsdlsourcefilename_value, new ArrayList());
|
---|
496 | }
|
---|
497 |
|
---|
498 | ((ArrayList) source_file_name_to_description_elements_mapping.get(gsdlsourcefilename_value)).add(new Integer(description_element_start));
|
---|
499 | }
|
---|
500 |
|
---|
501 | // Warn about an odd gsdlsourcefilename, except if it is the Greenstone "tmp" directory
|
---|
502 | // This is true when the source files come from a zip file processed by ZIPPlug, for example
|
---|
503 | else if (gsdlsourcefilename_value.indexOf("tmp") == -1) {
|
---|
504 | // We don't really know what is going on...
|
---|
505 | System.err.println("Warning: Could not understand gsdlsourcefilename " + gsdlsourcefilename_value);
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | // Ignore metadata starting with gsdl (used to be lowercase metadata and /metadata)
|
---|
510 | if (metadata_element_name.startsWith("gsdl")) {
|
---|
511 | continue;
|
---|
512 | }
|
---|
513 |
|
---|
514 | MetadataElement metadata_element = extracted_metadata_set.getMetadataElementWithName(metadata_element_name);
|
---|
515 | if (metadata_element == null) {
|
---|
516 | // This element isn't defined in ex.mds, so create it for this session
|
---|
517 | DebugStream.println("Extracted metadata element not defined: " + metadata_element_name);
|
---|
518 | extracted_metadata_set.addMetadataElementForThisSession(metadata_element_name);
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | buffered_reader.close();
|
---|
523 | }
|
---|
524 | catch (FileNotFoundException exception) {
|
---|
525 | DebugStream.printStackTrace(exception);
|
---|
526 | }
|
---|
527 | catch (IOException exception) {
|
---|
528 | DebugStream.printStackTrace(exception);
|
---|
529 | }
|
---|
530 | }
|
---|
531 | */
|
---|
532 |
|
---|
533 | }
|
---|