source: main/trunk/gli/src/org/greenstone/gatherer/metadata/DocXMLFileManager.java@ 29793

Last change on this file since 29793 was 17101, checked in by davidb, 16 years ago

Typcast added to assignment statement to keep Java 1.4 happy

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
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
27package org.greenstone.gatherer.metadata;
28
29
30import java.io.*;
31import java.util.*;
32import org.greenstone.gatherer.DebugStream;
33
34
35/** This class is a static class that manages the doc.xml files */
36public class DocXMLFileManager
37{
38 static private ArrayList doc_xml_files = new ArrayList();
39
40
41 static public void clearDocXMLFiles()
42 {
43 doc_xml_files.clear();
44 }
45
46
47 static public ArrayList getMetadataExtractedFromFile(File file)
48 {
49 // Build up a list of metadata values extracted from this file
50 ArrayList metadata_values = new ArrayList();
51
52 // Look at each loaded doc.xml file to see if any have extracted metadata for this file
53 for (int i = 0; i < doc_xml_files.size(); i++) {
54 DocXMLFile doc_xml_file = (DocXMLFile) doc_xml_files.get(i);
55 metadata_values.addAll(doc_xml_file.getMetadataExtractedFromFile(file));
56 }
57
58 return metadata_values;
59 }
60
61
62 static public void loadDocXMLFiles(File directory, String filename_match)
63 {
64 // Make sure the directory (archives) exists
65 if (directory.exists() == false) {
66 return;
67 }
68
69 // Look recursively at each subfile of the directory for doc.xml files
70 File[] directory_files = directory.listFiles();
71 for (int i = 0; i < directory_files.length; i++) {
72 File child_file = directory_files[i];
73 if (child_file.isDirectory()) {
74 loadDocXMLFiles(child_file,filename_match);
75 }
76 else if (child_file.getName().equals(filename_match)) {
77 // e.g. doc.xml (for regular Greenstone, docmets.xml for Fedora)
78
79 loadDocXMLFile(child_file,filename_match);
80 }
81 }
82 }
83
84
85 static private void loadDocXMLFile(File doc_xml_file_file,String filename_match)
86 {
87 String file = doc_xml_file_file.getAbsolutePath();
88
89 // Need to do typecasts in the following to keep Java 1.4 happy
90 DocXMLFile doc_xml_file
91 = (filename_match.equals("docmets.xml"))
92 ? (DocXMLFile) new DocMetsXMLFile(file)
93 : (DocXMLFile) new DocGAFile(file);
94
95 try {
96 doc_xml_file.skimFile();
97 doc_xml_files.add(doc_xml_file);
98 }
99 catch (Exception exception) {
100 // We catch any exceptions here so errors in doc.xml files don't stop the collection from loading
101 System.err.println("Error: Could not skim doc.xml file " + doc_xml_file.getAbsolutePath());
102 DebugStream.printStackTrace(exception);
103 }
104 }
105}
Note: See TracBrowser for help on using the repository browser.