Index: /trunk/gli/src/org/greenstone/gatherer/gui/MetaEditPane.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gui/MetaEditPane.java	(revision 5659)
+++ /trunk/gli/src/org/greenstone/gatherer/gui/MetaEditPane.java	(revision 5660)
@@ -184,11 +184,19 @@
 	Object esrc = event.getSource();
 	if (esrc == add) {
-	    (new AppendMetadataTask()).start();
+	   ElementWrapper element = tree.getSelectedMetadataElement();
+	   String value = tree.getSelectedValue();
+	   (new AppendMetadataTask(element, value)).start();
+	   value = null;
+	   element = null;
 	}
 	else if (esrc == update) {
-	    (new UpdateMetadataTask()).start();
+	   ElementWrapper element = tree.getSelectedMetadataElement();
+	   String value = tree.getSelectedValue();
+	   (new UpdateMetadataTask(element, value)).start();
+	   value = null;
+	   element = null;
 	}
 	else if (esrc == remove) {
-	    (new RemoveMetadataTask()).start();
+	   (new RemoveMetadataTask()).start();
 	}
 	else if (esrc == expand) {
@@ -205,17 +213,24 @@
 	extends Thread {
 
-	private AppendMetadataTask() { }
-
-	public void run() {
+       private ElementWrapper element = null;
+       private String value = null;
+       
+       private AppendMetadataTask(ElementWrapper element, String value) {
+	  this.element = element;
+	  // Transform the raw text to be GREENSTONE and DOM compatible - as that will be its next destination immediately after being added to the value model
+	  this.value = Codec.transform(value, Codec.REMOVE_SQUARE_BRACKET);
+	  this.value = Codec.transform(this.value, Codec.TEXT_TO_DOM);
+       }
+
+       public void run() {
+	  System.err.println("Add metadata - '" + value + "'");
 	    // Check the new metadata is valid
-	    ElementWrapper element = tree.getSelectedMetadataElement();
-	    String value = tree.getSelectedValue();
-	    Gatherer.println("Adding value:");
 	    if(records != null && element != null && value != null) {
-		// Check the records, and if they are folders then display the warning.
-		if(!records[0].isLeaf()) {
+	       // Check the records, and if they are folders then display the warning.
+	       Metadata added_metadata = null;
+	       if(!records[0].isLeaf()) {
 		    WarningDialog dialog = new WarningDialog("warning.DirectoryLevelMetadata", true);
 		    if(dialog.display() == JOptionPane.OK_OPTION) {
-			Gatherer.c_man.getCollection().msm.addMetadata(System.currentTimeMillis(), records, element, value);
+			added_metadata = Gatherer.c_man.getCollection().msm.addMetadata(System.currentTimeMillis(), records, element, value);
 		    }
 		    dialog.dispose();
@@ -223,8 +238,6 @@
 		}
 		else {
-		    Gatherer.c_man.getCollection().msm.addMetadata(System.currentTimeMillis(), records, element, value);
+		    added_metadata = Gatherer.c_man.getCollection().msm.addMetadata(System.currentTimeMillis(), records, element, value);
 		}
-		GValueNode value_node = ((GValueModel) tree.getModel()).addValue(value);
-		Metadata added_metadata = new Metadata(element, value_node);
 		model.selectMetadataWhenBuildingComplete(added_metadata);
 	    }
@@ -235,11 +248,17 @@
 	extends Thread {
 
-	private UpdateMetadataTask() { }
+       private ElementWrapper element;
+       private String value;
+       
+	private UpdateMetadataTask(ElementWrapper element, String value) {
+	  this.element = element;
+	  // Transform the raw text to be DOM compatible - as that will be its next destination immediately after being added to the value model
+	  this.value = Codec.transform(value, Codec.REMOVE_SQUARE_BRACKET);
+	  this.value = Codec.transform(this.value, Codec.TEXT_TO_DOM);
+	}
 
 	public void run() {
 	    // You can only update if there is a selected_metadata and
 	    // you have valid values in all fields.
-	    ElementWrapper element = tree.getSelectedMetadataElement();
-	    String value = tree.getSelectedValue();
 	    Gatherer.println("Replacing value:");
 	    if(selected_metadata != null && records != null && element != null && value != null) {
@@ -252,7 +271,7 @@
     private class RemoveMetadataTask
 	extends Thread {
-
-	private RemoveMetadataTask() { }
-
+       
+       private RemoveMetadataTask() {}
+       
 	public void run() {
 	    Gatherer.println("Removing value:");
@@ -1185,5 +1204,5 @@
 		    for (int i = 0; i < tree_node.getChildCount(); i++) {
 			GValueNode child_node = (GValueNode) tree_node.getChildAt(i);
-			if (child_node.toString().equals(token)) {
+			if (child_node.toString(GValueNode.DOM).equals(token)) {
 			    // The matching node has been found, so move onto the next token
 			    tree_node = child_node;
@@ -1197,5 +1216,5 @@
 		    for (int i = 0; i < tree_node.getChildCount(); i++) {
 			GValueNode child_node = (GValueNode) tree_node.getChildAt(i);
-			if (child_node.toString().startsWith(token)) {
+			if (child_node.toString(GValueNode.DOM).startsWith(token)) {
 			    // The closest node has been found, so return its path
 			    return new TreePath(child_node.getPath());
@@ -1278,5 +1297,5 @@
 	    private void validate()
 	    {
-		String value_text = getSelectedValue();
+		String value_text = Codec.transform(getSelectedValue(), Codec.TEXT_TO_DOM);
 		///ystem.err.println("\n(Validate) Value text: " + value_text);
 
@@ -1285,4 +1304,6 @@
 		    TreePath closest_path = getClosestPath(value_text);
 
+		    ///ystem.err.println("The closest path is: " + closest_path);
+		    
 		    // Select the new path in the tree
 		    // The tree selection event this causes must be ignored, since it alters value
