Index: /main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java	(revision 26570)
+++ /main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java	(revision 26571)
@@ -53,11 +53,12 @@
 	static final private String PLUGOUT_ELEMENT = "plugout";//used by building flax collections
 
-  // a list of all known top level elements
-  static final private String known_element_names_array[] = {StaticStrings.METADATALIST_STR, StaticStrings.DISPLAYITEMLIST_STR, StaticStrings.FORMAT_STR, StaticStrings.SEARCH_STR, StaticStrings.INFODB_STR, StaticStrings.BROWSE_STR, StaticStrings.IMPORT_STR,  StaticStrings.DISPLAY_STR, StaticStrings.REPLACELISTREF_STR, StaticStrings.REPLACELIST_STR, StaticStrings.SERVICE_RACK_LIST_ELEMENT};
-  static final private Set known_element_names = new HashSet(Arrays.asList(known_element_names_array));
+	// a list of all known top level elements
+	static final private String known_element_names_array[] = { StaticStrings.METADATALIST_STR, StaticStrings.DISPLAYITEMLIST_STR, StaticStrings.FORMAT_STR, StaticStrings.SEARCH_STR, StaticStrings.INFODB_STR, StaticStrings.BROWSE_STR, StaticStrings.IMPORT_STR, StaticStrings.DISPLAY_STR, StaticStrings.REPLACELISTREF_STR, StaticStrings.REPLACELIST_STR, StaticStrings.SERVICE_RACK_LIST_ELEMENT };
+	static final private Set known_element_names = new HashSet(Arrays.asList(known_element_names_array));
+
 	/**
 	 * *************************************************************************
-	 * ******************************* The code in this file is used
-	 * for greenstone 3 collection configuration, i.e., read ColletionConfig.xml
+	 * ******************************* The code in this file is used for
+	 * greenstone 3 collection configuration, i.e., read ColletionConfig.xml
 	 * into the internal DOM tree, and convert the internal DOM tree back to
 	 * CollectionConfig.xml.
@@ -175,36 +176,36 @@
 				// Handling 'index' element
 				index_element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, index_str.substring(0, index_str.indexOf(StaticStrings.COLON_CHARACTER)));
-			
+
 				index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1);
 			}
-				//Each index may have a list of comma-separated strings.
-				//split them into 'content' elements in the internal structure
-				StringTokenizer content_tokenizer = new StringTokenizer(index_str, StaticStrings.COMMA_CHARACTER);
-				//index_str = "";
-				while (content_tokenizer.hasMoreTokens())
-				{
-					// Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject.
-
-					Element content_element = to.createElement(StaticStrings.CONTENT_ELEMENT);
-					String content_str = content_tokenizer.nextToken();
-					// Since the contents of indexes have to be certain keywords, or metadata elements,
-					//if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
-					if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR)))
-					{
-							content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
-						
-					}
-
-					content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str);
-					index_element.appendChild(content_element);
-					content_element = null;
-				} // while ends
-
-				indexes_element.appendChild(index_element);
-
-				// Handling 'displayItem' elements and Constructing 'collectionmetadata' elements
-				// Use the fully qualified index names
-				ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display);
-				appendArrayList(toElement, collectionmetadata_list);
+			//Each index may have a list of comma-separated strings.
+			//split them into 'content' elements in the internal structure
+			StringTokenizer content_tokenizer = new StringTokenizer(index_str, StaticStrings.COMMA_CHARACTER);
+			//index_str = "";
+			while (content_tokenizer.hasMoreTokens())
+			{
+				// Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject.
+
+				Element content_element = to.createElement(StaticStrings.CONTENT_ELEMENT);
+				String content_str = content_tokenizer.nextToken();
+				// Since the contents of indexes have to be certain keywords, or metadata elements,
+				//if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
+				if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR)))
+				{
+					content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
+
+				}
+
+				content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str);
+				index_element.appendChild(content_element);
+				content_element = null;
+			} // while ends
+
+			indexes_element.appendChild(index_element);
+
+			// Handling 'displayItem' elements and Constructing 'collectionmetadata' elements
+			// Use the fully qualified index names
+			ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display);
+			appendArrayList(toElement, collectionmetadata_list);
 		} //for loop ends
 		appendProperly(toElement, indexes_element);
@@ -269,5 +270,5 @@
 				System.err.println("Something is wrong! the index should NOT be level:source tuplets style.");
 				index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1);
-				
+
 			}
 			//Each index may have a list of comma-separated strings.
@@ -281,7 +282,7 @@
 				String content_str = content_tokenizer.nextToken();
 				// Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace.
-				if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR)|| content_str.equals(StaticStrings.ALLFIELDS_STR)))
-				{
-						content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
+				if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR) || content_str.equals(StaticStrings.ALLFIELDS_STR)))
+				{
+					content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str;
 				}
 				content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str);
@@ -338,10 +339,12 @@
 
 	}
-  static private void doGlobalFormat(Document to, Element from)
-  {
-    // look for a top level format element
-    Element fe = (Element) XMLTools.getChildByTagName(from, StaticStrings.FORMAT_STR);
-    to.getDocumentElement().appendChild(doFormat(to, fe, StaticStrings.GLOBAL_STR));
-  }
+
+	static private void doGlobalFormat(Document to, Element from)
+	{
+		// look for a top level format element
+		Element fe = (Element) XMLTools.getChildByTagName(from, StaticStrings.FORMAT_STR);
+		to.getDocumentElement().appendChild(doFormat(to, fe, StaticStrings.GLOBAL_STR));
+	}
+
 	static private void doDisplayFormat(Document to, Element from)
 	{
@@ -640,5 +643,5 @@
 		{ // not an empty format statement
 			String gsf_text = XMLTools.xmlNodeToString(format);
-			
+
 			//We don't want the <format> elements in the string
 			int startFormatIndex = gsf_text.indexOf(StaticStrings.FORMAT_START_TAG) + StaticStrings.FORMAT_START_TAG.length();
@@ -1003,4 +1006,5 @@
 		XMLTools.duplicateElementList(to, toElement, replace_elements, true);
 	}
+
 	// 	int num_elems = replace_elements.getLength();
 	// 	if (num_elems < 1)
@@ -1022,17 +1026,21 @@
 		XMLTools.duplicateElementList(to, toElement, replace_elements, true);
 	}
-		// int num_elems = replace_elements.getLength();
-		// if (num_elems < 1)
-		// {
-		// 	return;
-		// }
-		// for (int i = 0; i < num_elems; i++)
-		// {
-		// 	Element to_element = XMLTools.duplicateElement(to, (Element) replace_elements.item(i), true);
-		// 	toElement.appendChild(to_element);
-		// }
-  //	}
-
-  /* replacelist currently not editable in GLI, just copy it in and back out again */
+
+	// int num_elems = replace_elements.getLength();
+	// if (num_elems < 1)
+	// {
+	// 	return;
+	// }
+	// for (int i = 0; i < num_elems; i++)
+	// {
+	// 	Element to_element = XMLTools.duplicateElement(to, (Element) replace_elements.item(i), true);
+	// 	toElement.appendChild(to_element);
+	// }
+	//	}
+
+	/*
+	 * replacelist currently not editable in GLI, just copy it in and back out
+	 * again
+	 */
 	static private void doReplaceList(Document to, Element from)
 	{
@@ -1062,5 +1070,5 @@
 		toElement.appendChild(to_element);
 	}
