source: gli/branches/glicolgroup/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java@ 19668

Last change on this file since 19668 was 19668, checked in by ak19, 15 years ago

Not working. Changes made for collectiongroup.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 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.Gatherer;
33import org.greenstone.gatherer.collection.CollectionManager;
34import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
35import org.greenstone.gatherer.util.XMLTools;
36import org.w3c.dom.*;
37
38
39/** This class represents one profile.xml file */
40public class ProfileXMLFile
41 extends File
42{
43 private HashMap metadata_mapping = null;
44
45
46 public ProfileXMLFile(String profile_xml_file_path)
47 {
48 super(profile_xml_file_path);
49 }
50
51
52 public String getMetadataElementFor(String metadata_element_name_full)
53 {
54 if (getMetadataMapping() == null) {
55 return null;
56 }
57
58 return (String) metadata_mapping.get(metadata_element_name_full);
59 }
60
61
62 public HashMap getMetadataMapping()
63 {
64 // If we have already loaded the metadata mapping, use it
65 if (metadata_mapping != null) {
66 return metadata_mapping;
67 }
68
69 // Build the metadata mapping from the profile.xml file
70 metadata_mapping = new HashMap();
71
72 // Parse the profile.xml file
73 Document document = XMLTools.parseXMLFile(this);
74 if (document == null) {
75 System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath());
76 return null;
77 }
78
79 // Read all the Action elements in the file
80 NodeList action_elements_nodelist = document.getElementsByTagName("Action");
81 for (int i = 0; i < action_elements_nodelist.getLength(); i++) {
82 Element current_action_element = (Element) action_elements_nodelist.item(i);
83 String source_metadata_element_name_full = current_action_element.getAttribute("source");
84 String target_metadata_element_name_full = current_action_element.getAttribute("target");
85 metadata_mapping.put(source_metadata_element_name_full, target_metadata_element_name_full);
86 }
87
88 return metadata_mapping;
89 }
90
91
92 public void mapElement(String source_metadata_element_name_full, String target_metadata_element_name_full)
93 {
94 // Parse the profile.xml file
95 Document document = XMLTools.parseXMLFile(this);
96 if (document == null) {
97 System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath());
98 return;
99 }
100
101 // Create a new Action element to record this mapping
102 Element new_action_element = document.createElement("Action");
103 new_action_element.setAttribute("source", source_metadata_element_name_full);
104 new_action_element.setAttribute("target", target_metadata_element_name_full);
105 document.getDocumentElement().appendChild(new_action_element);
106
107 // Rewrite the profile.xml file
108 XMLTools.writeXMLFile(this, document);
109
110 // This is inefficient but for simplicity we'll just upload the file every time it is changed
111 if (Gatherer.isGsdlRemote) {
112 Gatherer.remoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedGroupQualifiedCollectionName(true), this);
113 }
114
115 // Invalidate the metadata mapping
116 metadata_mapping = null;
117 }
118}
Note: See TracBrowser for help on using the repository browser.