Index: /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 24231)
+++ /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 24232)
@@ -1,28 +1,28 @@
 /**
- *#########################################################################
- *
- * A component of the Gatherer application, part of the Greenstone digital
- * library suite from the New Zealand Digital Library Project at the
- * University of Waikato, New Zealand.
- *
- * Author: John Thompson, Greenstone Digital Library, University of Waikato
- *
- * Copyright (C) 1999 New Zealand Digital Library Project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *########################################################################
- */
+*#########################################################################
+*
+* A component of the Gatherer application, part of the Greenstone digital
+* library suite from the New Zealand Digital Library Project at the
+* University of Waikato, New Zealand.
+*
+* Author: John Thompson, Greenstone Digital Library, University of Waikato
+*
+* Copyright (C) 1999 New Zealand Digital Library Project
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*########################################################################
+*/
 package org.greenstone.gatherer;
 
@@ -64,17 +64,17 @@
 
 /** Containing the top-level "core" for the Gatherer, this class is the
- * common core for the GLI application and applet. It first parses the
- * command line arguments, preparing to update the configuration as
- * required. Next it loads several important support classes such as the
- * Configuration and Dictionary. Finally it creates the other important
- * managers and sends them on their way.
- * @author John Thompson, Greenstone Digital Library, University of Waikato
- * @version 2.3
- */
+* common core for the GLI application and applet. It first parses the
+* command line arguments, preparing to update the configuration as
+* required. Next it loads several important support classes such as the
+* Configuration and Dictionary. Finally it creates the other important
+* managers and sends them on their way.
+* @author John Thompson, Greenstone Digital Library, University of Waikato
+* @version 2.3
+*/
 public class Gatherer
 {
-    /** The name of the GLI. */
-    static final public String PROGRAM_NAME = "Greenstone Librarian Interface";
-    /** The current version of the GLI.
+	/** The name of the GLI. */
+	static final public String PROGRAM_NAME = "Greenstone Librarian Interface";
+	/** The current version of the GLI.
 		* Note: the gs3-release-maker relies on this variable being declared
 		* in a line which maches this java regex:
@@ -84,637 +84,641 @@
 		*/
 
-    static final public String PROGRAM_VERSION = "trunk";
-
-    static private Dimension size = new Dimension(800, 540);
-    static public RemoteGreenstoneServer remoteGreenstoneServer = null;
-
-    /** Has the exit flag been set? */
-    static final public int EXIT_THEN_RESTART= 2;
-    static public boolean exit = false;
-    static public int exit_status = 0;
-
-    static private String gli_directory_path = null;
-    static private String gli_user_directory_path = null;
-
-    static public String client_operating_system = null;
-
-    /** All of the external applications that must exit before we close the Gatherer. */
-    static private Vector apps = new Vector();
-    static private String non_standard_collect_directory_path = null;
-    static public String open_collection_file_path = null;
+	static final public String PROGRAM_VERSION = "trunk";
+
+	static private Dimension size = new Dimension(800, 540);
+	static public RemoteGreenstoneServer remoteGreenstoneServer = null;
+
+	/** Has the exit flag been set? */
+	static final public int EXIT_THEN_RESTART= 2;
+	static public boolean exit = false;
+	static public int exit_status = 0;
+
+	static private String gli_directory_path = null;
+	static private String gli_user_directory_path = null;
+
+	static public String client_operating_system = null;
+
+	/** All of the external applications that must exit before we close the Gatherer. */
+	static private Vector apps = new Vector();
+	static private String non_standard_collect_directory_path = null;
+	static public String open_collection_file_path = null;
 	static public String gsdlsite_collecthome = "";
-    /** A public reference to the FileAssociationManager. */
-    static public FileAssociationManager assoc_man;
-    /** A public reference to the CollectionManager. */
-    static public CollectionManager c_man;
-    /** A public reference to the RecycleBin. */
-    static public RecycleBin recycle_bin;
-    /** a reference to the Servlet Configuration is GS3 */
-    static public ServletConfiguration servlet_config;
-    /** A public reference to the FileManager. */
-    static public FileManager f_man;
-    /** A public reference to the GUIManager. */
-    static public GUIManager g_man = null;
-    static private boolean g_man_built = false;
-
-    /** We are using the GLI for GS3 */
-    static public boolean GS3 = false;
-
-    static public boolean isApplet = false;
-    static public boolean isGsdlRemote = false;
-    static public boolean isLocalLibrary = false;
-
-    /* TODO: If we're using local GLI, collections are built locally. If we're using client-GLI
-     * and it contains a gs2build folder in it, then localBuild will also be true (if this is not
-     * turned off in Preferences). If we're remote and this is turned off in Prefs, build remotely. */
-    /*static public boolean buildingLocally = true;*/
-    /** If we're using local GLI, we can always download. If we're using client-GLI, we can only
-     * download if we have a gs2build folder inside it. And if we don't turn off downloadEnabling
-     * in the preferences.
-    */
-    static public boolean isDownloadEnabled = true;
-
-    // feedback stuff
-    /** is the feedback feature enabled? */
-    static public boolean feedback_enabled = true;
-    /** the action recorder dialog */
-    static public ActionRecorderDialog feedback_dialog = null;
-
-    // Refresh reasons
-    static public final int COLLECTION_OPENED   = 0;
-    static public final int COLLECTION_CLOSED   = 1;
-    static public final int COLLECTION_REBUILT  = 2;
-    static public final int PREFERENCES_CHANGED = 3;
-
-   //////kk added////////  
-    static public String cgiBase="";
-    /////////////////
-
-    /** Magic to allow Enter to fire the default button. */
-    static {
-      KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
-      Keymap map = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
-      map.removeKeyStrokeBinding(enter);
-    }
-
-    static private URL default_gliserver_url=null;
-
-    public Gatherer(String[] args) 
-    {
-	// Display the version to make error reports a lot more useful
-	System.err.println("Version: " + PROGRAM_VERSION + "\n");
-
-	JarTools.initialise(this); 
-
-	GetOpt go = new GetOpt(args);
-
-	// Remember the GSDLOS value
-	client_operating_system = go.client_operating_system;
-
-	// If feedback is enabled, set up the recorder dialog
-	if (go.feedback_enabled) {
-	    // Use the default locale for now - this will be changed by the Gatherer run method
-	    feedback_enabled = true;
-	    feedback_dialog = new ActionRecorderDialog(Locale.getDefault());
-	}
-
-	// Are we using a remote Greenstone?
-	if (go.use_remote_greenstone) {
-	    isGsdlRemote = true;
-
-	    // We don't have a local Greenstone!
-	    go.gsdl3_path=null;
-	    go.gsdl3_src_path=null;
-
-	    // Don't set go.gsdl_path to null, since gdsl_path may still be set 
-	    // if we have a client-gli containing gs2build folder. 
-	    // However, keep track of whether we can download.
-	    if(go.gsdl_path == null) {
-		isDownloadEnabled = false;
-	    }
-
-	    // We have to use our own collect directory since we can't use the Greenstone one
-	    setCollectDirectoryPath(getGLIUserDirectoryPath() + "collect" + File.separator);
-	}
-	// We have a local Greenstone. OR we have a gs2build folder inside 
-	// the client-GLI folder (with which the Download panel becomes enabled) 
-	if(isDownloadEnabled) {
-	    LocalGreenstone.setDirectoryPath(go.gsdl_path);
-	}
-
-	// Users may specify a non-standard collect directory (eg. when running one GLI in a network environment)
-	if (go.collect_directory_path != null) {
-	    setCollectDirectoryPath(go.collect_directory_path);
-	}
-
-	// More special code for running with a remote Greenstone
-	if (isGsdlRemote) {
-	    if (go.fedora_info.isActive()) {
-		Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + "configRemote.xml";
-	    }
-	    else {
-		Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml";
-	    }
-
-	    Configuration.CONFIG_XML = "configRemote.xml"; 
-
-	    File collect_directory = new File(Gatherer.getCollectDirectoryPath());
-	    if (!collect_directory.exists() && !collect_directory.mkdir()) {
-		System.err.println("Warning: Unable to make directory: " + collect_directory);
-	    }
-	}
-	else {	    
-	    if (go.fedora_info.isActive()) {
-		Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + Configuration.CONFIG_XML;
-	    }
-	    // else, the CONFIG_XML uses the default config file, which is for the local GS server
-	}
-
-	init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path, 
-	     go.fedora_info,
-	     go.local_library_path, go.library_url_string, 
-	     go.gliserver_url_string, go.debug, go.perl_path, go.no_load, go.filename, go.site_name,
-	     go.servlet_path);
-    }
-
-
-    public void init(String gsdl_path, String gsdl3_path, String gsdl3_src_path, 
-		     FedoraInfo fedora_info,
-		     String local_library_path,
-		     String library_url_string, String gliserver_url_string, boolean debug_enabled,
-		     String perl_path, boolean no_load, String open_collection, 
-		     String site_name, String servlet_path) 
-    {
-	if (gsdl3_path != null && !gsdl3_path.equals("")) {
-	    this.GS3 = true;
-	} else {
-	    gsdl3_path = null;
-	    gsdl3_src_path = null;
-	}
-
-	// Create the debug stream if required
-	if (debug_enabled) {
-	    DebugStream.enableDebugging();
-
-	    Calendar now = Calendar.getInstance();
-	    String debug_file_path = "debug" + now.get(Calendar.DATE) + "-" + now.get(Calendar.MONTH) + "-" + now.get(Calendar.YEAR) + ".txt";
-
-	    // Debug file is created in the user's GLI directory
-	    debug_file_path = getGLIUserDirectoryPath() + debug_file_path;
-	    DebugStream.println("Debug file path: " + debug_file_path);
-	    DebugStream.setDebugFile(debug_file_path);
-	    DebugStream.print(System.getProperties());
-	}
-
-	// Delete plugins.dat and classifiers.dat files from previous versions of the GLI (no longer used)
-	File plugins_dat_file = new File(Gatherer.getGLIUserDirectoryPath() + "plugins.dat");
-	if (plugins_dat_file.exists()) {
-	    System.err.println("Deleting plugins.dat file...");
-	    Utility.delete(plugins_dat_file);
-	}
-	File classifiers_dat_file = new File(Gatherer.getGLIUserDirectoryPath() + "classifiers.dat");
-	if (classifiers_dat_file.exists()) {
-	    System.err.println("Deleting classifiers.dat file...");
-	    Utility.delete(classifiers_dat_file);
-	}
-
-	try {
-	    // Load GLI config file
-	    new Configuration(getGLIUserDirectoryPath(), gsdl_path, gsdl3_path, gsdl3_src_path, site_name,
-			      fedora_info);
-	    
-	    // Check we know where Perl is
-	    Configuration.perl_path = perl_path;
-	    if (isGsdlRemote && !isDownloadEnabled && Utility.isWindows() && Configuration.perl_path != null) {
-		if (Configuration.perl_path.toLowerCase().endsWith("perl.exe")) {
-		    Configuration.perl_path = Configuration.perl_path.substring(0, Configuration.perl_path.length() - "perl.exe".length());
-		}
-		if (Configuration.perl_path.endsWith(File.separator)) {
-		    Configuration.perl_path = Configuration.perl_path.substring(0, Configuration.perl_path.length() - File.separator.length());
-		}
-	    }
-
-	    // the feedback dialog has been loaded with a default locale, 
-	    // now set the user specified one
-	    if (feedback_enabled && feedback_dialog != null) {
-		feedback_dialog.setLocale(Configuration.getLocale("general.locale", true));
-	    }
-
-	    // Read Dictionary
-	    new Dictionary(Configuration.getLocale("general.locale", true), Configuration.getFont("general.font", true));
-
-	    // check that we are using Sun Java
-	    String java_vendor = System.getProperty("java.vendor");
-	    if (!java_vendor.equals("Sun Microsystems Inc.")) {
-		System.err.println(Dictionary.get("General.NotSunJava", java_vendor));
-	    }
-
-	    // Unless we're using remote building, we need to know where the local Greenstone is
-	    if (!isGsdlRemote && gsdl_path == null) {
-		missingGSDL();
-	    }
-
-	    if (fedora_info.isActive()) {
-		popupFedoraInfo();
-	    }
-		
-		// the no_load flag to GLI is processed at the end of handling open_collection_file_path
-		open_collection_file_path = open_collection;
-		if (open_collection_file_path == null) {
-			open_collection_file_path = Configuration.getString(
+	/** A public reference to the FileAssociationManager. */
+	static public FileAssociationManager assoc_man;
+	/** A public reference to the CollectionManager. */
+	static public CollectionManager c_man;
+	/** A public reference to the RecycleBin. */
+	static public RecycleBin recycle_bin;
+	/** a reference to the Servlet Configuration is GS3 */
+	static public ServletConfiguration servlet_config;
+	/** A public reference to the FileManager. */
+	static public FileManager f_man;
+	/** A public reference to the GUIManager. */
+	static public GUIManager g_man = null;
+	static private boolean g_man_built = false;
+
+	/** We are using the GLI for GS3 */
+	static public boolean GS3 = false;
+
+	static public boolean isApplet = false;
+	static public boolean isGsdlRemote = false;
+	static public boolean isLocalLibrary = false;
+
+	/* TODO: If we're using local GLI, collections are built locally. If we're using client-GLI
+	* and it contains a gs2build folder in it, then localBuild will also be true (if this is not
+	* turned off in Preferences). If we're remote and this is turned off in Prefs, build remotely. */
+	/*static public boolean buildingLocally = true;*/
+	/** If we're using local GLI, we can always download. If we're using client-GLI, we can only
+	* download if we have a gs2build folder inside it. And if we don't turn off downloadEnabling
+	* in the preferences.
+	*/
+	static public boolean isDownloadEnabled = true;
+
+	// feedback stuff
+	/** is the feedback feature enabled? */
+	static public boolean feedback_enabled = true;
+	/** the action recorder dialog */
+	static public ActionRecorderDialog feedback_dialog = null;
+
+	// Refresh reasons
+	static public final int COLLECTION_OPENED   = 0;
+	static public final int COLLECTION_CLOSED   = 1;
+	static public final int COLLECTION_REBUILT  = 2;
+	static public final int PREFERENCES_CHANGED = 3;
+
+	//////kk added////////  
+	static public String cgiBase="";
+	/////////////////
+
+	/** Magic to allow Enter to fire the default button. */
+	static {
+		KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
+		Keymap map = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
+		map.removeKeyStrokeBinding(enter);
+	}
+
+	static private URL default_gliserver_url=null;
+
+	public Gatherer(String[] args) 
+	{
+		// Display the version to make error reports a lot more useful
+		System.err.println("Version: " + PROGRAM_VERSION + "\n");
+
+		JarTools.initialise(this); 
+
+		GetOpt go = new GetOpt(args);
+
+		// Remember the GSDLOS value
+		client_operating_system = go.client_operating_system;
+
+		// If feedback is enabled, set up the recorder dialog
+		if (go.feedback_enabled) {
+			// Use the default locale for now - this will be changed by the Gatherer run method
+			feedback_enabled = true;
+			feedback_dialog = new ActionRecorderDialog(Locale.getDefault());
+		}
+
+		// Are we using a remote Greenstone?
+		if (go.use_remote_greenstone) {
+			isGsdlRemote = true;
+
+			// We don't have a local Greenstone!
+			go.gsdl3_path=null;
+			go.gsdl3_src_path=null;
+
+			// Don't set go.gsdl_path to null, since gdsl_path may still be set 
+			// if we have a client-gli containing gs2build folder. 
+			// However, keep track of whether we can download.
+			if(go.gsdl_path == null) {
+				isDownloadEnabled = false;
+			}
+
+			// We have to use our own collect directory since we can't use the Greenstone one
+			setCollectDirectoryPath(getGLIUserDirectoryPath() + "collect" + File.separator);
+		}
+		// We have a local Greenstone. OR we have a gs2build folder inside 
+		// the client-GLI folder (with which the Download panel becomes enabled) 
+		if(isDownloadEnabled) {
+			LocalGreenstone.setDirectoryPath(go.gsdl_path);
+		}
+
+		// Users may specify a non-standard collect directory (eg. when running one GLI in a network environment)
+		if (go.collect_directory_path != null) {
+			setCollectDirectoryPath(go.collect_directory_path);
+		}
+
+		// More special code for running with a remote Greenstone
+		if (isGsdlRemote) {
+			if (go.fedora_info.isActive()) {
+				Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + "configRemote.xml";
+			}
+			else {
+				Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml";
+			}
+
+			Configuration.CONFIG_XML = "configRemote.xml"; 
+
+			File collect_directory = new File(Gatherer.getCollectDirectoryPath());
+			if (!collect_directory.exists() && !collect_directory.mkdir()) {
+				System.err.println("Warning: Unable to make directory: " + collect_directory);
+			}
+		}
+		else {	    
+			if (go.fedora_info.isActive()) {
+				Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + Configuration.CONFIG_XML;
+			}
+			// else, the CONFIG_XML uses the default config file, which is for the local GS server
+		}
+
+		init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path, 
+		go.fedora_info,
+		go.local_library_path, go.library_url_string, 
+		go.gliserver_url_string, go.debug, go.perl_path, go.no_load, go.filename, go.site_name,
+		go.servlet_path);
+	}
+
+
+	public void init(String gsdl_path, String gsdl3_path, String gsdl3_src_path, 
+	FedoraInfo fedora_info,
+	String local_library_path,
+	String library_url_string, String gliserver_url_string, boolean debug_enabled,
+	String perl_path, boolean no_load, String open_collection, 
+	String site_name, String servlet_path) 
+	{
+		if (gsdl3_path != null && !gsdl3_path.equals("")) {
+			this.GS3 = true;
+		} else {
+			gsdl3_path = null;
+			gsdl3_src_path = null;
+		}
+
+		// Create the debug stream if required
+		if (debug_enabled) {
+			DebugStream.enableDebugging();
+
+			Calendar now = Calendar.getInstance();
+			String debug_file_path = "debug" + now.get(Calendar.DATE) + "-" + now.get(Calendar.MONTH) + "-" + now.get(Calendar.YEAR) + ".txt";
+
+			// Debug file is created in the user's GLI directory
+			debug_file_path = getGLIUserDirectoryPath() + debug_file_path;
+			DebugStream.println("Debug file path: " + debug_file_path);
+			DebugStream.setDebugFile(debug_file_path);
+			DebugStream.print(System.getProperties());
+		}
+
+		// Delete plugins.dat and classifiers.dat files from previous versions of the GLI (no longer used)
+		File plugins_dat_file = new File(Gatherer.getGLIUserDirectoryPath() + "plugins.dat");
+		if (plugins_dat_file.exists()) {
+			System.err.println("Deleting plugins.dat file...");
+			Utility.delete(plugins_dat_file);
+		}
+		File classifiers_dat_file = new File(Gatherer.getGLIUserDirectoryPath() + "classifiers.dat");
+		if (classifiers_dat_file.exists()) {
+			System.err.println("Deleting classifiers.dat file...");
+			Utility.delete(classifiers_dat_file);
+		}
+
+		try {
+			// Load GLI config file
+			new Configuration(getGLIUserDirectoryPath(), gsdl_path, gsdl3_path, gsdl3_src_path, site_name,
+			fedora_info);
+			
+			// Check we know where Perl is
+			Configuration.perl_path = perl_path;
+			if (isGsdlRemote && !isDownloadEnabled && Utility.isWindows() && Configuration.perl_path != null) {
+				if (Configuration.perl_path.toLowerCase().endsWith("perl.exe")) {
+					Configuration.perl_path = Configuration.perl_path.substring(0, Configuration.perl_path.length() - "perl.exe".length());
+				}
+				if (Configuration.perl_path.endsWith(File.separator)) {
+					Configuration.perl_path = Configuration.perl_path.substring(0, Configuration.perl_path.length() - File.separator.length());
+				}
+			}
+
+			// the feedback dialog has been loaded with a default locale, 
+			// now set the user specified one
+			if (feedback_enabled && feedback_dialog != null) {
+				feedback_dialog.setLocale(Configuration.getLocale("general.locale", true));
+			}
+
+			// Read Dictionary
+			new Dictionary(Configuration.getLocale("general.locale", true), Configuration.getFont("general.font", true));
+
+			// check that we are using Sun Java
+			String java_vendor = System.getProperty("java.vendor");
+			if (!java_vendor.equals("Sun Microsystems Inc.")) {
+				System.err.println(Dictionary.get("General.NotSunJava", java_vendor));
+			}
+
+			// Unless we're using remote building, we need to know where the local Greenstone is
+			if (!isGsdlRemote && gsdl_path == null) {
+				missingGSDL();
+			}
+
+			if (fedora_info.isActive()) {
+				popupFedoraInfo();
+			}
+			
+			// the no_load flag to GLI is processed at the end of handling open_collection_file_path
+			open_collection_file_path = open_collection;
+			if (open_collection_file_path == null) {
+				open_collection_file_path = Configuration.getString(
 				"general.open_collection"+Configuration.gliPropertyNameSuffix(), true);
-		}
-		
-		initCollectDirectoryPath(open_collection); 
-		
-		if (no_load || (isGsdlRemote && open_collection_file_path.equals(""))) {
-		open_collection_file_path = null;
-		}
-		
-	    // Finally, we're ready to find out the version of the remote Greenstone server 
-	    if(isGsdlRemote) {
-		// instantiate the RemoteGreenstoneServer object first
-		remoteGreenstoneServer = new RemoteGreenstoneServer();
-
-		// Set up proxy
-		setProxy();
-		// Now we set up an Authenticator
-		Authenticator.setDefault(new GAuthenticator());
-
-		int greenstoneVersion = 2;
-		requestGLIServerURL();
-		gliserver_url_string = Configuration.gliserver_url.toString();
-		
-		greenstoneVersion = remoteGreenstoneServer.getGreenstoneVersion();
-		// Display the version to make error reports a lot more useful
-		System.err.println("Remote Greenstone server version: " + greenstoneVersion);
-		if(greenstoneVersion == -1) { // remote server not running
-		    Gatherer.exit();
-		}
-		if(greenstoneVersion >= 3) {
-		    this.GS3 = true;
-		    Configuration.prepareForGS3();
-		} 
-		
-		if(fedora_info.isActive()) { 
-		    // when GS server is remote, FEDORA_HOME resides on the remote server side,
-		    // but we know the library URL from user-provided information
-		    library_url_string = fedora_info.getLibraryURL();
-		} else {
-		    library_url_string = remoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString());
-		}
-		// write it into the config file
-		Configuration.setString("general.library_url", true, library_url_string);
-	    }
-	    else { // local greenstone: Start up the local library server, if that's what we want
-		if (!GS3) {		
-		    isLocalLibrary = LocalLibraryServer.start(gsdl_path, local_library_path);
-		}
-		// else web library: GS server is local, but doesn't use the webserver included with GS2
-	    }
-	    
-	    // The "-library_url" option overwrites anything in the config files
-	    if (library_url_string != null && library_url_string.length() > 0) {
-		try {
-		    System.err.println("Setting library_url to " + library_url_string + "...");
-		    Configuration.library_url = new URL(library_url_string);
-		}
-		catch (MalformedURLException error) {
-		    DebugStream.printStackTrace(error);
-		}
-	    }
-  
-
-	    // Check that we now know the Greenstone library URL, since we need this for previewing collections
-	    // It is not necessary if an independent GSI was launched and the user hasn't pressed Enter Library yet
-	    DebugStream.println("Configuration.library_url = " + Configuration.library_url);
-	    if (Configuration.library_url == null) {
-		if(isLocalLibrary) {
-		    if(!LocalLibraryServer.isURLPending()) {
-			missingEXEC();
-		    }
-		    // else LocalLibraryServer is expecting a URL soon, so don't need to display the dialog
-		} else { // GS2 webLibrary or GS3 or remote Greenstone
-		    missingEXEC();
-		}
-	    }
-
-	    // The "-gliserver_url" option overwrites anything in the config files
-	    if (gliserver_url_string != null && gliserver_url_string.length() > 0) {
-		try {
-		    System.err.println("Setting gliserver_url to " + gliserver_url_string + "...");
-		    Configuration.gliserver_url = new URL(gliserver_url_string);
-		}
-		catch (MalformedURLException error) {
-		    DebugStream.printStackTrace(error);
-		}
-	    }
-
-	    // If we're using a remote Greenstone we need to know where the gliserver script is
-	    DebugStream.println("Configuration.gliserver_url = " + Configuration.gliserver_url);
-
-	    if (GS3) {
-		// Load Greenstone 3 servlet configuration
-		if (isGsdlRemote){
-		    servlet_config = new ServletConfiguration(Configuration.gli_user_directory_path);
-		}else{
-		    servlet_config= new ServletConfiguration(gsdl3_path);
-		}
-	    }
-
-	    if (GS3 && Configuration.servlet_path == null) {
-		Configuration.servlet_path = servlet_config.getServletPath(Configuration.site_name);
-	    }
-	     
-	    // ensure that a directory called 'cache' exists in the GLI user directory  
-	    File user_cache_dir = new File(Gatherer.getGLIUserCacheDirectoryPath());
-	    System.err.println("User cache dir: " + Gatherer.getGLIUserCacheDirectoryPath());
-	    if (!user_cache_dir.exists() && !user_cache_dir.mkdir()) {
-		System.err.println("Warning: Unable to make directory: " + user_cache_dir);
-	    }
-
-	    // Check for ImageMagick
-	    if (Gatherer.isGsdlRemote) {
-		DebugStream.println("Not checking for ImageMagick.");
-	    }
-	    else if (!(new ImageMagickTest()).found()) {
-		// Time for a warning message
-		missingImageMagick();
-	    }
-
-	    if (Gatherer.isGsdlRemote) {
-		DebugStream.println("Not checking for perl path/exe");
-	    }
-	    else {
-		// Perl path is a little different as it is perfectly ok to
-		// start the GLI without providing a perl path
-		boolean found_perl = false;
-		if (Configuration.perl_path != null) {
-		    // See if the file pointed to actually exists
-		    File perl_file = new File(Configuration.perl_path);
-		    found_perl = perl_file.exists();
-		    perl_file = null;
-		}
-		if (Configuration.perl_path == null || !found_perl) {
-		    // Run test to see if we can run perl as is.
-		    PerlTest perl_test = new PerlTest();
-		    if (perl_test.found()) {
-			// If so replace the perl path with the system
-			// default (or null for unix).
-			Configuration.perl_path = perl_test.toString();
-			found_perl = true;
-		    }
-		}
-		if (!found_perl) {
-		    // Time for an error message.
-		    missingPERL();
-		}
-	    }
-
-		// Check that the local can support multiple filename encodings
+			}
+			
+			initCollectDirectoryPath(open_collection); 
+			
+			if (no_load || (isGsdlRemote && open_collection_file_path.equals(""))) {
+				open_collection_file_path = null;
+			}
+			
+			// Finally, we're ready to find out the version of the remote Greenstone server 
+			if(isGsdlRemote) {
+				// instantiate the RemoteGreenstoneServer object first
+				remoteGreenstoneServer = new RemoteGreenstoneServer();
+
+				// Set up proxy
+				setProxy();
+				// Now we set up an Authenticator
+				Authenticator.setDefault(new GAuthenticator());
+
+				int greenstoneVersion = 2;
+				requestGLIServerURL();
+				gliserver_url_string = Configuration.gliserver_url.toString();
+				
+				greenstoneVersion = remoteGreenstoneServer.getGreenstoneVersion();
+				// Display the version to make error reports a lot more useful
+				System.err.println("Remote Greenstone server version: " + greenstoneVersion);
+				if(greenstoneVersion == -1) { // remote server not running
+					Gatherer.exit();
+				}
+				if(greenstoneVersion >= 3) {
+					this.GS3 = true;
+					Configuration.prepareForGS3();
+				} 
+				
+				if(fedora_info.isActive()) { 
+					// when GS server is remote, FEDORA_HOME resides on the remote server side,
+					// but we know the library URL from user-provided information
+					library_url_string = fedora_info.getLibraryURL();
+				} else {
+					library_url_string = remoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString());
+				}
+				// write it into the config file
+				Configuration.setString("general.library_url", true, library_url_string);
+			}
+			else { // local greenstone: Start up the local library server, if that's what we want
+				if (!GS3) {		
+					isLocalLibrary = LocalLibraryServer.start(gsdl_path, local_library_path);
+				}
+				else {
+					GS3ServerThread thread = new GS3ServerThread(gsdl_path);
+					thread.start();
+				}
+				// else web library: GS server is local, but doesn't use the webserver included with GS2
+			}
+			
+			// The "-library_url" option overwrites anything in the config files
+			if (library_url_string != null && library_url_string.length() > 0) {
+				try {
+					System.err.println("Setting library_url to " + library_url_string + "...");
+					Configuration.library_url = new URL(library_url_string);
+				}
+				catch (MalformedURLException error) {
+					DebugStream.printStackTrace(error);
+				}
+			}
+
+
+			// Check that we now know the Greenstone library URL, since we need this for previewing collections
+			// It is not necessary if an independent GSI was launched and the user hasn't pressed Enter Library yet
+			DebugStream.println("Configuration.library_url = " + Configuration.library_url);
+			if (Configuration.library_url == null) {
+				if(isLocalLibrary) {
+					if(!LocalLibraryServer.isURLPending()) {
+						missingEXEC();
+					}
+					// else LocalLibraryServer is expecting a URL soon, so don't need to display the dialog
+				} else { // GS2 webLibrary or GS3 or remote Greenstone
+					missingEXEC();
+				}
+			}
+
+			// The "-gliserver_url" option overwrites anything in the config files
+			if (gliserver_url_string != null && gliserver_url_string.length() > 0) {
+				try {
+					System.err.println("Setting gliserver_url to " + gliserver_url_string + "...");
+					Configuration.gliserver_url = new URL(gliserver_url_string);
+				}
+				catch (MalformedURLException error) {
+					DebugStream.printStackTrace(error);
+				}
+			}
+
+			// If we're using a remote Greenstone we need to know where the gliserver script is
+			DebugStream.println("Configuration.gliserver_url = " + Configuration.gliserver_url);
+
+			if (GS3) {
+				// Load Greenstone 3 servlet configuration
+				if (isGsdlRemote){
+					servlet_config = new ServletConfiguration(Configuration.gli_user_directory_path);
+				}else{
+					servlet_config= new ServletConfiguration(gsdl3_path);
+				}
+			}
+
+			if (GS3 && Configuration.servlet_path == null) {
+				Configuration.servlet_path = servlet_config.getServletPath(Configuration.site_name);
+			}
+			
+			// ensure that a directory called 'cache' exists in the GLI user directory  
+			File user_cache_dir = new File(Gatherer.getGLIUserCacheDirectoryPath());
+			System.err.println("User cache dir: " + Gatherer.getGLIUserCacheDirectoryPath());
+			if (!user_cache_dir.exists() && !user_cache_dir.mkdir()) {
+				System.err.println("Warning: Unable to make directory: " + user_cache_dir);
+			}
+
+			// Check for ImageMagick
+			if (Gatherer.isGsdlRemote) {
+				DebugStream.println("Not checking for ImageMagick.");
+			}
+			else if (!(new ImageMagickTest()).found()) {
+				// Time for a warning message
+				missingImageMagick();
+			}
+
+			if (Gatherer.isGsdlRemote) {
+				DebugStream.println("Not checking for perl path/exe");
+			}
+			else {
+				// Perl path is a little different as it is perfectly ok to
+				// start the GLI without providing a perl path
+				boolean found_perl = false;
+				if (Configuration.perl_path != null) {
+					// See if the file pointed to actually exists
+					File perl_file = new File(Configuration.perl_path);
+					found_perl = perl_file.exists();
+					perl_file = null;
+				}
+				if (Configuration.perl_path == null || !found_perl) {
+					// Run test to see if we can run perl as is.
+					PerlTest perl_test = new PerlTest();
+					if (perl_test.found()) {
+						// If so replace the perl path with the system
+						// default (or null for unix).
+						Configuration.perl_path = perl_test.toString();
+						found_perl = true;
+					}
+				}
+				if (!found_perl) {
+					// Time for an error message.
+					missingPERL();
+				}
+			}
+
+			// Check that the local can support multiple filename encodings
 			//System.err.println("#### Java identifies current Locale as (file.encoding): "
 			//	+ System.getProperty("file.encoding"));
-	    if(System.getProperty("file.encoding").equals("UTF-8")){
-			// If the locale is UTF-8, Java will interpret all filename bytes as UTF-8, 
-			// which is a destructive process as it will convert characters not recognised
-			// by UTF-8 into the invalid character, rather than preserving the bytecodes.
-			// This has the effect that non-UTF8 encoded filenames on a system set to a 
-			// UTF-8 locale are not 'seen' by Java (if they contain non-ASCII characters).
-			multipleFilenameEncodingsNotSupported();		
-			FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED = false; 
-			FilenameEncoding.URL_FILE_SEPARATOR = File.separator;
-	    } else {
-			FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED = true;
-			FilenameEncoding.URL_FILE_SEPARATOR = "/"; // URL file separator is always "/" 
-	    }
-		
-	    // Set the default font for all Swing components.
-	    FontUIResource default_font = Configuration.getFont("general.font", true);
-	    Enumeration keys = UIManager.getDefaults().keys();
-	    while (keys.hasMoreElements()) {
-		Object key = keys.nextElement();
-		Object value = UIManager.get(key);
-		if (value instanceof FontUIResource) {
-		    UIManager.put(key, default_font);
-		}
-	    }
-
-	    // At this point (which is where this code originally used to be), we can set up the proxy for the
-	    // non-remote case. The remote Greenstone server would already have setup its proxy when required.
-	    if(!isGsdlRemote) {
-		setProxy();
-		// Now we set up an Authenticator
-		Authenticator.setDefault(new GAuthenticator());
-	    }
-	    assoc_man = new FileAssociationManager();
-	    // Create File Manager
-	    f_man = new FileManager();
-	    // Create Collection Manager
-	    c_man = new CollectionManager();
-	    // Create Recycle Bin
-	    recycle_bin = new RecycleBin();
-
-	    if (GS3) {
-		if (site_name==null) {
-		    site_name = Configuration.site_name;
-		    servlet_path = null; // need to reset this
-		}
-		if (servlet_path == null) {
-		    servlet_path = Configuration.getServletPath();
-		}
-	    }
-	    
-		
-	} catch (Exception exception) {
-	    DebugStream.printStackTrace(exception);
+			if(System.getProperty("file.encoding").equals("UTF-8")){
+				// If the locale is UTF-8, Java will interpret all filename bytes as UTF-8, 
+				// which is a destructive process as it will convert characters not recognised
+				// by UTF-8 into the invalid character, rather than preserving the bytecodes.
+				// This has the effect that non-UTF8 encoded filenames on a system set to a 
+				// UTF-8 locale are not 'seen' by Java (if they contain non-ASCII characters).
+				multipleFilenameEncodingsNotSupported();		
+				FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED = false; 
+				FilenameEncoding.URL_FILE_SEPARATOR = File.separator;
+			} else {
+				FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED = true;
+				FilenameEncoding.URL_FILE_SEPARATOR = "/"; // URL file separator is always "/" 
+			}
+			
+			// Set the default font for all Swing components.
+			FontUIResource default_font = Configuration.getFont("general.font", true);
+			Enumeration keys = UIManager.getDefaults().keys();
+			while (keys.hasMoreElements()) {
+				Object key = keys.nextElement();
+				Object value = UIManager.get(key);
+				if (value instanceof FontUIResource) {
+					UIManager.put(key, default_font);
+				}
+			}
+
+			// At this point (which is where this code originally used to be), we can set up the proxy for the
+			// non-remote case. The remote Greenstone server would already have setup its proxy when required.
+			if(!isGsdlRemote) {
+				setProxy();
+				// Now we set up an Authenticator
+				Authenticator.setDefault(new GAuthenticator());
+			}
+			assoc_man = new FileAssociationManager();
+			// Create File Manager
+			f_man = new FileManager();
+			// Create Collection Manager
+			c_man = new CollectionManager();
+			// Create Recycle Bin
+			recycle_bin = new RecycleBin();
+
+			if (GS3) {
+				if (site_name==null) {
+					site_name = Configuration.site_name;
+					servlet_path = null; // need to reset this
+				}
+				if (servlet_path == null) {
+					servlet_path = Configuration.getServletPath();
+				}
+			}
+			
+			
+		} catch (Exception exception) {
+			DebugStream.printStackTrace(exception);
+		}
+
+		
+		// Create GUI Manager (last) or else suffer the death of a thousand NPE's
+		g_man = new GUIManager(size);
+
+		// Get a list of the core Greenstone classifiers and plugins
+		Classifiers.loadClassifiersList(null);
+		Plugins.loadPluginsList(null);
+
+		// If using a remote Greenstone we need to download the collection configurations now
+		if (Gatherer.isGsdlRemote) {
+			if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
+				// !! Something went wrong downloading the collection configurations
+				System.err.println("Error: Could not download collection configurations.");
+				if(!Gatherer.isApplet) { // don't close the browser if it is an applet!
+					System.exit(0);
+				}
+			}
+		}
 	}
 
 	
