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 org.greenstone.gatherer.DebugStream;
|
---|
33 |
|
---|
34 |
|
---|
35 | /** This class is a static class that manages the doc.xml files */
|
---|
36 | public 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)
|
---|
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);
|
---|
75 | }
|
---|
76 | else if (child_file.getName().equals("doc.xml")) {
|
---|
77 | loadDocXMLFile(child_file);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | static private void loadDocXMLFile(File doc_xml_file_file)
|
---|
84 | {
|
---|
85 | DocXMLFile doc_xml_file = new DocXMLFile(doc_xml_file_file.getAbsolutePath());
|
---|
86 | try {
|
---|
87 | doc_xml_file.skimFile();
|
---|
88 | doc_xml_files.add(doc_xml_file);
|
---|
89 | }
|
---|
90 | catch (Exception exception) {
|
---|
91 | // We catch any exceptions here so errors in doc.xml files don't stop the collection from loading
|
---|
92 | System.err.println("Error: Could not skim doc.xml file " + doc_xml_file.getAbsolutePath());
|
---|
93 | DebugStream.printStackTrace(exception);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|