Index: /trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java	(revision 9907)
+++ /trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java	(revision 9908)
@@ -242,7 +242,7 @@
 	    return self.metadataToString(command_element, show_extracted_namespace);
 	}
-	// else if(command_element_name.equals(COLLECTIONMETADATA_BETA_ELEMENT)) {
-	//     return self.metadataToString(command_element, show_extracted_namespace);
-	// }
+	else if (command_element_name.equals(BUILDTYPE_ELEMENT)) {
+	    return self.metadataToString(command_element, show_extracted_namespace);
+	}
 	else if(command_element_name.equals(PLUGIN_ELEMENT)) {
 	    return self.pluginToString(command_element, show_extracted_namespace);
@@ -310,5 +310,5 @@
 
     /** Gives the preferred ordering of commands */
-    static final private String[] COMMAND_ORDER = {StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT, StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT, StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT, /* StaticStrings.COLLECTIONMETADATA_BETA_ELEMENT, */ StaticStrings.SEARCHTYPE_ELEMENT, StaticStrings.PLUGIN_ELEMENT, StaticStrings.INDEXES_ELEMENT, StaticStrings.LEVELS_ELEMENT, StaticStrings.INDEX_DEFAULT_ELEMENT, StaticStrings.LANGUAGES_ELEMENT, StaticStrings.LANGUAGE_DEFAULT_ELEMENT, StaticStrings.SUBCOLLECTION_ELEMENT, StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT, StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT, StaticStrings.SUPERCOLLECTION_ELEMENT, StaticStrings.CLASSIFY_ELEMENT, StaticStrings.FORMAT_ELEMENT, StaticStrings.COLLECTIONMETADATA_ELEMENT};
+    static final private String[] COMMAND_ORDER = {StaticStrings.COLLECTIONMETADATA_CREATOR_ELEMENT, StaticStrings.COLLECTIONMETADATA_MAINTAINER_ELEMENT, StaticStrings.COLLECTIONMETADATA_PUBLIC_ELEMENT,  StaticStrings.SEARCHTYPE_ELEMENT, StaticStrings.BUILDTYPE_ELEMENT, StaticStrings.PLUGIN_ELEMENT, StaticStrings.INDEXES_ELEMENT, StaticStrings.LEVELS_ELEMENT, StaticStrings.INDEX_DEFAULT_ELEMENT, StaticStrings.LANGUAGES_ELEMENT, StaticStrings.LANGUAGE_DEFAULT_ELEMENT, StaticStrings.SUBCOLLECTION_ELEMENT, StaticStrings.SUBCOLLECTION_INDEXES_ELEMENT, StaticStrings.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT, StaticStrings.SUPERCOLLECTION_ELEMENT, StaticStrings.CLASSIFY_ELEMENT, StaticStrings.FORMAT_ELEMENT, StaticStrings.COLLECTIONMETADATA_ELEMENT};
 
     /** ************************** Public Data Members ***************************/
@@ -316,6 +316,4 @@
     /** ************************** Private Data Members ***************************/
     
-    /** Is the configuration file currently being read in one of the infamous G2.39 ones. */
-    private boolean is_twopointthreenine = false;
     private File collect_config_file;
 
@@ -358,10 +356,4 @@
     }
 
-//      public Element getBeta() {
-//  	Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_BETA_ELEMENT, null, null);
-//  	element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_BETA_STR);
-//  	element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
-//  	return element;
-//      }
 
     public Element getCreator() {
@@ -412,4 +404,11 @@
     }
 
+    public Element getBuildType() {
+	Element element = getOrCreateElementByTagName(BUILDTYPE_ELEMENT, null, null);
+	element.setAttribute(NAME_ATTRIBUTE, BUILDTYPE_STR);
+	element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
+	return element;
+
+    }
     /** Retrieve or create the searchtype element. */
     public Element getSearchType() {
@@ -479,8 +478,4 @@
 		//FileWriter file_writer = new FileWriter(collect_config_file, false);
 		BufferedWriter buffered_writer = new BufferedWriter(file_writer);
-		// In order to write out an old style collect.cfg we have to traverse the model and do several 'cute' tricks to ensure the collect.cfg is valid (for instance while every metadata element has a language attribute, only second or subsequent metadata, for a certain name, needs a language argument - hence the known metadata array. Note that within GLI the language will always be shown, but it doesn't crash and burn like G2 does, te-he).
-		// is this still true?? now we are writing all metadata with a lang tag. can we get rid of known_metadata??
-		// Yes we can. Lets see..
-		// known_metadata = new ArrayList(); 'blamo'
 		Element collect_config_element = document.getDocumentElement();
 		NodeList command_elements = collect_config_element.getChildNodes();
@@ -513,5 +508,4 @@
 		}
 		buffered_writer.close();