-	// Create GUI Manager (last) or else suffer the death of a thousand NPE's
-	g_man = new GUIManager(size);
-
-	// Get a list of the core Greenstone classifiers and plugins
-	Classifiers.loadClassifiersList(null);
+	/** Returns the correct version of the (local or remote) Greenstone server if init() has already been called. */
+	public static int serverVersionNumber() { 
+		return GS3 ? 3 : 2;
+	} 
+
+	/** Returns "Server: version number" if init() has already been called. */
+	public static String getServerVersionAsString() { 
+		return "Server: v" + serverVersionNumber();
+	} 
+
+	public void openGUI()
+	{
+		// Size and place the frame on the screen
+		Rectangle bounds = Configuration.getBounds("general.bounds", true);
+		if (bounds == null) {
+			// Choose a sensible default value
+			bounds = new Rectangle(0, 0, 640, 480);
+		}
+		
+		// Ensure width and height are reasonable
+		size = bounds.getSize();
+		if (size.width < 640) {
+			size.width = 640;
+		}
+		else if (size.width > Configuration.screen_size.width && Configuration.screen_size.width > 0) {
+			size.width = Configuration.screen_size.width;
+		}
+		if (size.height < 480) {
+			size.height = 480;
+		}
+		else if (size.height > Configuration.screen_size.height && Configuration.screen_size.height > 0) {
+			size.height = Configuration.screen_size.height;
+		}
+
+		if (!g_man_built) {
+
+			g_man.display();
+
+			// Place the window in the desired location on the screen, if this is do-able (not under most linux window managers apparently. In fact you're lucky if they listen to any of your screen size requests).
+			g_man.setLocation(bounds.x, bounds.y);
+			g_man.setVisible(true);
+
+			// After the window has been made visible, check that it is in the correct place
+			// sometimes java places a window not in the correct place, 
+			// but with an offset. If so, we work out what the offset is
+			// and change the desired location to take that into account 
+			Point location = g_man.getLocation();
+			int x_offset = bounds.x - location.x;
+			int y_offset = bounds.y - location.y;
+			// If not, offset the window to move it into the correct location
+			if (x_offset > 0 || y_offset > 0) {
+				///ystem.err.println("changing the location to "+(bounds.x + x_offset)+" "+ (bounds.y + y_offset));
+				g_man.setLocation(bounds.x + x_offset, bounds.y + y_offset);
+			}
+
+			// The 'after-display' triggers several events which don't occur until after the visual components are actually available on screen. Examples of these would be the various html renderings, as they can't happen offscreen.
+			g_man.afterDisplay();
+			g_man_built = true;
+		}
+		else {
+			g_man.setVisible(true);
+		}
+
+		// Get a list of the core Greenstone classifiers and plugins
+		/*Classifiers.loadClassifiersList(null);
 	Plugins.loadPluginsList(null);
 
 	// If using a remote Greenstone we need to download the collection configurations now
 	if (Gatherer.isGsdlRemote) {
-	    if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
-		// !! Something went wrong downloading the collection configurations
-		System.err.println("Error: Could not download collection configurations.");
-		if(!Gatherer.isApplet) { // don't close the browser if it is an applet!
-		    System.exit(0);
-		}
-	    }
-	}
-    }
-
-    
-    /** Returns the correct version of the (local or remote) Greenstone server if init() has already been called. */
-    public static int serverVersionNumber() { 
-	return GS3 ? 3 : 2;
-    } 
-
-    /** Returns "Server: version number" if init() has already been called. */
-    public static String getServerVersionAsString() { 
-	return "Server: v" + serverVersionNumber();
-    } 
-
-    public void openGUI()
-    {
-	// Size and place the frame on the screen
-	Rectangle bounds = Configuration.getBounds("general.bounds", true);
-	if (bounds == null) {
-	    // Choose a sensible default value
-	    bounds = new Rectangle(0, 0, 640, 480);
-	}
-	
-	// Ensure width and height are reasonable
-	size = bounds.getSize();
-	if (size.width < 640) {
-	    size.width = 640;
-	}
-	else if (size.width > Configuration.screen_size.width && Configuration.screen_size.width > 0) {
-	    size.width = Configuration.screen_size.width;
-	}
-	if (size.height < 480) {
-	    size.height = 480;
-	}
-	else if (size.height > Configuration.screen_size.height && Configuration.screen_size.height > 0) {
-	    size.height = Configuration.screen_size.height;
-	}
-
-	if (!g_man_built) {
-
-	    g_man.display();
-
-	    // Place the window in the desired location on the screen, if this is do-able (not under most linux window managers apparently. In fact you're lucky if they listen to any of your screen size requests).
-	    g_man.setLocation(bounds.x, bounds.y);
-	    g_man.setVisible(true);
-
-	    // After the window has been made visible, check that it is in the correct place
-	    // sometimes java places a window not in the correct place, 
-	    // but with an offset. If so, we work out what the offset is
-	    // and change the desired location to take that into account 
-	    Point location = g_man.getLocation();
-	    int x_offset = bounds.x - location.x;
-	    int y_offset = bounds.y - location.y;
-	    // If not, offset the window to move it into the correct location
-	    if (x_offset > 0 || y_offset > 0) {
-		///ystem.err.println("changing the location to "+(bounds.x + x_offset)+" "+ (bounds.y + y_offset));
-		g_man.setLocation(bounds.x + x_offset, bounds.y + y_offset);
-	    }
-
-	    // The 'after-display' triggers several events which don't occur until after the visual components are actually available on screen. Examples of these would be the various html renderings, as they can't happen offscreen.
-	    g_man.afterDisplay();
-	    g_man_built = true;
-	}
-	else {
-	    g_man.setVisible(true);
-	}
-
-	// Get a list of the core Greenstone classifiers and plugins
-	/*Classifiers.loadClassifiersList(null);
-	Plugins.loadPluginsList(null);
-
-	// If using a remote Greenstone we need to download the collection configurations now
-	if (Gatherer.isGsdlRemote) {
-	    if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
+		if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
 		// !! Something went wrong downloading the collection configurations
 		System.err.println("Error: Could not download collection configurations.");
 		System.exit(0);
-	    }
+		}
 	}*/
 
-	// If there was a collection left open last time, reopen it	
-	 if (open_collection_file_path == null || new File(Gatherer.open_collection_file_path).isDirectory()) {
-      
-      //the menu bar items, file and edit, are disabled from the moment of their creation. if there is no left-over collection from the last session, enable them; otherwise it is untill the collection finishes loading, will they be enabled in collectionManager.java
-	  setMenuBarEnabled(true);
-      } else {
-  
-      // If there was a collection left open last time, reopen it
-	  c_man.openCollectionFromLastTime();
-      }
-    }
-
-    public static void setMenuBarEnabled(boolean enabled) {
-      g_man.menu_bar.file.setEnabled(enabled);
-      g_man.menu_bar.edit.setEnabled(enabled);
-    }
-
-    /** Exits the Gatherer after ensuring that things needing saving are saved.
-     * @see java.io.FileOutputStream
-     * @see java.io.PrintStream
-     * @see java.lang.Exception
-     * @see javax.swing.JOptionPane
-     * @see org.greenstone.gatherer.Configuration
-     * @see org.greenstone.gatherer.collection.CollectionManager
-     * @see org.greenstone.gatherer.gui.GUIManager
-     */
-    static public void exit(int new_exit_status)
-    {
-	DebugStream.println("In Gatherer.exit()...");
-	exit = true;
-	if (new_exit_status != 0) {
-	    // default exit_status is already 0 
-	    // only remember a new exit status if it is non-trivial
-	    exit_status = new_exit_status;
-	}
-
-	// Save the file associations
-	if (assoc_man != null) {
-	    assoc_man.save();
-	    assoc_man = null;
-	}
-
-	// Get the gui to deallocate
-	if(g_man != null) {
-	    g_man.destroy();
-	    g_man_built = false;
-	}
-
-	// Flush debug
-	DebugStream.closeDebugStream();
-	
-	// If we started a server, we should try to stop it.
-	if (LocalLibraryServer.isRunning() == true) {		
-	    LocalLibraryServer.stop();
-	}
-
-	// If we're using a remote Greenstone server we need to make sure that all jobs have completed first
-	if (isGsdlRemote) {
-	    remoteGreenstoneServer.exit();
-	}
-
-	// Make sure we haven't started up any processes that are still running
-	if (apps.size() == 0) {
-	    // If we're running as an applet we don't actually quit (just hide the main GLI window)
-	    if (!Gatherer.isApplet) {
-		// This is the end...
-		System.exit(exit_status);
-	    }
-	}
-	else {
-	    JOptionPane.showMessageDialog(g_man, Dictionary.get("General.Outstanding_Processes"), Dictionary.get("General.Outstanding_Processes_Title"), JOptionPane.ERROR_MESSAGE);
-	    g_man.setVisible(false);
-	}
-    }
-
-    static public void exit()
-    {
-	exit(0);
-    }
-
-    /** Returns the path of the current collect directory. */
-    static public String getCollectDirectoryPath()
-    {
-	if (non_standard_collect_directory_path != null) {
-	    return non_standard_collect_directory_path;
-	}
-	
-	return getDefaultGSCollectDirectoryPath(true); // file separator appended
-	
-    }
+		// If there was a collection left open last time, reopen it	
+		if (open_collection_file_path == null || new File(Gatherer.open_collection_file_path).isDirectory()) {
+			
+			//the menu bar items, file and edit, are disabled from the moment of their creation. if there is no left-over collection from the last session, enable them; otherwise it is untill the collection finishes loading, will they be enabled in collectionManager.java
+			setMenuBarEnabled(true);
+		} else {
+
+			// If there was a collection left open last time, reopen it
+			c_man.openCollectionFromLastTime();
+		}
+	}
+
+	public static void setMenuBarEnabled(boolean enabled) {
+		g_man.menu_bar.file.setEnabled(enabled);
+		g_man.menu_bar.edit.setEnabled(enabled);
+	}
+
+	/** Exits the Gatherer after ensuring that things needing saving are saved.
+	* @see java.io.FileOutputStream
+	* @see java.io.PrintStream
+	* @see java.lang.Exception
+	* @see javax.swing.JOptionPane
+	* @see org.greenstone.gatherer.Configuration
+	* @see org.greenstone.gatherer.collection.CollectionManager
+	* @see org.greenstone.gatherer.gui.GUIManager
+	*/
+	static public void exit(int new_exit_status)
+	{
+		DebugStream.println("In Gatherer.exit()...");
+		exit = true;
+		if (new_exit_status != 0) {
+			// default exit_status is already 0 
+			// only remember a new exit status if it is non-trivial
+			exit_status = new_exit_status;
+		}
+
+		// Save the file associations
+		if (assoc_man != null) {
+			assoc_man.save();
+			assoc_man = null;
+		}
+
+		// Get the gui to deallocate
+		if(g_man != null) {
+			g_man.destroy();
+			g_man_built = false;
+		}
+
+		// Flush debug
+		DebugStream.closeDebugStream();
+		
+		// If we started a server, we should try to stop it.
+		if (LocalLibraryServer.isRunning() == true) {		
+			LocalLibraryServer.stop();
+		}
+
+		// If we're using a remote Greenstone server we need to make sure that all jobs have completed first
+		if (isGsdlRemote) {
+			remoteGreenstoneServer.exit();
+		}
+
+		// Make sure we haven't started up any processes that are still running
+		if (apps.size() == 0) {
+			// If we're running as an applet we don't actually quit (just hide the main GLI window)
+			if (!Gatherer.isApplet) {
+				// This is the end...
+				System.exit(exit_status);
+			}
+		}
+		else {
+			JOptionPane.showMessageDialog(g_man, Dictionary.get("General.Outstanding_Processes"), Dictionary.get("General.Outstanding_Processes_Title"), JOptionPane.ERROR_MESSAGE);
+			g_man.setVisible(false);
+		}
+	}
+
+	static public void exit()
+	{
+		exit(0);
+	}
+
+	/** Returns the path of the current collect directory. */
+	static public String getCollectDirectoryPath()
+	{
+		if (non_standard_collect_directory_path != null) {
+			return non_standard_collect_directory_path;
+		}
+		
+		return getDefaultGSCollectDirectoryPath(true); // file separator appended
+		
+	}
 	
 	// if we need to know whether the local server we are running is server.exe vs apache web server
