Index: /gli/trunk/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
===================================================================
--- /gli/trunk/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java	(revision 18638)
+++ /gli/trunk/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java	(revision 18639)
@@ -446,38 +446,11 @@
 	      text.append (option_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
 	      String value_str = XMLTools.getValue (option_element);
+	      value_str = modifyMetadataArgumentValue(value_str);
+	      if (value_str.length () > 0) {
+		text.append (StaticStrings.SPACE_CHARACTER);
+		text.append(value_str);
+	      }
               
-                // Convert metadata element names to internal names, and remove extracted metadata namespaces
-                if (value_str.length () > 0) {
-                    StringTokenizer string_tokenizer = new StringTokenizer (value_str, ",");
-                    StringBuffer value_buffer = new StringBuffer ();
-                    while (string_tokenizer.hasMoreElements ()) {
-                        String raw_token = (String) string_tokenizer.nextElement ();
-                        String token = raw_token.trim ();
-                        MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName (token);
-                        if (metadata_element != null) {
-                            token = metadata_element.getFullName ();
-                        }
-                        
-                        if (token.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
-                            token = token.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
-                        }
-                        value_buffer.append (token);
-                        if (string_tokenizer.hasMoreElements ()) {
-                            value_buffer.append (",");
-                        }
-                    }
-                    value_str = value_buffer.toString ();
-                }
-                
-                text.append (StaticStrings.SPACE_CHARACTER);
-                if (value_str.indexOf (StaticStrings.SPACE_CHARACTER) == -1) {
-                    text.append (value_str);
-                }
-                else {
-                    text.append (StaticStrings.SPEECH_CHARACTER);
-                    text.append (value_str);
-                    text.append (StaticStrings.SPEECH_CHARACTER);
-                }
-                value_str = null;
+	      value_str = null;
             }
             option_element = null;
@@ -1548,43 +1521,12 @@
 	      text.append (option_element.getAttribute (StaticStrings.NAME_ATTRIBUTE));
 	      String value_str = XMLTools.getValue (option_element);
-
 	      
-	      // Convert metadata element names to internal names, and remove extracted metadata namespaces
+	      value_str = modifyMetadataArgumentValue(value_str);
+	      // are there any valid cases of "" args??
 	      if (value_str.length () > 0) {
-		StringTokenizer string_tokenizer = new StringTokenizer (value_str, ",");
-		StringBuffer value_buffer = new StringBuffer ();
-		while (string_tokenizer.hasMoreElements ()) {
-		  String raw_token = (String) string_tokenizer.nextElement ();
-		  String token = raw_token.trim ();
-		  MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName (token);
-		  if (metadata_element != null) {
-		    token = metadata_element.getFullName ();
-		  }
-                        
-		  if (token.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
-		    token = token.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
-		  }
-		  value_buffer.append (token);
-		  if (string_tokenizer.hasMoreElements ()) {
-		    value_buffer.append (",");
-		  }
-		}
-		value_str = value_buffer.toString ();
+		text.append (StaticStrings.SPACE_CHARACTER);
+		text.append(value_str);
 	      }
-
-	      // if(!show_extracted_namespace && value_str.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
-	      //            value_str = value_str.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
-	      //        }
-	      if(value_str.length () > 0) {
-		text.append (StaticStrings.SPACE_CHARACTER);
-		if(value_str.indexOf (StaticStrings.SPACE_CHARACTER) == -1) {
-		  text.append (value_str);
-		}
-		else {
-		  text.append (StaticStrings.SPEECH_CHARACTER);
-		  text.append (value_str);
-		  text.append (StaticStrings.SPEECH_CHARACTER);
-		}
-	      }
+	      
 	      value_str = null;
 	    }
@@ -1596,4 +1538,53 @@
 	return text.toString ();
     }
+
+    // Convert metadata element names to internal names, and remove extracted metadata namespaces
+  static private String modifyMetadataArgumentValue(String value_str) {
+    if (value_str.length () == 0) {
+      return value_str;
+    }
+    
+    // final true arg to return delims as tokens
+    StringTokenizer string_tokenizer = new StringTokenizer (value_str, ",", true);
+    StringBuffer value_buffer = new StringBuffer ();
+    while (string_tokenizer.hasMoreElements ()) {
+      String raw_token = (String) string_tokenizer.nextElement ();
+      String token = raw_token.trim ();
+      boolean modified_token = false;
+      // not a delimiter token
+      if (!raw_token.equals(",")) {
+	MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName (token);
+	if (metadata_element != null) {
+	  token = metadata_element.getFullName ();
+	  modified_token = true;
+	}
+	
+	if (token.startsWith (StaticStrings.EXTRACTED_NAMESPACE)) {
+	  token = token.substring (StaticStrings.EXTRACTED_NAMESPACE.length ());
+	  modified_token = true;
+	}
+      }
+      if (modified_token) {
+	value_buffer.append (token);
+      } else {
+	// we may have had whitespace etc that was part of the string
+	value_buffer.append (raw_token);
+      }
+    }
+    
+    
+    if(value_buffer.length () == 0) {
+      return "";
+    }
+    if(value_str.indexOf (StaticStrings.SPACE_CHARACTER) == -1) {
+      return value_buffer.toString();
+    }
+    
+    // it must contain a space, so we surround the value with quotes
+    value_buffer.insert(0, StaticStrings.SPEECH_CHARACTER);
+    value_buffer.append(StaticStrings.SPEECH_CHARACTER);
+    return value_buffer.toString();
+
+  }
     
     static private String searchtypeToString (Element command_element) {
