Index: /trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java	(revision 8013)
+++ /trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java	(revision 8014)
@@ -13,91 +13,133 @@
 public class XMLTools
 {
-   static public ArrayList getChildElementsByTagName(Element parent_element, String element_name)
-   {
-      ArrayList child_elements = new ArrayList();
+    static public ArrayList getChildElementsByTagName(Element parent_element, String element_name)
+    {
+	ArrayList child_elements = new ArrayList();
 
-      NodeList children_nodelist = parent_element.getChildNodes();
-      for (int i = 0; i < children_nodelist.getLength(); i++) {
-	 Node child_node = children_nodelist.item(i);
-	 if (child_node.getNodeType() == Node.ELEMENT_NODE && child_node.getNodeName().equals(element_name)) {
-	    child_elements.add(child_node);
-	 }
-      }
+	NodeList children_nodelist = parent_element.getChildNodes();
+	for (int i = 0; i < children_nodelist.getLength(); i++) {
+	    Node child_node = children_nodelist.item(i);
+	    if (child_node.getNodeType() == Node.ELEMENT_NODE && child_node.getNodeName().equals(element_name)) {
+		child_elements.add(child_node);
+	    }
+	}
 
-      return child_elements;
-   }
+	return child_elements;
+    }
 
 
-   static public String getElementTextValue(Element element)
-   {
-      // Find the first text node child
-      NodeList children_nodelist = element.getChildNodes();
-      for (int i = 0; i < children_nodelist.getLength(); i++) {
-	 Node child_node = children_nodelist.item(i);
-	 if (child_node.getNodeType() == Node.TEXT_NODE) {
-	    return child_node.getNodeValue();
-	 }
-      }
+    static public String getElementTextValue(Element element)
+    {
+	// Find the first text node child
+	NodeList children_nodelist = element.getChildNodes();
+	for (int i = 0; i < children_nodelist.getLength(); i++) {
+	    Node child_node = children_nodelist.item(i);
+	    if (child_node.getNodeType() == Node.TEXT_NODE) {
+		return child_node.getNodeValue();
+	    }
+	}
 
-      // None found
-      return null;
-   }
+	// None found
+	return null;
+    }
 
 
-   /** Parse an XML document from a given file */
-   static public Document parseXMLFile(File xml_file)
-   {
-      Document document = null;
-
-      try {
-	 FileInputStream fis   = new FileInputStream(xml_file);
-	 InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
-	 Reader r              = new BufferedReader(isr);
-	 InputSource isc       = new InputSource(r);
-	 DOMParser parser      = new DOMParser();
-	 parser.setFeature("http://xml.org/sax/features/validation", false);
-	 parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
-	 // May or may not be ignored, the documentation for Xerces is contradictory. If it works then parsing -should- be faster.
-	 parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
-	 parser.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace", false);
-	 parser.parse(isc);
-	 document = parser.getDocument();
-	 isr.close();
-	 fis.close();
-      }
-      catch (Exception exception) {
-	 exception.printStackTrace();
-      }
-
-      return document;
-   }
+    /** Method to retrieve the value of a given node.
+     * @param element The <strong>Element</strong> whose value we wish to find.
+     * Soon to be deprecated!
+     */
+    static final public String getValue(Node element) {
+	// If we've been given a subject node first retrieve its value node.
+	if(element.getNodeName().equals("Subject")) {
+	    element = getNodeFromNamed(element, "Value");
+	}
+	// If we've got a value node, then reconstruct the text. Remember that DOM will split text over 256 characters into several text nodes
+	if(element != null && element.hasChildNodes()) {
+	    StringBuffer text_buffer = new StringBuffer();
+	    NodeList text_nodes = element.getChildNodes();
+	    for(int i = 0; i < text_nodes.getLength(); i++) {
+		Node possible_text = text_nodes.item(i);
+		if(possible_text.getNodeName().equals(StaticStrings.TEXT_NODE)) {
+		    text_buffer.append(possible_text.getNodeValue());
+		}
+	    }
+	    return text_buffer.toString();
+	}
+	return "";
+    }
 
 
-   /** Write an XML document to a given file */
-   static public void writeXMLFile(File xml_file, Document document)
-   {
-      try {
-	 OutputStream os = new FileOutputStream(xml_file);
-	 // Create an output format for our document.
-	 OutputFormat f = new OutputFormat(document);
-	 f.setEncoding("UTF-8");
-	 f.setIndenting(true);
-	 f.setLineWidth(0); // Why isn't this working!
-	 f.setPreserveSpace(false);
-	 // Create the necessary writer stream for serialization.
-	 OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
-	 Writer w               = new BufferedWriter(osw);
-	 // Generate a new serializer from the above.
-	 XMLSerializer s        = new XMLSerializer(w, f);
-	 s.asDOMSerializer();
-	 // Finally serialize the document to file.
-	 s.serialize(document);
-	 // And close.
-	 os.close();
-      }
-      catch (Exception exception) {
-	 exception.printStackTrace();
-      }
-   }
+    /** Method to retrieve from the node given, a certain child node with the specified name.
+     * @param parent The <strong>Node</strong> whose children should be searched.
+     * @param name The required nodes name as a <strong>String</strong>.
+     * @return The requested <strong>Node</strong> if it is found, <i>null</i> otherwise.
+     * Soon to be deprecated!
+     */ 
+    static final public Node getNodeFromNamed(Node parent, String name) {
+	Node child = null;
+	for(Node i = parent.getFirstChild(); i != null && child == null; 
+	    i = i.getNextSibling()) {
+	    if(i.getNodeName().equals(name)) {
+		child = i;
+	    }
+	}
+	return child;
+    }
+
+
+    /** Parse an XML document from a given file */
+    static public Document parseXMLFile(File xml_file)
+    {
+	Document document = null;
+
+	try {
+	    FileInputStream fis   = new FileInputStream(xml_file);
+	    InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
+	    Reader r              = new BufferedReader(isr);
+	    InputSource isc       = new InputSource(r);
+	    DOMParser parser      = new DOMParser();
+	    parser.setFeature("http://xml.org/sax/features/validation", false);
+	    parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+	    // May or may not be ignored, the documentation for Xerces is contradictory. If it works then parsing -should- be faster.
+	    parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
+	    parser.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace", false);
+	    parser.parse(isc);
+	    document = parser.getDocument();
+	    isr.close();
+	    fis.close();
+	}
+	catch (Exception exception) {
+	    exception.printStackTrace();
+	}
+
+	return document;
+    }
+
+
+    /** Write an XML document to a given file */
+    static public void writeXMLFile(File xml_file, Document document)
+    {
+	try {
+	    OutputStream os = new FileOutputStream(xml_file);
+	    // Create an output format for our document.
+	    OutputFormat f = new OutputFormat(document);
+	    f.setEncoding("UTF-8");
+	    f.setIndenting(true);
+	    f.setLineWidth(0); // Why isn't this working!
+	    f.setPreserveSpace(false);
+	    // Create the necessary writer stream for serialization.
+	    OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
+	    Writer w               = new BufferedWriter(osw);
+	    // Generate a new serializer from the above.
+	    XMLSerializer s        = new XMLSerializer(w, f);
+	    s.asDOMSerializer();
+	    // Finally serialize the document to file.
+	    s.serialize(document);
+	    // And close.
+	    os.close();
+	}
+	catch (Exception exception) {
+	    exception.printStackTrace();
+	}
+    }
 }
-