@@ -724,5 +728,5 @@
 
 	/** Returns the path of the Greenstone "collect" directory. */
-    static public String getDefaultGSCollectDirectoryPath(boolean appendSeparator) {
+	static public String getDefaultGSCollectDirectoryPath(boolean appendSeparator) {
 		String colDir;
 		if (GS3) {
@@ -730,5 +734,5 @@
 		}
 		else {
-		    colDir = Configuration.gsdl_path + "collect";
+			colDir = Configuration.gsdl_path + "collect";
 		}
 		
@@ -739,70 +743,70 @@
 	}	
 
-    /** Returns the path of the GLI directory. */
-    static public String getGLIDirectoryPath()
-    {
-	return gli_directory_path;
-    }
-
-
-    /** Returns the path of the GLI "metadata" directory. */
-    static public String getGLIMetadataDirectoryPath()
-    {
-	return getGLIDirectoryPath() + "metadata" + File.separator;
-    }
-
-
-    /** Returns the path of the GLI user directory. */
-    static public String getGLIUserDirectoryPath()
-    {
-	return gli_user_directory_path;
-    }
-
-
-    /** Returns the path of the GLI user "cache" directory. */
-    static public String getGLIUserCacheDirectoryPath()
-    {
-	return getGLIUserDirectoryPath() + "cache" + File.separator;
-    }
-
-
-    /** Returns the path of the GLI user "log" directory. */
-    static public String getGLIUserLogDirectoryPath()
-    {
-	return getGLIUserDirectoryPath() + "log" + File.separator;
-    }
-
-
-    static public String getSitesDirectoryPath()
-    {
-	return Configuration.gsdl3_path + "sites" + File.separator;
-    }
-
-
-    static public void setCollectDirectoryPath(String collect_directory_path)
-    {
-	non_standard_collect_directory_path = collect_directory_path;
-	if (!non_standard_collect_directory_path.endsWith(File.separator)) {
-	    non_standard_collect_directory_path = non_standard_collect_directory_path + File.separator;
-	}
-    }
-
-
-    static public void setGLIDirectoryPath(String gli_directory_path_arg)
-    {
-	gli_directory_path = gli_directory_path_arg;
-    }
-
-
-    static public void setGLIUserDirectoryPath(String gli_user_directory_path_arg)
-    {
-	gli_user_directory_path = gli_user_directory_path_arg;
-
-	// Ensure the GLI user directory exists
-	File gli_user_directory = new File(gli_user_directory_path);
-	if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
-	    System.err.println("Error: Unable to make directory: " + gli_user_directory);
-	}
-    }
+	/** Returns the path of the GLI directory. */
+	static public String getGLIDirectoryPath()
+	{
+		return gli_directory_path;
+	}
+
+
+	/** Returns the path of the GLI "metadata" directory. */
+	static public String getGLIMetadataDirectoryPath()
+	{
+		return getGLIDirectoryPath() + "metadata" + File.separator;
+	}
+
+
+	/** Returns the path of the GLI user directory. */
+	static public String getGLIUserDirectoryPath()
+	{
+		return gli_user_directory_path;
+	}
+
+
+	/** Returns the path of the GLI user "cache" directory. */
+	static public String getGLIUserCacheDirectoryPath()
+	{
+		return getGLIUserDirectoryPath() + "cache" + File.separator;
+	}
+
+
+	/** Returns the path of the GLI user "log" directory. */
+	static public String getGLIUserLogDirectoryPath()
+	{
+		return getGLIUserDirectoryPath() + "log" + File.separator;
+	}
+
+
+	static public String getSitesDirectoryPath()
+	{
+		return Configuration.gsdl3_path + "sites" + File.separator;
+	}
+
+
+	static public void setCollectDirectoryPath(String collect_directory_path)
+	{
+		non_standard_collect_directory_path = collect_directory_path;
+		if (!non_standard_collect_directory_path.endsWith(File.separator)) {
+			non_standard_collect_directory_path = non_standard_collect_directory_path + File.separator;
+		}
+	}
+
+
+	static public void setGLIDirectoryPath(String gli_directory_path_arg)
+	{
+		gli_directory_path = gli_directory_path_arg;
+	}
+
+
+	static public void setGLIUserDirectoryPath(String gli_user_directory_path_arg)
+	{
+		gli_user_directory_path = gli_user_directory_path_arg;
+
+		// Ensure the GLI user directory exists
+		File gli_user_directory = new File(gli_user_directory_path);
+		if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
+			System.err.println("Error: Unable to make directory: " + gli_user_directory);
+		}
+	}
 
 
@@ -811,6 +815,6 @@
 		String coldir = defaultColdir;
 		// If local GS and opening a collection outside the standard GS collect folder,