- 
+
 	/**
 	 * serviceRackList is currently not editable in GLI - just copy it in from
@@ -1198,31 +1206,35 @@
 		// as displayItems in the collectionConfig.xml than they do in memory
 		Map attributeMap = new HashMap(4);
-		attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR,StaticStrings.DESCRIPTION_STR);
-		attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR,StaticStrings.NAME_STR);
-		attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR,StaticStrings.SMALLICON_STR);
-		attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR,StaticStrings.ICON_STR);
+		attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR, StaticStrings.DESCRIPTION_STR);
+		attributeMap.put(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR, StaticStrings.NAME_STR);
+		attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR, StaticStrings.SMALLICON_STR);
+		attributeMap.put(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR, StaticStrings.ICON_STR);
 
 		NodeList e_list = from.getDocumentElement().getElementsByTagName(StaticStrings.COLLECTIONMETADATA_ELEMENT);
 		// if such elements don't exist, don't bother
-		if (e_list != null) { 
-		    
-		    for (int j = 0; j < e_list.getLength(); j++) {
-			Element e = (Element) e_list.item(j);
-			if (e.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) {
-			    continue;
-			}
-			String text = XMLTools.getNodeText(e);
-			String lang = e.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE);
-			String name_value = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-			
-			String name_mapping = (String)attributeMap.get(name_value);
-			if(name_mapping != null) {
-			    name_value = name_mapping;
-			}
-
-			Element displayItem = constructElement(StaticStrings.DISPLAYITEM_STR, name_value, StaticStrings.LANG_STR, lang, text, to);
-			displayItemList.appendChild(displayItem);
-		    }
-		    
+		if (e_list != null)
+		{
+
+			for (int j = 0; j < e_list.getLength(); j++)
+			{
+				Element e = (Element) e_list.item(j);
+				if (e.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR))
+				{
+					continue;
+				}
+				String text = XMLTools.getNodeText(e);
+				String lang = e.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE);
+				String name_value = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
+
+				String name_mapping = (String) attributeMap.get(name_value);
+				if (name_mapping != null)
+				{
+					name_value = name_mapping;
+				}
+
+				Element displayItem = constructElement(StaticStrings.DISPLAYITEM_STR, name_value, StaticStrings.LANG_STR, lang, text, to);
+				displayItemList.appendChild(displayItem);
+			}
+
 		}
 		destination.appendChild(displayItemList);
@@ -1416,13 +1428,13 @@
 	}
 
-  // convert global format statement
+	// convert global format statement
 	static private void convertGlobalFormat(Document from, Document to)
 	{
-	  Element e = XMLTools.getNamedElement(from.getDocumentElement(), StaticStrings.FORMAT_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.GLOBAL_STR);
-
-	to.getDocumentElement().appendChild(convertFormat(to, e));
-
-	}
-  
+		Element e = XMLTools.getNamedElement(from.getDocumentElement(), StaticStrings.FORMAT_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.GLOBAL_STR);
+
+		to.getDocumentElement().appendChild(convertFormat(to, e));
+
+	}
+
 	// Convert plugins in the internal(i.e. Document from) to collectionconfig.xml (i.e. Document to)
 	static private void convertPlugin(Document from, Document to)
@@ -2102,40 +2114,43 @@
 	}
 
-  // handle top level elements which GLI knows nothing about
-  // we store them internally in a Unknown element for easy access when
-  // we write them out.
-  static private void doUnknownElements(Document to, Element from) {
-    Element toElement = to.getDocumentElement();
-    Element unknownElement = to.createElement(StaticStrings.UNKNOWN_ELEMENT);
-    toElement.appendChild(unknownElement);
-    
-    Node child = from.getFirstChild();
-    while (child != null)
-      {
-	System.err.println("child name=" +child.getNodeName());
-	if (child.getNodeType() == Node.ELEMENT_NODE && ! known_element_names.contains(child.getNodeName())) {
-	  unknownElement.appendChild(XMLTools.duplicateElement(to, (Element) child, true));
-	}
-	child = child.getNextSibling();
-      }
-    
-  }
-
-    // just copy all children of Unknown element into output doc.
-  static private void convertUnknownElements(Document from, Document to) {
-
-    Element toElement = to.getDocumentElement();
-    Node unknown_element = XMLTools.getChildByTagName(from.getDocumentElement(), StaticStrings.UNKNOWN_ELEMENT);
-
-    Node child = unknown_element.getFirstChild();
-    while (child != null)
-      {
-	Element to_element = XMLTools.duplicateElement(to, (Element) child, true);
-	toElement.appendChild(to_element);
-	
-	child = child.getNextSibling();
-      }
-
-  }
+	// handle top level elements which GLI knows nothing about
+	// we store them internally in a Unknown element for easy access when
+	// we write them out.
+	static private void doUnknownElements(Document to, Element from)
+	{
+		Element toElement = to.getDocumentElement();
+		Element unknownElement = to.createElement(StaticStrings.UNKNOWN_ELEMENT);
+		toElement.appendChild(unknownElement);
+
+		Node child = from.getFirstChild();
+		while (child != null)
+		{
+			System.err.println("child name=" + child.getNodeName());
+			if (child.getNodeType() == Node.ELEMENT_NODE && !known_element_names.contains(child.getNodeName()))
+			{
+				unknownElement.appendChild(XMLTools.duplicateElement(to, (Element) child, true));
+			}
+			child = child.getNextSibling();
+		}
+
+	}
+
+	// just copy all children of Unknown element into output doc.
+	static private void convertUnknownElements(Document from, Document to)
+	{
+
+		Element toElement = to.getDocumentElement();
+		Node unknown_element = XMLTools.getChildByTagName(from.getDocumentElement(), StaticStrings.UNKNOWN_ELEMENT);
+
+		Node child = unknown_element.getFirstChild();
+		while (child != null)
+		{
+			Element to_element = XMLTools.duplicateElement(to, (Element) child, true);
+			toElement.appendChild(to_element);
+
+			child = child.getNextSibling();
+		}
+
+	}
 
 	// Append the element son to the element mother in the appropriate position.
@@ -2425,5 +2440,5 @@
 		{
 			doMGPPIndexes(dOc, searchNode);
-		}		
+		}
 
 		doDefaultIndex(dOc, searchNode);
@@ -2443,5 +2458,5 @@
 		doReplaceList(dOc, fromElement);
 		doServiceRackList(dOc, fromElement);
-		doUnknownElements(dOc, fromElement); 
+		doUnknownElements(dOc, fromElement);
 		// the official displayItems in the displayItemList element have already been handled above
 		// and created as collectionmetadata elements in the dOc object
@@ -2449,42 +2464,52 @@
 		NodeList collectionMetadataList = dOc.getDocumentElement().getElementsByTagName(StaticStrings.COLLECTIONMETADATA_ELEMENT);
 		Set setOfUniqueColMetaNames = new HashSet();
-		for(int i = 0; i < collectionMetadataList.getLength(); i++) {
-		    Element colMeta = (Element)collectionMetadataList.item(i);
-		    String name = colMeta.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-		    setOfUniqueColMetaNames.add(name);
+		for (int i = 0; i < collectionMetadataList.getLength(); i++)
+		{
+			Element colMeta = (Element) collectionMetadataList.item(i);
+			String name = colMeta.getAttribute(StaticStrings.NAME_ATTRIBUTE);
+			setOfUniqueColMetaNames.add(name);
 		}
 
 		if (displayItemListNode != null)
 		{
-		    NodeList nl = ((Element)displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR);
-
-		    // make a list of all unique attribute names that are specifically not
-		    // description, smallicon, icon and name, since these are already processed above
-		    Set setOfUniqueDisplayItemNames = new LinkedHashSet();
-		    for(int i = 0; i < nl.getLength(); i++) {
-			Element displayItem = (Element)nl.item(i);
-			String name = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-
-			if(name.equals("")) continue; // no name attribute
-			if(setOfUniqueColMetaNames.contains(name)) continue;
-
-			if(name.equals(StaticStrings.DESCRIPTION_STR)) continue;
-			if(name.equals(StaticStrings.SMALLICON_STR)) continue;
-			if(name.equals(StaticStrings.ICON_STR)) continue;
-			if(name.equals(StaticStrings.NAME_STR)) continue;
-			// don't add displayItems that are handled by the indexers, etc. E.g. document:ex.Title 
-			if(name.indexOf(":") != -1) continue;
-
-			// otherwise
-			setOfUniqueDisplayItemNames.add(name); // Set will ensure no duplicate names
-		    }
-		    
-		    Iterator i = setOfUniqueDisplayItemNames.iterator();
-		    while (i.hasNext()) {
-			String displayItemName = (String)i.next();
-
-			ArrayList custom_displayItem = doDisplayItemList(dOc, displayItemListNode, displayItemName, displayItemName);		
-			appendArrayList(toElement, custom_displayItem);
-		    }
+			NodeList nl = ((Element) displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR);
+
+			// make a list of all unique attribute names that are specifically not
+			// description, smallicon, icon and name, since these are already processed above
+			Set setOfUniqueDisplayItemNames = new LinkedHashSet();
+			for (int i = 0; i < nl.getLength(); i++)
+			{
+				Element displayItem = (Element) nl.item(i);
+				String name = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
+
+				if (name.equals(""))
+					continue; // no name attribute
+				if (setOfUniqueColMetaNames.contains(name))
+					continue;
+
+				if (name.equals(StaticStrings.DESCRIPTION_STR))
+					continue;
+				if (name.equals(StaticStrings.SMALLICON_STR))
+					continue;
+				if (name.equals(StaticStrings.ICON_STR))
+					continue;
+				if (name.equals(StaticStrings.NAME_STR))
+					continue;
+				// don't add displayItems that are handled by the indexers, etc. E.g. document:ex.Title 
+				if (name.indexOf(":") != -1)
+					continue;
+
+				// otherwise
+				setOfUniqueDisplayItemNames.add(name); // Set will ensure no duplicate names
+			}
+
+			Iterator i = setOfUniqueDisplayItemNames.iterator();
+			while (i.hasNext())
+			{
+				String displayItemName = (String) i.next();
+
+				ArrayList custom_displayItem = doDisplayItemList(dOc, displayItemListNode, displayItemName, displayItemName);
+				appendArrayList(toElement, custom_displayItem);
+			}
 		}
 
@@ -2508,5 +2533,5 @@
 		//first parse an empty skeleton of xml config file
 		//The aim is to convert the internal structure into this skeleton
-	  // This skeleton just has the CollectionConfig element and nothing else
+		// This skeleton just has the CollectionConfig element and nothing else
 		Document skeleton = XMLTools.parseXMLFile("xml/CollectionConfig.xml", true);
 		//Element internal = dOc.getDocumentElement();
