- Timestamp:
- 2004-09-21T11:19:32+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java
r8127 r8128 3 3 4 4 import java.io.*; 5 import java.util.*;6 5 import org.greenstone.gatherer.util.XMLTools; 7 6 import org.w3c.dom.*; … … 12 11 extends File 13 12 { 14 private HashMap metadata_import_mapping = new HashMap();15 16 17 13 public ProfileXMLFile(String profile_xml_file_path) 18 14 { 19 15 super(profile_xml_file_path); 16 } 20 17 18 19 public String getMetadataElementFor(String source_metadata_element_name_full) 20 { 21 21 // Parse the profile.xml file 22 System.err.println("Loading profile.xml file " + profile_xml_file_path + "..."); 22 Document document = XMLTools.parseXMLFile(this); 23 if (document == null) { 24 System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath()); 25 return null; 26 } 27 28 // Read all the Action elements in the file 29 NodeList action_elements_nodelist = document.getElementsByTagName("Action"); 30 for (int i = 0; i < action_elements_nodelist.getLength(); i++) { 31 Element current_action_element = (Element) action_elements_nodelist.item(i); 32 33 // Does this action map the desired element? 34 if (current_action_element.getAttribute("source").equals(source_metadata_element_name_full)) { 35 return current_action_element.getAttribute("target"); 36 } 37 } 38 39 // No import mapping for this element 40 return null; 41 } 42 43 44 public void mapElement(String source_metadata_element_name_full, String target_metadata_element_name_full) 45 { 46 // Parse the profile.xml file 23 47 Document document = XMLTools.parseXMLFile(this); 24 48 if (document == null) { … … 26 50 return; 27 51 } 28 }29 52 53 // Create a new Action element to record this mapping 54 Element new_action_element = document.createElement("Action"); 55 new_action_element.setAttribute("source", source_metadata_element_name_full); 56 new_action_element.setAttribute("target", target_metadata_element_name_full); 57 document.getDocumentElement().appendChild(new_action_element); 30 58 31 public String getMetadataElementFor(String metadata_element_name_full) 32 { 33 return (String) metadata_import_mapping.get(metadata_element_name_full); 59 // Rewrite the profile.xml file 60 XMLTools.writeXMLFile(this, document); 34 61 } 35 62 }
Note:
See TracChangeset
for help on using the changeset viewer.