-	    // need to open the non-standard collect folder that the collection resides in
-	    if (!isGsdlRemote 
+		// need to open the non-standard collect folder that the collection resides in
+		if (!isGsdlRemote 
 				&& !open_collection_file_path.startsWith(defaultColdir))
 		{
@@ -819,16 +823,16 @@
 			if(!open_collection_file_path.equals("")) {			
 				if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
-				    collectFolder = new File(open_collection_file_path);
+					collectFolder = new File(open_collection_file_path);
 				} else {
-				    // the filepath is a gli.col file. To get the collect folder: the 1st level up
-				    // is the collection folder, 2 two levels up is the containing collect folder
-				    collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
+					// the filepath is a gli.col file. To get the collect folder: the 1st level up
+					// is the collection folder, 2 two levels up is the containing collect folder
+					collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
 				}	
-			
+				
 				// Need to deal with colgroups as well: while there's an etc/collect.cfg
 				// in the current collectFolder, move one level up
 				String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
 				if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
-				    collectFolder = collectFolder.getParentFile();		    
+					collectFolder = collectFolder.getParentFile();		    
 				}
 			}		
@@ -855,31 +859,31 @@
 			if(coldir.equals(defaultColdir)) {				
 				gsdlsite_collecthome = Utility.updatePropertyConfigFile(
-					gsdlsitecfg, "collecthome", null);						
+				gsdlsitecfg, "collecthome", null);						
 			} else {
 				gsdlsite_collecthome = Utility.updatePropertyConfigFile(
-					gsdlsitecfg, "collecthome", coldir); // no file separator
-					// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
+				gsdlsitecfg, "collecthome", coldir); // no file separator
+				// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
 			}
 		}		
 	}
