Index: /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 14049)
+++ /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 14050)
@@ -193,6 +193,7 @@
     public boolean built() {
 	if(collection != null) {
-	    // Determine if the collection has been built by looking for the build.cfg file
-	    File build_cfg_file = new File(getLoadedCollectionIndexDirectoryPath() + "build.cfg");
+	    // Determine if the collection has been built by looking for the build.cfg or buildConfig.xml file
+	    String file_name = (Gatherer.GS3)? Utility.BUILD_CONFIG_XML : Utility.BUILD_CFG;
+	    File build_cfg_file = new File(getLoadedCollectionIndexDirectoryPath() + file_name);
 	    return build_cfg_file.exists();
 	}
@@ -252,24 +253,24 @@
     }
 
-
-    public void convertToGS3Collection() {
-	// Generate the convert_coll_from_gs2.pl command
-	ArrayList command_parts_list = new ArrayList();
-	if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
-	    command_parts_list.add(Configuration.perl_path);
-	    command_parts_list.add("-S");
-	}
-	command_parts_list.add(Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl");
-	command_parts_list.add("-collectdir");
-	command_parts_list.add(getCollectDirectory());
-    	command_parts_list.add(collection.getName());
-
-	// Run the convert_coll_from_gs2.pl command
-	String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
-	GShell process = new GShell(command_parts, GShell.CONVERT, COLLECT, this, null, GShell.GSHELL_CONVERT);
-	process.addGShellListener(this);
-	process.run(); // Don't bother threading this... yet
-       
-    }
+//This method is no longer used in gs3 since the modification of CollectionConfiguration.java
+//    public void convertToGS3Collection() {
+//	// Generate the convert_coll_from_gs2.pl command
+//	ArrayList command_parts_list = new ArrayList();
+//	if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
+//	    command_parts_list.add(Configuration.perl_path);
+//	    command_parts_list.add("-S");
+//	}
+//	command_parts_list.add(Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl");
+//	command_parts_list.add("-collectdir");
+//	command_parts_list.add(getCollectDirectory());
+//    	command_parts_list.add(collection.getName());
+//
+//	// Run the convert_coll_from_gs2.pl command
+//	String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
+//	GShell process = new GShell(command_parts, GShell.CONVERT, COLLECT, this, null, GShell.GSHELL_CONVERT);
+//	process.addGShellListener(this);
+//	process.run(); // Don't bother threading this... yet
+//       
+//    }
 
     /** When basing a new collection on an existing one, we need to copy 
@@ -379,12 +380,14 @@
 	    if (!new File(collection_directory_path).exists()) {
 		// If there is no collection directory then the creation was unsuccessful, or cancelled
-		System.err.println("No collection directory...");
+
 		return;
 	    }
 
-	    // Check for the existence of the collect.cfg file
-	    File collect_cfg_file = new File(collection_directory_path + "etc" + File.separator + "collect.cfg");
+	    // Check for the existence of the collection configuration file
+	    String file_name = ((Gatherer.GS3 == true)? Utility.COLLECTION_CONFIG_XML : Utility.COLLECT_CFG);
+	    File collect_cfg_file = new File(collection_directory_path + "etc" + File.separator + file_name);
+
 	    if (!collect_cfg_file.exists()) {
-		System.err.println("Error: no collect.cfg file has been created!");
+		System.err.println("Error: no " + file_name + " file has been created!");
 		JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Create_Collection_With_Reason", Dictionary.get("CollectionManager.No_Config_File")), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 
 		return;
@@ -449,6 +452,14 @@
 
 		// Now we update our collect.cfg
-		DebugStream.println("Copy and update collect.cfg from base collection.");
-		updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE), new File(collection_directory_path, Utility.CONFIG_FILE), description, email, title);
+		DebugStream.println("Copy and update " + file_name + " from base collection.");
+
+		if (Gatherer.GS3 == true) {
+		    updateCollectionConfigXML(new File(base_collection_directory, Utility.CONFIG_GS3_FILE),
+					new File(collection_directory_path, Utility.CONFIG_GS3_FILE)); 
+		} else {
+		    updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE),
+					new File(collection_directory_path, Utility.CONFIG_FILE),
+					description, email, title);
+		}
 	    }
 
@@ -467,5 +478,5 @@
 	    collection_extra_collectionmeta.setValue(description);
 
-	    // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically
+	    // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically. This update is done to the internal xml structure which may be saved into collect.cfg or collectionConfig.xml accordingly.
 	    if (base_collection_directory != null) {
 		// Update the creator and maintainer
@@ -594,5 +605,6 @@
     static public String getLoadedCollectionCfgFilePath()
     {
-	return getLoadedCollectionEtcDirectoryPath() + "collect.cfg";
+	String path = (Gatherer.GS3 == true)? Utility.COLLECTION_CONFIG_XML : Utility.COLLECT_CFG;
+	return getLoadedCollectionEtcDirectoryPath() + path;
     }
 
@@ -878,4 +890,5 @@
 	// Ensure that the directory exists
 	File collection_directory = collection_file.getParentFile();
+	   
 	if (collection_directory == null || !collection_directory.exists()) {
 	    // We can't open this
@@ -884,5 +897,6 @@
 	}
 
-	File collection_config_file = new File(collection_directory, Utility.CONFIG_FILE);
+	String file_str = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
+	File collection_config_file = new File(collection_directory, file_str);
 	if (!collection_config_file.exists()) {
 	    System.err.println("CollectionManager.loadCollection: No config file.");
@@ -1031,6 +1045,10 @@
 	command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "mkcol.pl");
 
+	command_parts_list.add((Gatherer.GS3) ? Utility.GS3MODE_ARGUMENT : "");// add '-gs3mode' 
+
 	command_parts_list.add("-collectdir");
 	command_parts_list.add(getCollectDirectory());
+
+	
 	command_parts_list.add("-win31compat");
 	command_parts_list.add((Gatherer.isGsdlRemote) ? "false" : "true");
@@ -1042,7 +1060,8 @@
 
 	command_parts_list.add(name);
-
+	
 	// Run the mkcol.pl command
 	String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
+
 	GShell process = new GShell(command_parts, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW);
 	process.run(); // Don't bother threading this... yet
@@ -1114,5 +1133,5 @@
 		}
 		else if (Gatherer.GS3) {
-		    convertToGS3Collection();
+		    //xiao comment out this: convertToGS3Collection();
 		    Gatherer.configGS3Server(Configuration.site_name, ServletConfiguration.ADD_COMMAND + collection.getName());
 		}  
@@ -1380,5 +1399,91 @@
     }
 
-
+    private void updateCollectionConfigXML(File base_cfg, File new_cfg) {
+	//In this method, the files base_cfg and new_cfg are all xml files.
+
+	Document base_cfg_doc = XMLTools.parseXMLFile(base_cfg);
+	XMLTools.writeXMLFile(new_cfg, base_cfg_doc);
+	Document new_cfg_doc = XMLTools.parseXMLFile(new_cfg);
+	Element collection_config = new_cfg_doc.getDocumentElement();
+
+	Node browseNode = XMLTools.getChildByTagNameIndexed(collection_config, StaticStrings.BROWSE_STR, 0);
+	NodeList classifier_children = ((Element)browseNode).getElementsByTagName(StaticStrings.CLASSIFIER_STR);
+	int num_nodes = classifier_children.getLength();
+	
+	if (num_nodes < 1) {
+	    return;
+	}
+
+		// Read in the classifier command watching for hfile, metadata and sort arguments.
+		String buttonname = null;
+		String hfile = null;
+		String metadata = null;
+		String sort = null;
+		
+	for (int i=0; i<num_nodes; i++) {
+	    Element classifier_element = (Element)classifier_children.item(i);
+	    NodeList option_children = classifier_element.getElementsByTagName(StaticStrings.OPTION_STR);
+	    for (int j=0; j<option_children.getLength(); j++) {
+		Element option_element = (Element)option_children.item(j);
+	        String name_str = option_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
+ 		String value_str = option_element.getAttribute(StaticStrings.VALUE_ATTRIBUTE);
+		    
+		if (name_str == null || name_str.equals("")) {
+		    continue;
+		}
+		if (name_str != null && value_str == null ) {
+		    value_str = "";
+		}
+		if (name_str.equals("hfile")) {
+		    hfile = value_str;
+		} 
+		else if (name_str.equals("metadata") && value_str != null) { 
+		    String replacement = ProfileXMLFileManager.getMetadataElementFor(value_str);
+		    if (replacement != null && !replacement.equals("")) {
+			metadata = replacement;
+		    }
+		}
+		else if (name_str.equals("sort") && value_str != null) { 
+		    String replacement = ProfileXMLFileManager.getMetadataElementFor(value_str);
+		    if (replacement != null && !replacement.equals("")) {
+			sort = replacement;
+		    }
+		}
+		else if(name_str.equals("buttonname") && value_str != null) {
+		    buttonname = value_str;
+		}
+	    }
+	}
+	for (int i=0; i<num_nodes; i++) {
+	    Element classifier_element = (Element)classifier_children.item(i);
+	    NodeList option_children = classifier_element.getElementsByTagName(StaticStrings.OPTION_STR);
+	    for (int j=0; j<option_children.getLength(); j++) {
+		Element option_element = (Element)option_children.item(j);
+	        String name_str = option_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
+		
+		if (name_str.equals("metadata") && metadata != null) { 
+		    option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata);
+		}
+		else if (name_str.equals("hfile") && hfile != null) {
+		    option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata + ".txt");
+		}
+		else if (name_str.equals("sort") && sort != null) { 
+		    option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, sort);
+		}
+		else if(name_str.equals("buttonname") && buttonname == "") {
+		    option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata);		    
+		}
+		else if(buttonname == null) {
+		    // No buttonname has been specified. Lets create one using the metadata as its value
+		    Element option = new_cfg_doc.createElement(StaticStrings.OPTION_STR);
+		    option.setAttribute(StaticStrings.NAME_ATTRIBUTE, "buttonname");
+		    option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata);	
+		    classifier_element.appendChild(option);
+		}
+	    }
+	}
+	
+    }
+	
     private void updateCollectionCFG(File base_cfg, File new_cfg, String description, String email, String title)
     {