-		// known_metadata = null; 'poof'
 	    }
 	    catch (Exception exception) {
@@ -782,10 +776,10 @@
 	String name_str = command_element.getAttribute(NAME_ATTRIBUTE);
 	// If the name is one of the special four, we don't write the collectionmeta first. Note the maintainer collectionmeta is singled out for 'prittying' reasons.
-	if(name_str.equals(COLLECTIONMETADATA_MAINTAINER_STR)) {
+	if(name_str.equals(COLLECTIONMETADATA_MAINTAINER_STR)|| name_str.equals(BUILDTYPE_STR) ) {
 	    text.append(name_str);
 	    text.append(TAB_CHARACTER);
 	    special = true;
 	}
-	else if (/* name_str.equals(COLLECTIONMETADATA_BETA_STR) || */ name_str.equals(COLLECTIONMETADATA_CREATOR_STR) || name_str.equals(COLLECTIONMETADATA_PUBLIC_STR)) {
+	else if (name_str.equals(COLLECTIONMETADATA_CREATOR_STR) || name_str.equals(COLLECTIONMETADATA_PUBLIC_STR) ) {
 	    text.append(name_str);
 	    text.append(TAB_CHARACTER);
@@ -799,7 +793,4 @@
 	    text.append(SPACE_CHARACTER);
 	    String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);
-	    // If this is element is in english, and it is the first one found, we don't need to write the language argument.
-	    //if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {
-	    // changed so that we always write the language string
 	    text.append(LBRACKET_CHARACTER);
 	    text.append(LANGUAGE_ARGUMENT);
@@ -807,5 +798,5 @@
 	    text.append(RBRACKET_CHARACTER);
 	    text.append(SPACE_CHARACTER);
-	    //}
+
 	    if(known_metadata != null) {
 		known_metadata.add(name_str);
@@ -837,35 +828,8 @@
     }
 
-    /** Parse a collect.cfg into a DOM model representation. */
+    /** Parse a collect.cfg into a DOM model representation. 
+     * note we are ignoring 2.39 compatibility now. */
     private void parse(File collect_config_file) {
 	try {
-	    ArrayList acquired_collectionmeta_names = null;
-	    ArrayList obsolete_collectionmeta_names = null;
-	    HashMap changed_collectionmeta_names = null;
-	    
-	    // Life is made oh-so-more tricky by the existance of G2.39 config files. There are two ways to handle them:
-	    // 1. Notice that the file is G2.39 from the start, then as I parse it magic it into G2.4 standard
-	    // 2. Extend the parsing method to handle reading in G2.39, then afterwards go through the DOM changing it to G2.4 as appropriate. 
-	    // As far as I can tell the second option is twice as much work, so I'll try option 1. The problem here is that I have to determine if the 'buildtype' command is somewhere in the collect.cfg file, which means I'm going to have to read the file twice - once seaching for 'buildtype' and the second time to parse it.
-
-	    // Search for 'buildtype mgpp' 
-	    InputStream input_stream_one = new FileInputStream(collect_config_file);
-	    Reader reader_one = new InputStreamReader(input_stream_one, ENCODING);
-	    BufferedReader buffered_reader_one = new BufferedReader(reader_one);
-	    String search_line_str = null;
-	    while(!is_twopointthreenine && (search_line_str = buffered_reader_one.readLine()) != null) {
-		if(search_line_str.toLowerCase().indexOf(BUILDTYPE_STR) != -1) {
-		    is_twopointthreenine = true;
-		    acquired_collectionmeta_names = new ArrayList();
-		    changed_collectionmeta_names = new HashMap();
-		    obsolete_collectionmeta_names = new ArrayList();
-		}
-	    }
-	    buffered_reader_one.close();
-	    reader_one.close();
-	    input_stream_one.close();
-	    buffered_reader_one = null;
-	    reader_one = null;
-	    input_stream_one = null;
 
 	    Element collect_cfg_element = document.getDocumentElement();
@@ -910,9 +874,4 @@
 		    String command_type = tokenizer.nextToken().toLowerCase();
 		    // Why can't you switch on strings eh? We pass it to the various subparsers who each have a bash at parsing the command. If none can parse the command, an unknown element is created
-		    if(command_element == null && command_type.equals(BUILDTYPE_STR)) {
-			DebugStream.println("G2.39 Buildtype command detected. Ignoring.");
-			command_element = document.createElement(UNKNOWN_ELEMENT);
-			append_element = false;
-		    }
 		    if(command_element == null && command_type.equals(CLASSIFY_STR)) {
 			command_element = parseClassify(command_str);
@@ -922,50 +881,4 @@
 		    }
 		    if(command_element == null && (command_type.equals(INDEX_STR)  || command_type.equals(COMMENTED_INDEXES_STR))) {
-			// If this was a G2.39 config file then we manipulate the command string a bit before we submit it to the parser. We start by adding allfields as the first index. We then space separate the remaining indexes, and remove duplicates when encountered. Of course before we do any of that we record the various space separated indexes so that we can remove the collection meta assigned to them.
-			if(is_twopointthreenine) {
-			    DebugStream.println("G2.39 Index command detected. Modifying.");
-			    DebugStream.println("Before: " + command_str);
-			    StringBuffer new_command_str = new StringBuffer(command_type);
-			    new_command_str.append(SPACE_CHARACTER);
-			    new_command_str.append(ALLFIELDS_STR);
-			    new_command_str.append(SPACE_CHARACTER);
-			    ArrayList known_indexes = new ArrayList();
-			    while(tokenizer.hasMoreTokens()) {
-				String old_index_str = tokenizer.nextToken();
-				// If this index is a combination of sources, then we need to remove the old collectionmeta, split up the compound index, then request new metadata be added for each part
-				if(old_index_str.indexOf(COMMA_CHARACTER) != -1) {
-				    obsolete_collectionmeta_names.add(STOP_CHARACTER + old_index_str);
-				    StringTokenizer string_tokenizer = new StringTokenizer(old_index_str, COMMA_CHARACTER);
-				    while(string_tokenizer.hasMoreTokens()) {
-					String index_fragment_str = string_tokenizer.nextToken();
-					if(!known_indexes.contains(index_fragment_str)) {
-					    known_indexes.add(index_fragment_str);
-					    new_command_str.append(index_fragment_str);
-					    new_command_str.append(SPACE_CHARACTER);
-					    acquired_collectionmeta_names.add(STOP_CHARACTER + index_fragment_str);
-					}
-					index_fragment_str = null;
-				    }
-				    string_tokenizer = null;
-				}
-				// However if this was just a single index then a little choir of angels sing haleluja because we don't have to do -anything-. Nothing at all. Zip. Well no changes anyway. I obviously had to write this comment, and you can probably see, assuming you are not blind, that there are several lines of code below doing something, which is of course not nothing but something. And if we assume you are blind then you probably can't see the code, but then you probably didn't not see it doing the not nothing I said it would above.
-				else {
-				    if(!known_indexes.contains(old_index_str)) {
-					known_indexes.add(old_index_str);
-					new_command_str.append(old_index_str);
-					new_command_str.append(SPACE_CHARACTER);
-				    }
-				    else {
-					// Use the collectionmeta for the single index instead of generating a default one
-					acquired_collectionmeta_names.remove(STOP_CHARACTER + old_index_str);
-				    }
-				}
-				old_index_str = null;
-			    }
-			    known_indexes = null;
-			    command_str = new_command_str.toString();
-			    new_command_str = null;
-			    DebugStream.println("After: " + command_str);
-			}
 			command_element = parseIndex(command_str);
 		    }
@@ -973,9 +886,4 @@
 			
 			command_element = parseIndexDefault(command_str);
-			// If this was a G2.39 config file then we squelch the default index (no such thing in G2.4)
-			if(is_twopointthreenine) {
-			    DebugStream.println("G2.39 Default Index command detected. Ignoring.");
-			    append_element = false;
-			}
 		    }
 		    if(command_element == null && command_type.equals(LANGUAGES_STR)) {
@@ -986,28 +894,4 @@
 		    }
 		    if(command_element == null && (command_type.equals(LEVELS_STR) || command_type.equals(COMMENTED_LEVELS_STR))) {
-			// Again if this is G2.39 we have to do a tiny bit of magic to the levels command. We need to add document level, and change the remainder to lower case.
-			if(is_twopointthreenine) {
-			    DebugStream.println("G2.39 Levels command detected. Modifying.");
-			    DebugStream.println("Before: " + command_str);
-			    StringBuffer new_command_str = new StringBuffer(command_type);
-			    new_command_str.append(SPACE_CHARACTER);
-			    new_command_str.append(DOCUMENT_STR);
-			    while(tokenizer.hasMoreTokens()) {
-				String token = tokenizer.nextToken();
-				// Generate a lower case version
-				String token_lc = token.toLowerCase();
-				// If they are still the same then it is all good baby, otherwise we have to remember to transform their collectionmeta as well
-				if(!token.equals(token_lc)) {
-				    changed_collectionmeta_names.put(STOP_CHARACTER + token, STOP_CHARACTER + token_lc);
-				}
-				new_command_str.append(SPACE_CHARACTER);
-				new_command_str.append(token_lc);
-				token_lc = null;
-				token = null;
-			    }
-			    command_str = new_command_str.toString();
-			    new_command_str = null;
-			    DebugStream.println("After: " + command_str);
-			}
 			command_element = parseLevels(command_str);
 		    }
@@ -1015,5 +899,5 @@
 			command_element = parseMetadata(tokenizer); // Revised to handle multiple lines
 		    }
-		    if(command_element == null && (/* command_type.equals(COLLECTIONMETADATA_BETA_STR) || */ command_type.equals(COLLECTIONMETADATA_PUBLIC_STR) || command_type.equals(COLLECTIONMETADATA_CREATOR_STR) || command_type.equals(COLLECTIONMETADATA_MAINTAINER_STR))) {
+		    if(command_element == null && (command_type.equals(COLLECTIONMETADATA_PUBLIC_STR) || command_type.equals(COLLECTIONMETADATA_CREATOR_STR) || command_type.equals(COLLECTIONMETADATA_MAINTAINER_STR) || command_type.equals(BUILDTYPE_STR))) {
 			command_element = parseMetadataSpecial(command_str);
 		    }
@@ -1049,69 +933,9 @@
 		}
 		// Now command element shouldn't be null so we append it to the collection config DOM, but only if we haven't been told not to add it
-		if(append_element) {
+		//if(append_element) {
 		    collect_cfg_element.appendChild(command_element);
-		}
-	    }
-
-	    // We have completed parsing the collect configuration file. Now, if we are dealing with the G2.39 nightmare scenario, it's time to add the SearchType command and modify the collectionmeta commands as necessary.
-	    if(is_twopointthreenine) {
-		Element search_type_element = getSearchType();
-		search_type_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
-		while(search_type_element.hasChildNodes()) {
-		    search_type_element.removeChild(search_type_element.getFirstChild());
-		}
-		Element plain_search_type_element = document.createElement(CONTENT_ELEMENT);
-		plain_search_type_element.setAttribute(NAME_ATTRIBUTE, SearchTypeManager.SEARCH_TYPES[1]);
-		search_type_element.appendChild(plain_search_type_element);
-		plain_search_type_element = null;
-		Element form_search_type_element = document.createElement(CONTENT_ELEMENT);
-		form_search_type_element.setAttribute(NAME_ATTRIBUTE, SearchTypeManager.SEARCH_TYPES[0]);
-		search_type_element.appendChild(form_search_type_element);
-		form_search_type_element = null;
-		search_type_element = null;
-		
-		// Search through the existing collectionmeta
-		Element document_element = document.getDocumentElement();
-		NodeList collectionmeta_elements = document_element.getElementsByTagName(COLLECTIONMETADATA_ELEMENT);
-		DebugStream.println("There are " + obsolete_collectionmeta_names.size() + " collectionmeta to remove.");
-		DebugStream.println("There are " + changed_collectionmeta_names.size() + " collectionmeta to change.");
-		for(int z = collectionmeta_elements.getLength(); z > 0; z--) {
-		    Element collectionmeta_element = (Element) collectionmeta_elements.item(z - 1);
-		    String name = collectionmeta_element.getAttribute(NAME_ATTRIBUTE);
-		    DebugStream.println("Checking " + name);
-		    // Remove any obsolete metadata
-		    if(obsolete_collectionmeta_names.contains(name)) {
-			DebugStream.println("G2.39 CollectMeta detected. Removing: " + name);
-			document_element.removeChild(collectionmeta_element);
-		    }
-		    // We may have been asked to change the index name to lower case
-		    else if(changed_collectionmeta_names.containsKey(name)) {
-			String new_name = (String) changed_collectionmeta_names.get(name);
-			DebugStream.println("G2.39 CollectMeta detected. Changing: " + name + " -> " + new_name);
-			collectionmeta_element.setAttribute(NAME_ATTRIBUTE, new_name);
-			new_name = null;
-		    }
-		    name = null;
-		}
-
-		// Finally add any newly acquired collectionmeta. This general defaults to the collectionmeta name less the full stop
-		DebugStream.println("There are " + acquired_collectionmeta_names.size() + " collectionmeta to add.");
-		for(int y = 0; y < acquired_collectionmeta_names.size(); y++) {
-		    String name = (String) acquired_collectionmeta_names.get(y);
-		    String value = name.substring(1);
-		    DebugStream.println("G2.39 CollectMeta missing. Adding: " + name + " [l=" + Configuration.getLanguage() + "] \"" + value + "\"");
-		    Element element = document.createElement(COLLECTIONMETADATA_ELEMENT);
-		    element.setAttribute(NAME_ATTRIBUTE, name);
-		    element.setAttribute(LANGUAGE_ATTRIBUTE, Configuration.getLanguage());
-		    element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
-		    XMLTools.setValue(element, value);
-		    document_element.appendChild(element);
-		    element = null;
-		    value = null;
-		    name = null;
-		}
-
-		document_element = null;
-	    }
+		    //}
+	    }
+
 	}
 	catch(Exception exception) {
@@ -1312,4 +1136,32 @@
 	return command_element;
     }