-   
-    /** depending on the version of GS being run, return the path to the current GS' installation's gsdl(3)site.cfg */
-    public static String getGsdlSiteConfigFile() {
+
+	/** depending on the version of GS being run, return the path to the current GS' installation's gsdl(3)site.cfg */
+	public static String getGsdlSiteConfigFile() {
 		if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
 			return Configuration.gsdl3_path + File.separator + "WEB-INF" 
-				+ File.separator + "cgi" + File.separator + "gsdl3site.cfg";
+			+ File.separator + "cgi" + File.separator + "gsdl3site.cfg";
 		} else { // cgi-bin/gsdlsite.cfg
 			return Configuration.gsdl_path /* + File.separator */
-				+ "cgi-bin" + File.separator + "gsdlsite.cfg";
-		}
-    }
-
-    public static void collectDirectoryHasChanged(
-		String oldCollectPath, String newCollectPath, final Component container) 
+			+ "cgi-bin" + File.separator + "gsdlsite.cfg";
+		}
+	}
+
+	public static void collectDirectoryHasChanged(
+	String oldCollectPath, String newCollectPath, final Component container) 
 	{ 	
 		if(oldCollectPath.equals(newCollectPath)) {
 			return; // nothing to be done
 		}
-	
+		
 		// Will use a busy cursor if the process of changing the collect directory takes more 
 		// than half a second/500ms. See http://www.catalysoft.com/articles/busyCursor.html
@@ -895,8 +899,8 @@
 		try {
 			timer.schedule(timerTask, 500);
-		
+			
 			// first save any open collection in the old location, then close it
 			if(Gatherer.c_man.getCollection() != null) {
-			    Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
+				Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
 			}
 			
@@ -904,8 +908,8 @@
 			if(newCollectPath.equals(getDefaultGSCollectDirectoryPath(true))) {
 				Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), 
-						true, "");
+				true, "");
 			} else {
 				Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), 
-						true, newCollectPath);
+				true, newCollectPath);
 			}
 			Gatherer.setCollectDirectoryPath(newCollectPath);
@@ -922,5 +926,5 @@
 			// This method does nothing for a remote Greenstone.	
 			if(Gatherer.isGsdlRemote) {
-			    return;
+				return;
 			}	
 			
@@ -930,12 +934,12 @@
 			collectDir = collectDir.substring(0, collectDir.length()-1); // remove file separator at end	
 			Utility.updatePropertyConfigFile(getGsdlSiteConfigFile(), "collecthome", collectDir);
-					// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
+			// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
 			
 			if(!Gatherer.GS3 && Gatherer.isLocalLibrary) {
-			    // for Images in the collection to work, the apache web server 
-			    // configuration's COLLECTHOME should be updated on collectdir change. 
-			    // Does nothing for server.exe at the moment
-
-			    LocalLibraryServer.reconfigure();
+				// for Images in the collection to work, the apache web server 
+				// configuration's COLLECTHOME should be updated on collectdir change. 
+				// Does nothing for server.exe at the moment
+
+				LocalLibraryServer.reconfigure();
 			}
 		} finally { // Note try-finally section without catch:
@@ -951,608 +955,640 @@
 			container.setCursor(originalCursor);
 		}
