source: trunk/gli/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java@ 8248

Last change on this file since 8248 was 8164, checked in by mdewsnip, 20 years ago

Added headers at the top of each file.

  • 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.util.XMLTools;
33import org.w3c.dom.*;
34
35
36/** This class represents one profile.xml file */
37public class ProfileXMLFile
38 extends File
39{
40 public ProfileXMLFile(String profile_xml_file_path)
41 {
42 super(profile_xml_file_path);
43 }
44
45
46 public String getMetadataElementFor(String source_metadata_element_name_full)
47 {
48 // Parse the profile.xml file
49 Document document = XMLTools.parseXMLFile(this);
50 if (document == null) {
51 System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath());
52 return null;
53 }
54
55 // Read all the Action elements in the file
56 NodeList action_elements_nodelist = document.getElementsByTagName("Action");
57 for (int i = 0; i < action_elements_nodelist.getLength(); i++) {
58 Element current_action_element = (Element) action_elements_nodelist.item(i);
59
60 // Does this action map the desired element?
61 if (current_action_element.getAttribute("source").equals(source_metadata_element_name_full)) {
62 return current_action_element.getAttribute("target");
63 }
64 }
65
66 // No import mapping for this element
67 return null;
68 }
69
70
71 public HashMap getMetadataMapping()
72 {
73 HashMap metadata_import_mapping = new HashMap();
74
75 // Parse the profile.xml file
76 Document document = XMLTools.parseXMLFile(this);
77 if (document == null) {
78 System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath());
79 return null;
80 }
81
82 // Read all the Action elements in the file
83 NodeList action_elements_nodelist = document.getElementsByTagName("Action");
84 for (int i = 0; i < action_elements_nodelist.getLength(); i++) {
85 Element current_action_element = (Element) action_elements_nodelist.item(i);
86 String source_metadata_element_name_full = current_action_element.getAttribute("source");
87 String target_metadata_element_name_full = current_action_element.getAttribute("target");
88 metadata_import_mapping.put(source_metadata_element_name_full, target_metadata_element_name_full);
89 }
90
91 return metadata_import_mapping;
92 }
93
94
95 public void mapElement(String source_metadata_element_name_full, String target_metadata_element_name_full)
96 {
97 // Parse the profile.xml file
98 Document document = XMLTools.parseXMLFile(this);
99 if (document == null) {
100 System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath());
101 return;
102 }
103
104 // Create a new Action element to record this mapping
105 Element new_action_element = document.createElement("Action");
106 new_action_element.setAttribute("source", source_metadata_element_name_full);
107 new_action_element.setAttribute("target", target_metadata_element_name_full);
108 document.getDocumentElement().appendChild(new_action_element);
109
110 // Rewrite the profile.xml file
111 XMLTools.writeXMLFile(this, document);
112 }
113}
Note: See TracBrowser for help on using the repository browser.