+    private Element parseBuildType(String command_str) {
+	Element command_element = null;
+	try {
+	    StringTokenizer tokenizer = new StringTokenizer(command_str);
+	    if(tokenizer.countTokens() >= 2) {
+		command_element = document.createElement(INDEX_DEFAULT_ELEMENT);
+		command_element.setAttribute(ASSIGNED_ATTRIBUTE, ((tokenizer.nextToken()).equals(INDEX_DEFAULT_STR) ? TRUE_STR : FALSE_STR));
+		String index_str = tokenizer.nextToken();
+		command_element.setAttribute(LEVEL_ATTRIBUTE, index_str.substring(0, index_str.indexOf(StaticStrings.COLON_CHARACTER)));
+		String content_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1);
+		StringTokenizer content_tokenizer = new StringTokenizer(content_str, StaticStrings.COMMA_CHARACTER);
+		while(content_tokenizer.hasMoreTokens()) {
+		    Element content_element = document.createElement(CONTENT_ELEMENT);
+		    content_element.setAttribute(NAME_ATTRIBUTE, content_tokenizer.nextToken());
+		    command_element.appendChild(content_element);
+		    content_element = null;
+		}
+		content_tokenizer = null;
+		content_str = null;
+		content_str = null;
+		index_str = null;
+	    }
+	    tokenizer = null;
+	}
+	catch (Exception exception) {
+	}
+	return command_element;
+    }
 
     private Element parseLanguage(String command_str) {
@@ -1422,7 +1274,4 @@
 		String name_str = tokenizer.nextToken();
 		String value_str = tokenizer.nextToken();
-		// if(name_str.equals(COLLECTIONMETADATA_BETA_STR)) {
-		//     command_element = document.createElement(COLLECTIONMETADATA_BETA_ELEMENT);
-		// }
 		if (name_str.equals(COLLECTIONMETADATA_CREATOR_STR)) {
 		    command_element = document.createElement(COLLECTIONMETADATA_CREATOR_ELEMENT);
@@ -1433,4 +1282,7 @@
 		else if(name_str.equals(COLLECTIONMETADATA_PUBLIC_STR)) {
 		    command_element = document.createElement(COLLECTIONMETADATA_PUBLIC_ELEMENT);
+		}
+		else if (name_str.equals(BUILDTYPE_STR)) {
+		    command_element = document.createElement(BUILDTYPE_ELEMENT);
 		}
 		if(command_element != null) {