-    }
-
-
-    static public void refresh(int refresh_reason)
-    {
-	if (g_man != null) {
-
-	    g_man.refresh(refresh_reason, c_man.ready());
-	}
-
-	// Now is a good time to force a garbage collect
-	System.gc();
-    }
-
-
-    // used to send reload coll messages to the tomcat server
-    static public void configGS3Server(String site, String command) {
-	if (Configuration.library_url == null){
-	    System.out.println("Error: you have not provided the Greenstone Library address.");  
-           return;
-
-	} 
-          
-	try {
-	    // need to add the servlet name to the exec address
-	    String raw_url = Configuration.library_url.toString() + Configuration.getServletPath() + command;
-	    URL url = new URL(raw_url);
-	    DebugStream.println("Action: " + raw_url);
-	    HttpURLConnection library_connection = (HttpURLConnection) url.openConnection();
-	    int response_code = library_connection.getResponseCode();
-	    if(HttpURLConnection.HTTP_OK <= response_code && response_code < HttpURLConnection.HTTP_MULT_CHOICE) {
-		DebugStream.println("200 - Complete.");
-	    }
-	    else {
-		DebugStream.println("404 - Failed.");
-	    }
-	    url = null;
-	}
-	catch(java.net.ConnectException connectException) {
-	    JOptionPane.showMessageDialog(g_man, Dictionary.get("Preferences.Connection.Library_Path_Connection_Failure", Configuration.library_url.toString()), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
-	    DebugStream.println(connectException.getMessage());
-	}
-	catch (Exception exception) {            
-	    DebugStream.printStackTrace(exception);
-	}
-    }
-
-
-    /** Used to 'spawn' a new child application when a file is double clicked.
-     * @param file The file to open 
-     * @see org.greenstone.gatherer.Gatherer.ExternalApplication
-     */
-    static public void spawnApplication(File file) {
-	String [] commands = assoc_man.getCommand(file);
-	if(commands != null) {
-	    ExternalApplication app = new ExternalApplication(commands);
-	    apps.add(app);
-	    app.start();
-	}
-	else {
-	    ///ystem.err.println("No open command available.");
-	}
-    }
-
-
-    static public void spawnApplication(String command)
-    {
-	ExternalApplication app = new ExternalApplication(command);
-	apps.add(app);
-	app.start();
-    }
-
-    static public void spawnApplication(String command, String ID)
-    {
-	ExternalApplication app = new ExternalApplication(command, ID);
-	apps.add(app);
-	app.start();
-    }
-
-    static public void spawnApplication(String[] commands, String ID)
-    {
-	ExternalApplication app = new ExternalApplication(commands, ID);
-	apps.add(app);
-	app.start();
-    }
-
-    static public void terminateApplication(String ID) {
-	for(int i = 0; i < apps.size(); i++) {
-	    ExternalApplication app = (ExternalApplication)apps.get(i);
-	    if(app.getID() != null && app.getID().equals(ID)) {
-		app.stopExternalApplication();
-		apps.remove(app);
-	    }
-	}
-    }
-
-
-    /** Used to 'spawn' a new  browser application or reset an existing one when the preview button is clicked 
-     * @param url The url to open the browser at
-     * @see org.greenstone.gatherer.Gatherer.BrowserApplication
-     */    
-    static public void spawnBrowser(String url) {
-	String command = assoc_man.getBrowserCommand(url);
-	if (command != null) {
-	    BrowserApplication app = new BrowserApplication(command, url);
-	    apps.add(app);
-	    app.start();
-	}
-	else {
-	    ///ystem.err.println("No browser command available."); 
-	}
-    }
-
-
-    /** Prints a warning message about a missing library path, which means the final collection cannot be previewed in the Gatherer.
-     */
-    static public void missingEXEC() {
-	WarningDialog dialog;
-	String configPropertyName = "general.library_url"+Configuration.gliPropertyNameSuffix();
-
-	if (GS3) {
-	    // Warning dialog with no cancel button and no "turn off warning" checkbox 
-	    dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC_GS3.Title"), Dictionary.get("MissingEXEC_GS3.Message"), configPropertyName, false, false);
-	} else { // local case
-	    dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC.Title"), Dictionary.get("MissingEXEC.Message"), configPropertyName, false);
-	}
-
-	JTextField field = new URLField.Text(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false));
-
-	// Set the default library URL to the tomcat server and port number
-	// specified in the build.properties located in the gsdl3_src_path 
-	if (GS3) {
-	    String host = "localhost";
-	    String port = "8080";
-	    
-	    File buildPropsFile = new File(Configuration.gsdl3_src_path + File.separator + "build.properties");
-	    if(buildPropsFile.exists()) {
-		Properties props = new Properties();
-		try{
-		    props.load(new FileInputStream(buildPropsFile));
-		    host = props.getProperty("tomcat.server", host); 
-		    port = props.getProperty("tomcat.port", port);
-		}catch(Exception e){
-		    DebugStream.println("Could not load build.properties file");
-		    System.err.println("Could not load build.properties file");
-		}
-		props = null;
-	    }
-	    String defaultURL = "http://"+host+":"+port+"/"+"greenstone3";
-	    field.setText(defaultURL);
-	    field.selectAll();
-	}
-	dialog.setValueField(field);
-	dialog.display();
-	dialog.dispose();
-	dialog = null;
-
-	String library_url_string = Configuration.getString(configPropertyName, true);
-	if (!library_url_string.equals("")) {
-	    try {
-		// WarningDialog does not allow invalid URLs, so the following is ignored:
-		// make sure the URL the user provided contains the http:// prefix
-		// and then save the corrected URL
-		if(!library_url_string.startsWith("http://") 
-		   && !library_url_string.startsWith("https://")) {
-		    library_url_string = "http://"+library_url_string;
-		    Configuration.setString(configPropertyName, true, configPropertyName);
-		}
-		Configuration.library_url = new URL(library_url_string);
-	    }
-	    catch (MalformedURLException exception) {
-		DebugStream.printStackTrace(exception);
-	    }
-	}
-    }
-
-
-
-    /** Prints a warning message about a missing library path, which means the final collection cannot be previewed in the Gatherer.
-     */
-    static private void popupFedoraInfo() {
-
-	FedoraLogin dialog = new FedoraLogin("Fedora Login", false);
-
-	if (Configuration.library_url == null) {
-	    
-	    String library_url_string = dialog.getLibraryURL();
-	    if (!library_url_string.equals("")) {
+	}
+
+
+	static public void refresh(int refresh_reason)
+	{
+		if (g_man != null) {
+
+			g_man.refresh(refresh_reason, c_man.ready());
+		}
+
+		// Now is a good time to force a garbage collect
+		System.gc();
+	}
+
+
+	// used to send reload coll messages to the tomcat server
+	static public void configGS3Server(String site, String command) {
+		if (Configuration.library_url == null){
+			System.out.println("Error: you have not provided the Greenstone Library address.");  
+			return;
+
+		} 
+		
 		try {
-		    Configuration.library_url = new URL(library_url_string);
-		}
-		catch (MalformedURLException exception) {
-		    DebugStream.printStackTrace(exception);
-		}
-	    }
-	}
-	
-	boolean showLogin = true;
-	do {
-	    if(!dialog.loginRequested()) { // user pressed cancel to exit the FedoraLogin dialog
-		System.exit(0);
-	    } else {
-		showLogin = dialog.loginRequested();
-		String hostname = dialog.getHostname();
-		String port     = dialog.getPort();
-		String username = dialog.getUsername();
-		String password = dialog.getPassword();
-		String protocol = dialog.getProtocol();
-	    
-		Configuration.fedora_info.setHostname(hostname);
-		Configuration.fedora_info.setPort(port);
-		Configuration.fedora_info.setUsername(username);
-		Configuration.fedora_info.setPassword(password);
-		Configuration.fedora_info.setProtocol(protocol);
-	    
-		String ping_url_str = protocol + "://" + hostname + ":" + port + "/fedora";
-		String login_str = username + ":" + password;
-		
-		String login_encoding = Base64.encodeBytes(login_str.getBytes());
-				
-		try {
-		    URL ping_url = new URL(ping_url_str);
-		    URLConnection uc = ping_url.openConnection();
-		    uc.setRequestProperty  ("Authorization", "Basic " + login_encoding);
-		    // Attempt to access some content ...
-		    InputStream content = (InputStream)uc.getInputStream();
-		    
-		    // if no exception occurred in the above, we would have come here:
-		    showLogin = false;
-		    dialog.dispose();
-		}
-		catch (Exception exception) {
-		    // TODO: move into dictionary
-		    String[] errorMessage = {"Failed to connect to the Fedora server.", "It might not be running, or",
-					     "incorrect username and/or password."};
-		    dialog.setErrorMessage(errorMessage);
-		    //DebugStream.printStackTrace(exception);
-		    // exception occurred, show the dialog again (do this after printing to
-		    // debugStream, else the above does not get done for some reason).
-		    dialog.setVisible(true);
-		}
-	    } 
-	} while(showLogin);
-
-	dialog = null; // no more need of the dialog
-	
-	// Now we are connected.
-    }
-
-
-
-    static private void requestGLIServerURL()
-    {
-	WarningDialog dialog;
-	String[] defaultURLs = {
-	    "http://localhost:8080/greenstone3/cgi-bin/gliserver.pl", 
-	    "http://localhost:8080/gsdl/cgi-bin/gliserver.pl"
-	};
-
-	// Warning dialog with no cancel button and no "turn off warning" checkbox 
-	// (since user-input of the gliserver script is mandatory)
-	dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer.Title"), Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false, false); 
-
-	dialog.setValueField(new URLField.DropDown(Configuration.getColor("coloring.editable_foreground", false), 
-						   Configuration.getColor("coloring.editable_background", false), 
-						   defaultURLs, "general.gliserver_url", 
-						   "general.open_collection"+Configuration.gliPropertyNameSuffix(), 
-						   "gliserver.pl")); 
-
-	if (Gatherer.default_gliserver_url!=null){
-	    dialog.setValueField(Gatherer.default_gliserver_url.toString());
-	}
-
-	// A WarningDialog cannot always be made to respond (let alone to exit the program) on close. We
-	// handle the response of this particular WarningDialog here: a URL for gliserver.pl is a crucial
-	// piece of user-provided data. Therefore, if no URL was entered for gliserver.pl, it'll exit safely.
-	dialog.addWindowListener(new WindowAdapter() {
-		public void windowClosing(WindowEvent e) {
-		    Gatherer.exit();
-		}
-	    });
-	
-	dialog.display();
-	dialog.dispose();
-	dialog = null;
-
-	
-	String gliserver_url_string = Configuration.getString("general.gliserver_url", true);
-	if (!gliserver_url_string.equals("")) {
-	    try {
-		Configuration.gliserver_url = new URL(gliserver_url_string);
-		Configuration.setString("general.gliserver_url", true, gliserver_url_string);
-	    }
-	    catch (MalformedURLException exception) {
-		DebugStream.printStackTrace(exception);
-	    }
-	}
-    }
-
-
-    /** Prints a warning message about a missing GSDL path, which although not fatal pretty much ensures nothing will work properly in the GLI.
-     */
-    static private void missingGSDL() {
-	WarningDialog dialog = new WarningDialog("warning.MissingGSDL", Dictionary.get("MissingGSDL.Title"), Dictionary.get("MissingGSDL.Message"), null, false);
-	dialog.display();
-	dialog.dispose();
-	dialog = null;
-    }
-
-    /** Prints a warning message about missing a valid ImageMagick path, which although not fatal means building image collections won't work */
-    static private void missingImageMagick() {
-	WarningDialog dialog = new WarningDialog("warning.MissingImageMagick", Dictionary.get("MissingImageMagick.Title"), Dictionary.get("MissingImageMagick.Message"), null, false);
-	dialog.display();
-	dialog.dispose();
-	dialog = null;
-    }
-
-    /** Prints a warning message about missing a valid PERL path, which although not fatal pretty much ensures no collection creation/building will work properly in the GLI. */
-    static private void missingPERL() {
-	WarningDialog dialog = new WarningDialog("warning.MissingPERL", Dictionary.get("MissingPERL.Title"), Dictionary.get("MissingPERL.Message"), null, false);
-	dialog.display();
-	dialog.dispose();
-	dialog = null;
-    }
-
-	/** Prints a warning message about the OS not supporting multiple filename encodings.  */
-    static private void multipleFilenameEncodingsNotSupported() {	
-		WarningDialog dialog = new WarningDialog("warning.NoEncodingSupport", 
-			Dictionary.get("NoEncodingSupport.Title"), 
-			Dictionary.get("NoEncodingSupport.Message"), null, false);
+			// need to add the servlet name to the exec address
+			String raw_url = Configuration.library_url.toString() + Configuration.getServletPath() + command;
+			URL url = new URL(raw_url);
+			DebugStream.println("Action: " + raw_url);
+			HttpURLConnection library_connection = (HttpURLConnection) url.openConnection();
+			int response_code = library_connection.getResponseCode();
+			if(HttpURLConnection.HTTP_OK <= response_code && response_code < HttpURLConnection.HTTP_MULT_CHOICE) {
+				DebugStream.println("200 - Complete.");
+			}
+			else {
+				DebugStream.println("404 - Failed.");
+			}
+			url = null;
+		}
+		catch(java.net.ConnectException connectException) {
+			JOptionPane.showMessageDialog(g_man, Dictionary.get("Preferences.Connection.Library_Path_Connection_Failure", Configuration.library_url.toString()), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
+			DebugStream.println(connectException.getMessage());
+		}
+		catch (Exception exception) {            
+			DebugStream.printStackTrace(exception);
+		}
+	}
+
+
+	/** Used to 'spawn' a new child application when a file is double clicked.
+	* @param file The file to open 
+	* @see org.greenstone.gatherer.Gatherer.ExternalApplication
+	*/
+	static public void spawnApplication(File file) {
+		String [] commands = assoc_man.getCommand(file);
+		if(commands != null) {
+			ExternalApplication app = new ExternalApplication(commands);
+			apps.add(app);
+			app.start();
+		}
+		else {
+			///ystem.err.println("No open command available.");
+		}
+	}
+
+
+	static public void spawnApplication(String command)
+	{
+		ExternalApplication app = new ExternalApplication(command);
+		apps.add(app);
+		app.start();
+	}
+
+	static public void spawnApplication(String command, String ID)
+	{
+		ExternalApplication app = new ExternalApplication(command, ID);
+		apps.add(app);
+		app.start();
+	}
+
+	static public void spawnApplication(String[] commands, String ID)
+	{
+		ExternalApplication app = new ExternalApplication(commands, ID);
+		apps.add(app);
+		app.start();
+	}
+
+	static public void terminateApplication(String ID) {
+		for(int i = 0; i < apps.size(); i++) {
+			ExternalApplication app = (ExternalApplication)apps.get(i);
+			if(app.getID() != null && app.getID().equals(ID)) {
+				app.stopExternalApplication();
+				apps.remove(app);
+			}
+		}
+	}
+
+
+	/** Used to 'spawn' a new  browser application or reset an existing one when the preview button is clicked 
+	* @param url The url to open the browser at
+	* @see org.greenstone.gatherer.Gatherer.BrowserApplication
+	*/    
+	static public void spawnBrowser(String url) {
+		String command = assoc_man.getBrowserCommand(url);
+		if (command != null) {
+			BrowserApplication app = new BrowserApplication(command, url);
+			apps.add(app);
+			app.start();
+		}
+		else {
+			///ystem.err.println("No browser command available."); 
+		}
+	}
+
+
+	/** Prints a warning message about a missing library path, which means the final collection cannot be previewed in the Gatherer.
+	*/
+	static public void missingEXEC() {
+		WarningDialog dialog;
+		String configPropertyName = "general.library_url"+Configuration.gliPropertyNameSuffix();
+
+		if (GS3) {
+			// Warning dialog with no cancel button and no "turn off warning" checkbox 
+			dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC_GS3.Title"), Dictionary.get("MissingEXEC_GS3.Message"), configPropertyName, false, false);
+		} else { // local case
+			dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC.Title"), Dictionary.get("MissingEXEC.Message"), configPropertyName, false);
+		}
+
+		JTextField field = new URLField.Text(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false));
+
+		// Set the default library URL to the tomcat server and port number
+		// specified in the build.properties located in the gsdl3_src_path 
+		if (GS3) {
+			String host = "localhost";
+			String port = "8080";
+			
+			File buildPropsFile = new File(Configuration.gsdl3_src_path + File.separator + "build.properties");
+			if(buildPropsFile.exists()) {
+				Properties props = new Properties();
+				try{
+					props.load(new FileInputStream(buildPropsFile));
+					host = props.getProperty("tomcat.server", host); 
+					port = props.getProperty("tomcat.port", port);
+				}catch(Exception e){
+					DebugStream.println("Could not load build.properties file");
+					System.err.println("Could not load build.properties file");
+				}
+				props = null;
+			}
+			String defaultURL = "http://"+host+":"+port+"/"+"greenstone3";
+			field.setText(defaultURL);
+			field.selectAll();
+		}
+		dialog.setValueField(field);
 		dialog.display();
 		dialog.dispose();
 		dialog = null;
