Ignore:
Timestamp:
2004-09-21T11:19:32+12:00 (20 years ago)
Author:
mdewsnip
Message:

More work on opening legacy collections and dealing with non-namespaced metadata.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java

    r8127 r8128  
    33
    44import java.io.*;
    5 import java.util.*;
    65import org.greenstone.gatherer.util.XMLTools;
    76import org.w3c.dom.*;
     
    1211    extends File
    1312{
    14     private HashMap metadata_import_mapping = new HashMap();
    15 
    16 
    1713    public ProfileXMLFile(String profile_xml_file_path)
    1814    {
    1915    super(profile_xml_file_path);
     16    }
    2017
     18
     19    public String getMetadataElementFor(String source_metadata_element_name_full)
     20    {
    2121    // 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
    2347    Document document = XMLTools.parseXMLFile(this);
    2448    if (document == null) {
     
    2650        return;
    2751    }
    28     }
    2952
     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);
    3058
    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);
    3461    }
    3562}
Note: See TracChangeset for help on using the changeset viewer.