-    }
-
-    /** Sets up the proxy connection by setting JVM Environment flags and creating a new Authenticator.
-     * @see java.lang.Exception
-     * @see java.lang.System
-     * @see java.net.Authenticator
-     * @see org.greenstone.gatherer.Configuration
-     * @see org.greenstone.gatherer.GAuthenticator
-     */
-    static public void setProxy() {
-	try {// Can throw several exceptions
-	    if(Configuration.get("general.use_proxy", true)) {
-		System.setProperty("http.proxyType", "4");
-		System.setProperty("http.proxyHost", Configuration.getString("general.proxy_host", true));
-		System.setProperty("http.proxyPort", Configuration.getString("general.proxy_port", true));
-		System.setProperty("http.proxySet", "true");
-	    } else {
-		System.setProperty("http.proxyHost", "");
-		System.setProperty("http.proxyPort", "");
-		System.setProperty("http.proxySet", "false");
-	    }
-	} catch (Exception error) {
-	    DebugStream.println("Error in Gatherer.initProxy(): " + error);
-	    DebugStream.printStackTrace(error);
-	}
-    }
-
-    
-    /** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
-    static private class ExternalApplication
+
+		String library_url_string = Configuration.getString(configPropertyName, true);
+		if (!library_url_string.equals("")) {
+			try {
+				// WarningDialog does not allow invalid URLs, so the following is ignored:
+				// make sure the URL the user provided contains the http:// prefix
+				// and then save the corrected URL
+				if(!library_url_string.startsWith("http://") 
+						&& !library_url_string.startsWith("https://")) {
+					library_url_string = "http://"+library_url_string;
+					Configuration.setString(configPropertyName, true, configPropertyName);
+				}
+				Configuration.library_url = new URL(library_url_string);
+			}
+			catch (MalformedURLException exception) {
+				DebugStream.printStackTrace(exception);
+			}
+		}
+	}
+
+
+
+	/** Prints a warning message about a missing library path, which means the final collection cannot be previewed in the Gatherer.
+	*/
+	static private void popupFedoraInfo() {
+
+		FedoraLogin dialog = new FedoraLogin("Fedora Login", false);
+
+		if (Configuration.library_url == null) {
+			
+			String library_url_string = dialog.getLibraryURL();
+			if (!library_url_string.equals("")) {
+				try {
+					Configuration.library_url = new URL(library_url_string);
+				}
+				catch (MalformedURLException exception) {
+					DebugStream.printStackTrace(exception);
+				}
+			}
+		}
+		
+		boolean showLogin = true;
+		do {
+			if(!dialog.loginRequested()) { // user pressed cancel to exit the FedoraLogin dialog
+				System.exit(0);
+			} else {
+				showLogin = dialog.loginRequested();
+				String hostname = dialog.getHostname();
+				String port     = dialog.getPort();
+				String username = dialog.getUsername();
+				String password = dialog.getPassword();
+				String protocol = dialog.getProtocol();
+				
+				Configuration.fedora_info.setHostname(hostname);
+				Configuration.fedora_info.setPort(port);
+				Configuration.fedora_info.setUsername(username);
+				Configuration.fedora_info.setPassword(password);
+				Configuration.fedora_info.setProtocol(protocol);
+				
+				String ping_url_str = protocol + "://" + hostname + ":" + port + "/fedora";
+				String login_str = username + ":" + password;
+				
+				String login_encoding = Base64.encodeBytes(login_str.getBytes());
+				
+				try {
+					URL ping_url = new URL(ping_url_str);
+					URLConnection uc = ping_url.openConnection();
+					uc.setRequestProperty  ("Authorization", "Basic " + login_encoding);
+					// Attempt to access some content ...
+					InputStream content = (InputStream)uc.getInputStream();
+					
+					// if no exception occurred in the above, we would have come here:
+					showLogin = false;
+					dialog.dispose();
+				}
+				catch (Exception exception) {
+					// TODO: move into dictionary
+					String[] errorMessage = {"Failed to connect to the Fedora server.", "It might not be running, or",
+						"incorrect username and/or password."};
+					dialog.setErrorMessage(errorMessage);
+					//DebugStream.printStackTrace(exception);
+					// exception occurred, show the dialog again (do this after printing to
+					// debugStream, else the above does not get done for some reason).
+					dialog.setVisible(true);
+				}
+			} 
+		} while(showLogin);
+
+		dialog = null; // no more need of the dialog
+		
+		// Now we are connected.
+	}
+
+
+
+	static private void requestGLIServerURL()
+	{
+		WarningDialog dialog;
+		String[] defaultURLs = {
+			"http://localhost:8080/greenstone3/cgi-bin/gliserver.pl", 
+			"http://localhost:8080/gsdl/cgi-bin/gliserver.pl"
+		};
+
+		// Warning dialog with no cancel button and no "turn off warning" checkbox 
+		// (since user-input of the gliserver script is mandatory)
+		dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer.Title"), Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false, false); 
+
+		dialog.setValueField(new URLField.DropDown(Configuration.getColor("coloring.editable_foreground", false), 
+		Configuration.getColor("coloring.editable_background", false), 
+		defaultURLs, "general.gliserver_url", 
+		"general.open_collection"+Configuration.gliPropertyNameSuffix(), 
+		"gliserver.pl")); 
+
+		if (Gatherer.default_gliserver_url!=null){
+			dialog.setValueField(Gatherer.default_gliserver_url.toString());
+		}
+
+		// A WarningDialog cannot always be made to respond (let alone to exit the program) on close. We
+		// handle the response of this particular WarningDialog here: a URL for gliserver.pl is a crucial
+		// piece of user-provided data. Therefore, if no URL was entered for gliserver.pl, it'll exit safely.
+		dialog.addWindowListener(new WindowAdapter() {
+			public void windowClosing(WindowEvent e) {
+				Gatherer.exit();
+			}
+		});
+		
+		dialog.display();
+		dialog.dispose();
+		dialog = null;
+
+		
+		String gliserver_url_string = Configuration.getString("general.gliserver_url", true);
+		if (!gliserver_url_string.equals("")) {
+			try {
+				Configuration.gliserver_url = new URL(gliserver_url_string);
+				Configuration.setString("general.gliserver_url", true, gliserver_url_string);
+			}
+			catch (MalformedURLException exception) {
+				DebugStream.printStackTrace(exception);
+			}
+		}
+	}
+
+
+	/** Prints a warning message about a missing GSDL path, which although not fatal pretty much ensures nothing will work properly in the GLI.
+	*/
+	static private void missingGSDL() {
+		WarningDialog dialog = new WarningDialog("warning.MissingGSDL", Dictionary.get("MissingGSDL.Title"), Dictionary.get("MissingGSDL.Message"), null, false);
+		dialog.display();
+		dialog.dispose();
+		dialog = null;
+	}
+
+	/** Prints a warning message about missing a valid ImageMagick path, which although not fatal means building image collections won't work */
+	static private void missingImageMagick() {
+		WarningDialog dialog = new WarningDialog("warning.MissingImageMagick", Dictionary.get("MissingImageMagick.Title"), Dictionary.get("MissingImageMagick.Message"), null, false);
+		dialog.display();
+		dialog.dispose();
+		dialog = null;
+	}
+
+	/** Prints a warning message about missing a valid PERL path, which although not fatal pretty much ensures no collection creation/building will work properly in the GLI. */
+	static private void missingPERL() {
+		WarningDialog dialog = new WarningDialog("warning.MissingPERL", Dictionary.get("MissingPERL.Title"), Dictionary.get("MissingPERL.Message"), null, false);
+		dialog.display();
+		dialog.dispose();
+		dialog = null;
+	}
+
+	/** Prints a warning message about the OS not supporting multiple filename encodings.  */
+	static private void multipleFilenameEncodingsNotSupported() {	
+		WarningDialog dialog = new WarningDialog("warning.NoEncodingSupport", 
+		Dictionary.get("NoEncodingSupport.Title"), 
+		Dictionary.get("NoEncodingSupport.Message"), null, false);
+		dialog.display();
+		dialog.dispose();
+		dialog = null;
+	}
+
+	/** Sets up the proxy connection by setting JVM Environment flags and creating a new Authenticator.
+	* @see java.lang.Exception
+	* @see java.lang.System
+	* @see java.net.Authenticator
+	* @see org.greenstone.gatherer.Configuration
+	* @see org.greenstone.gatherer.GAuthenticator
+	*/
+	static public void setProxy() {
+		try {// Can throw several exceptions
+			if(Configuration.get("general.use_proxy", true)) {
+				System.setProperty("http.proxyType", "4");
+				System.setProperty("http.proxyHost", Configuration.getString("general.proxy_host", true));
+				System.setProperty("http.proxyPort", Configuration.getString("general.proxy_port", true));
+				System.setProperty("http.proxySet", "true");
+			} else {
+				System.setProperty("http.proxyHost", "");
+				System.setProperty("http.proxyPort", "");
+				System.setProperty("http.proxySet", "false");
+			}
+		} catch (Exception error) {
+			DebugStream.println("Error in Gatherer.initProxy(): " + error);
+			DebugStream.printStackTrace(error);
+		}
+	}
+
+	
+	/** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
+	static private class ExternalApplication
 	extends Thread {
-	private Process process = null;
-	/** The initial command string given to this sub-process. */
-	private String command = null;
-	private String[] commands = null;
-
-	private String ID = null;
-
-	/** Constructor.
-	 * @param command The initial command <strong>String</strong>.
-	 */
-	public ExternalApplication(String command) {
-	    this.command = command;
-	}
-
-	public ExternalApplication(String[] commands) {
-	    this.commands = commands;
-	}
-
-	public ExternalApplication(String command, String ID) {
-	    this.command = command;
-	    this.ID = ID;
-	}
-
-	public ExternalApplication(String[] commands, String ID) {
-	    this.commands = commands;
-	    this.ID = ID;
+		private Process process = null;
+		/** The initial command string given to this sub-process. */
+		private String command = null;
+		private String[] commands = null;
+
+		private String ID = null;
+
+		/** Constructor.
+	* @param command The initial command <strong>String</strong>.
+	*/
+		public ExternalApplication(String command) {
+			this.command = command;
+		}
+
+		public ExternalApplication(String[] commands) {
+			this.commands = commands;
+		}
+
+		public ExternalApplication(String command, String ID) {
+			this.command = command;
+			this.ID = ID;
+		}
+
+		public ExternalApplication(String[] commands, String ID) {
+			this.commands = commands;
+			this.ID = ID;
+		}
+		
+		public String getID() { 
+			return ID; 
+		}
+
+		/** We start the child process inside a new thread so it doesn't block the rest of Gatherer.
+	* @see java.lang.Exception
+	* @see java.lang.Process
+	* @see java.lang.Runtime
+	* @see java.lang.System
+	* @see java.util.Vector
+	*/
+		public void run() {
+			// Call an external process using the args.
+			try {
+				if(commands != null) {
+					StringBuffer whole_command = new StringBuffer();
+					for(int i = 0; i < commands.length; i++) {
+						whole_command.append(commands[i]);
+						whole_command.append(" ");
+					}
+					DebugStream.println("Running " + whole_command.toString());
+					Runtime rt = Runtime.getRuntime();
+					process = rt.exec(commands);
+					process.waitFor();
+				}
+				else {
+					DebugStream.println("Running " + command);
+					Runtime rt = Runtime.getRuntime();
+					process = rt.exec(command);
+					process.waitFor();
+				}
+			}
+			catch (Exception exception) {
+				DebugStream.printStackTrace(exception);
+			}
+			// Remove ourself from Gatherer list of threads.
+			apps.remove(this);
+			// Call exit if we were the last outstanding child process thread.
+			if (apps.size() == 0 && exit == true) {
+				// In my opinion (DB) there is no need to exit here,
+				// the 'run' method ending naturally brings this
+				// thread to an end.  In fact it is potentially
+				// dangerous to exit here, as the main thread in the
+				// Gatherer class may be stopped prematurely.  As it so
+				// happens the point at which the ExternalApplication thread
+				// is asked to stop (Back in the main Gatherer thread) is after
+				// various configuration files have been saved.
+				// 
+				// A similar argument holds for BrowserApplication thread below.
+				System.exit(exit_status);
+			}
+		}
+		public void stopExternalApplication() {
+			if(process != null) {
+				process.destroy();
+			}
+		}
+	}
+	/** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
+	static private class BrowserApplication
+	extends Thread {
+		private Process process = null;
+		/** The initial command string given to this sub-process. */
+		private String command = null;
+		private String url = null;
+		private String[] commands = null;
+
+		public BrowserApplication(String command, String url) {
+			StringTokenizer st = new StringTokenizer(command);
+			int num_tokens = st.countTokens();
+			this.commands = new String [num_tokens];
+			int i=0;
+			while (st.hasMoreTokens()) {
+				commands[i] = st.nextToken();
+				i++;
+			}
+			//this.commands = commands;
+			this.url = url;
+		}
+		/** We start the child process inside a new thread so it doesn't block the rest of Gatherer.
+	* @see java.lang.Exception
+	* @see java.lang.Process
+	* @see java.lang.Runtime
+	* @see java.lang.System
+	* @see java.util.Vector
+	*/
+		public void run() {
+			// Call an external process using the args.
+			if(commands == null) {
+				apps.remove(this);
+				return;
+			}
+			try {
+				String prog_name = commands[0];
+				String lower_name = prog_name.toLowerCase();
+				if (lower_name.indexOf("mozilla") != -1 || lower_name.indexOf("netscape") != -1) { 
+					DebugStream.println("found mozilla or netscape, trying remote it");
+					// mozilla and netscape, try using a remote command to get things in the same window
+					String [] new_commands = new String[] {prog_name, "-raise", "-remote", "openURL("+url+",new-tab)"};
+					printArray(new_commands);
+
+					Runtime rt = Runtime.getRuntime();
+					process = rt.exec(new_commands);
+					int exitCode = process.waitFor();
+					if (exitCode != 0) { // if Netscape or mozilla was not open
+						DebugStream.println("couldn't do remote, trying original command");
+						printArray(commands);
+						process = rt.exec(commands); // try the original command
+					}
+				} else {
+					// just run what we have been given
+					StringBuffer whole_command = new StringBuffer();
+					for(int i = 0; i < commands.length; i++) {
+						whole_command.append(commands[i]);
+						whole_command.append(" ");
+					}
+					DebugStream.println("Running " + whole_command.toString());
+					Runtime rt = Runtime.getRuntime();
+					process = rt.exec(commands);
+					process.waitFor();
+				}
+			}
+			
+			catch (Exception exception) {
+				DebugStream.printStackTrace(exception);
+			}
+			// Remove ourself from Gatherer list of threads.
+			apps.remove(this);
+			// Call exit if we were the last outstanding child process thread.
+			if (apps.size() == 0 && exit == true) {
+				System.exit(exit_status);
+			}
+		}
+		public void printArray(String [] array) {
+			for(int i = 0; i < array.length; i++) {
+				DebugStream.print(array[i]+" ");
+				System.err.println(array[i]+" ");
+			}
+		}
+		public void stopBrowserApplication() {
+			if(process != null) {
+				process.destroy();
+			}
+		}
+	}
+
+
+	private class ImageMagickTest
+	{
+		public boolean found()
+		{
+			try {
+				String[] command = new String[2];
+				command[0] = (Utility.isWindows() ? "identify.exe" : "identify");
+				command[1] = "-version";
+				Process image_magick_process = Runtime.getRuntime().exec(command);
+				image_magick_process.waitFor();
+
+				//new way of detection of ImageMagick
+				InputStreamReader isr = new InputStreamReader(image_magick_process.getInputStream());
+
+				BufferedReader br = new BufferedReader(isr);
+				// Capture the standard output stream and seach for two particular occurances: Version and ImageMagick.
+
+				String line = br.readLine();
+				if (line == null) {
+					return false;
+				}
+				String lc_line = line.toLowerCase();
+				if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
+					return true;
+				} else {
+					return false;
+				}
+
+				//return (image_magick_process.exitValue() == 0);
+			}
+			catch (IOException exception) {
+				return false;
+			}
+			catch (InterruptedException exception) {
+				return false;
+			}
+		}
+	}
+
+
+	private class PerlTest
+	{
+		private String[] command = new String[2];
+
+		public PerlTest()
+		{
+			command[0] = (Utility.isWindows() ? Utility.PERL_EXECUTABLE_WINDOWS : Utility.PERL_EXECUTABLE_UNIX);
+			command[1] = "-version";
+		}
+
+		public boolean found()
+		{
+			try {
+				Process perl_process = Runtime.getRuntime().exec(command);
+				perl_process.waitFor();
+				return (perl_process.exitValue() == 0);
+			}
+			catch (Exception exception) {
+				return false;
+			}
+		}
+
+		public String toString() {
+			return command[0];
+		}
 	}
 	
-	public String getID() { 
-	    return ID; 
-	}
-
-	/** We start the child process inside a new thread so it doesn't block the rest of Gatherer.
-	 * @see java.lang.Exception
-	 * @see java.lang.Process
-	 * @see java.lang.Runtime
-	 * @see java.lang.System
-	 * @see java.util.Vector
-	 */
-	public void run() {
-	    // Call an external process using the args.
-	    try {
-		if(commands != null) {
-		    StringBuffer whole_command = new StringBuffer();
-		    for(int i = 0; i < commands.length; i++) {
-			whole_command.append(commands[i]);
-			whole_command.append(" ");
-		    }
-		    DebugStream.println("Running " + whole_command.toString());
-		    Runtime rt = Runtime.getRuntime();
-		    process = rt.exec(commands);
-		    process.waitFor();
-		}
-		else {
-		    DebugStream.println("Running " + command);
-		    Runtime rt = Runtime.getRuntime();
-		    process = rt.exec(command);
-		    process.waitFor();
-		}
-	    }
-	    catch (Exception exception) {
-		DebugStream.printStackTrace(exception);
-	    }
-	    // Remove ourself from Gatherer list of threads.
-	    apps.remove(this);
-	    // Call exit if we were the last outstanding child process thread.
-	    if (apps.size() == 0 && exit == true) {
-		// In my opinion (DB) there is no need to exit here,
-		// the 'run' method ending naturally brings this
-		// thread to an end.  In fact it is potentially
-		// dangerous to exit here, as the main thread in the
-		// Gatherer class may be stopped prematurely.  As it so
-		// happens the point at which the ExternalApplication thread
-		// is asked to stop (Back in the main Gatherer thread) is after
-		// various configuration files have been saved.
-		// 
-		// A similar argument holds for BrowserApplication thread below.
-		System.exit(exit_status);
-	    }
-	}
-	public void stopExternalApplication() {
-	    if(process != null) {
-		process.destroy();
-	    }
-	}
-    }
-    /** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
-    static private class BrowserApplication
-	extends Thread {
-	private Process process = null;
-	/** The initial command string given to this sub-process. */
-	private String command = null;
-	private String url = null;
-	private String[] commands = null;
-
-	public BrowserApplication(String command, String url) {
-	    StringTokenizer st = new StringTokenizer(command);
-	    int num_tokens = st.countTokens();
-	    this.commands = new String [num_tokens];
-	    int i=0;
-	    while (st.hasMoreTokens()) {
-		commands[i] = st.nextToken();
-		i++;
-	    }
-	    //this.commands = commands;
-	    this.url = url;
-	}
-	/** We start the child process inside a new thread so it doesn't block the rest of Gatherer.
-	 * @see java.lang.Exception
-	 * @see java.lang.Process
-	 * @see java.lang.Runtime
-	 * @see java.lang.System
-	 * @see java.util.Vector
-	 */
-	public void run() {
-	    // Call an external process using the args.
-	    if(commands == null) {
-		apps.remove(this);
-		return;
-	    }
-	    try {
-		String prog_name = commands[0];
-		String lower_name = prog_name.toLowerCase();
-		if (lower_name.indexOf("mozilla") != -1 || lower_name.indexOf("netscape") != -1) { 
-		    DebugStream.println("found mozilla or netscape, trying remote it");
-		    // mozilla and netscape, try using a remote command to get things in the same window
-		    String [] new_commands = new String[] {prog_name, "-raise", "-remote", "openURL("+url+",new-tab)"};
-		    printArray(new_commands);
-
-		    Runtime rt = Runtime.getRuntime();
-		    process = rt.exec(new_commands);
-		    int exitCode = process.waitFor();
-		    if (exitCode != 0) { // if Netscape or mozilla was not open
-			DebugStream.println("couldn't do remote, trying original command");
-			printArray(commands);
-			process = rt.exec(commands); // try the original command
-		    }
-		} else {
-		    // just run what we have been given
-		    StringBuffer whole_command = new StringBuffer();
-		    for(int i = 0; i < commands.length; i++) {
-			whole_command.append(commands[i]);
-			whole_command.append(" ");
-		    }
-		    DebugStream.println("Running " + whole_command.toString());
-		    Runtime rt = Runtime.getRuntime();
-		    process = rt.exec(commands);
-		    process.waitFor();
-		}
-	    }
-	    
-	    catch (Exception exception) {
-		DebugStream.printStackTrace(exception);
-	    }
-	    // Remove ourself from Gatherer list of threads.
-	    apps.remove(this);
-	    // Call exit if we were the last outstanding child process thread.
-	    if (apps.size() == 0 && exit == true) {
-		System.exit(exit_status);
-	    }
-	}
-	public void printArray(String [] array) {
-	    for(int i = 0; i < array.length; i++) {
-		DebugStream.print(array[i]+" ");
-		System.err.println(array[i]+" ");
-	    }
-	}
-	public void stopBrowserApplication() {
-	    if(process != null) {
-		process.destroy();
-	    }
-	}
-    }
-
-
-    private class ImageMagickTest
-    {
-	public boolean found()
-	{
-	    try {
-		String[] command = new String[2];
-		command[0] = (Utility.isWindows() ? "identify.exe" : "identify");
-		command[1] = "-version";
-		Process image_magick_process = Runtime.getRuntime().exec(command);
-		image_magick_process.waitFor();
-
-		//new way of detection of ImageMagick
-		InputStreamReader isr = new InputStreamReader(image_magick_process.getInputStream());
-
-	        BufferedReader br = new BufferedReader(isr);
-	        // Capture the standard output stream and seach for two particular occurances: Version and ImageMagick.
-
-	        String line = br.readLine();
-		if (line == null) {
-		    return false;
-		}
-	        String lc_line = line.toLowerCase();
-		if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
-			return true;
-		} else {
-		        return false;
-		}
-
-		//return (image_magick_process.exitValue() == 0);
-	    }
-	    catch (IOException exception) {
-		return false;
-	    }
-	    catch (InterruptedException exception) {
-		return false;
-	    }
-	}
-    }
-
-
-    private class PerlTest
-    {
-	private String[] command = new String[2];
-
-	public PerlTest()
-	{
-	    command[0] = (Utility.isWindows() ? Utility.PERL_EXECUTABLE_WINDOWS : Utility.PERL_EXECUTABLE_UNIX);
-	    command[1] = "-version";
-	}
-
-	public boolean found()
-	{
-	    try {
-		Process perl_process = Runtime.getRuntime().exec(command);
-		perl_process.waitFor();
-		return (perl_process.exitValue() == 0);
-	    }
-	    catch (Exception exception) {
-		return false;
-	    }
-	}
-
-	public String toString() {
-	    return command[0];
-	}
-    }
+	public class GS3ServerThread extends Thread
+	{
+		String _gsdl_path = "";
+		
+		public GS3ServerThread(String gsdl_path)
+		{
+			_gsdl_path = gsdl_path;
+		}
+		
+		public void run()
+		{
+			try
+			{
+				String shellCommand = null;
+				if (Utility.isWindows())
+				{
+					shellCommand = "cmd /C";
+				}
+				else
+				{
+					shellCommand = "bash -c";
+				}
+				
+				Process p = Runtime.getRuntime().exec(shellCommand + " \"cd " + _gsdl_path + File.separator + ".. && ant start\"");
+			}
+			catch(Exception ex)
+			{
+				ex.printStackTrace();
+			}
+		}
+	}
 }
