Index: in/trunk/greenstone3/src/java/org/greenstone/admin/Configuration.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/Configuration.java	(revision 22084)
+++ 	(revision )
@@ -1,132 +1,0 @@
-/**
- *#########################################################################
- * Configuration
- * A component of the GAI application, part of the Greenstone digital
- * library suite from the New Zealand Digital Library Project at the
- * University of Waikato, New Zealand.
- *
- * <BR><BR>
- *
- * Copyright (C) 1999 New Zealand Digital Library Project
- *
- * <BR><BR>
- *
- * 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.
- *
- * <BR><BR>
- *
- * 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.
- *
- * <BR><BR>
- *
- * 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.admin;
-
-import java.awt.Color;
-import java.util.Locale;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
-
-// eventually this class will hold configuration settings from a config file. For now, lets use static info
-// loosely copied from Gatherer Configuration
-public class Configuration {
-    
-    static private Hashtable hash = null;
-
-    /** The first of three patterns used during tokenization, this pattern handles a comma separated list. */
-    static final private String TOKENIZER_PATTERN1 = " ,\n\t";
-    /** The second of three patterns used during tokenization, this pattern handles an underscore separated list. */
-    static final private String TOKENIZER_PATTERN2 = "_\n\t";
-    /** The last of three patterns used during tokenization, this pattern handles an comma separated list containing spaces. */
-    static final private String TOKENIZER_PATTERN3 = ",\n\t";
-
-    public Configuration() {
-	
-	hash = new Hashtable();
-	
-	
-	// load up all the initial stuff
-	hash.put("admin.log", "true");
-	hash.put("admin.conf", "true");
-	hash.put("admin.ext", "true");
-	hash.put("admin.monitor", "true");
-	hash.put("coloring.workspace_selection_foreground", "0, 0, 0");
-	hash.put("coloring.workspace_selection_background", "176, 208, 176");
-	hash.put("coloring.table_noneditable_background", "255, 255, 255");
-	hash.put("coloring.table_editable_background", "255, 255, 255");
-	hash.put("coloring.collection_tree_background", "224, 240, 224");
-	hash.put("coloring.collection_tree_foreground", "0, 0, 0");
-	hash.put("coloring.workspace_tree_foreground", "0, 0, 0");
-	hash.put("coloring.workspace_tree_background", "218, 237, 252");
-	hash.put("coloring.workspace_heading_background", "128, 180, 216");
-	hash.put("coloring.workspace_heading_foreground", "0, 0, 0");
-	
-    }
-
-    /** Retrieve whether the named property is set or not */
-    static public boolean get(String property) {
-	String value = (String)hash.get(property);
-	return (value != null && value.equalsIgnoreCase("true"));
-    }
-    
-    /** Retrieve the value of the named property as a String */
-    static public String getString(String property) {
-	return (String)hash.get(property);
-    }
-
-    /** Retrieve the value of the named property as a Locale. */
-    static public Locale getLocale(String property) {
-	Locale result = Locale.getDefault();
-	try {
-	    String raw = (String) hash.get(property);
-	    if (raw==null) {
-		return result;
-	    }
-	    // Locale is a underscore separated code.
-	    StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN2);
-	    String language = tokenizer.nextToken();
-	    if(tokenizer.hasMoreTokens()) {
-		String country = tokenizer.nextToken();
-		result = new Locale(language, country);
-	    }
-	    else {
-		result = new Locale(language);
-	    }
-	}
-	catch(Exception error) {
-	    error.printStackTrace();
-	}
-	return result;
-    }
-    
-    /** Retrieve the value of the named property as a Color. */
-    static public Color getColor(String property) {
-	Color result = Color.white; // Default
-	String raw = (String)hash.get(property);
-	if (raw == null || raw.equals("")) {
-	    return result;
-	}
-	try {
-	    // Color is a RGB triplet list, comma separated (also remove whitespace)
-	    StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
-	    int red = Integer.parseInt(tokenizer.nextToken());
-	    int green = Integer.parseInt(tokenizer.nextToken());
-	    int blue = Integer.parseInt(tokenizer.nextToken());
-	    result = new Color(red, green, blue);
-	}
-	catch(Exception error) {
-	    error.printStackTrace();
-	}
-	return result;
-    }
-}
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/GAI.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/GAI.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/GAI.java	(revision 22085)
@@ -38,4 +38,5 @@
 import javax.swing.text.*;
 
+import org.greenstone.util.Configuration;
 import org.greenstone.gsdl3.util.Dictionary;
 import org.greenstone.admin.gui.SetServerPane;
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/GAIFirstSettingFrame.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/GAIFirstSettingFrame.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/GAIFirstSettingFrame.java	(revision 22085)
@@ -49,4 +49,5 @@
 import javax.swing.tree.*;
 
+import org.greenstone.util.Configuration;
 import org.greenstone.core.ParsingProgress;
 import org.greenstone.admin.gui.SetServerPane;
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/GAIManager.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/GAIManager.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/GAIManager.java	(revision 22085)
@@ -35,4 +35,6 @@
 import org.greenstone.admin.gui.ConfPane;
 import org.greenstone.admin.guiext.ExtPane;
+
+import org.greenstone.util.Configuration;
 
 //import java AWT classes
@@ -87,4 +89,6 @@
 	//this.addFocusListener(new GAIGUIFocusListener());	
 	//display();
+	Image img = Toolkit.getDefaultToolkit().getImage("admin32.png");
+	this.setIconImage(img);
     }
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/ConfPane.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/ConfPane.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/ConfPane.java	(revision 22085)
@@ -56,9 +56,10 @@
 import org.greenstone.admin.GAI;
 import org.greenstone.admin.GAIManager;
-import org.greenstone.admin.Configuration;
 import org.greenstone.admin.gui.ThreadControl;
 //import org.greenstone.admin.gui.ConfSettingTableModel;
 import org.greenstone.admin.gui.SiteConfSetting;
 import org.greenstone.core.ParsingProgress;
+
+import org.greenstone.util.Configuration;
 import org.greenstone.gsdl3.util.GSFile;
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/LogPane.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/LogPane.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/LogPane.java	(revision 22085)
@@ -48,5 +48,5 @@
 import org.greenstone.admin.GAIManager;
 import org.greenstone.admin.GAI;
-import org.greenstone.admin.Configuration;
+import org.greenstone.util.Configuration;
 
 /** The Log pane is to view the status of relevant log files in GSIII
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/MenuBar.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/MenuBar.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/MenuBar.java	(revision 22085)
@@ -43,5 +43,5 @@
 
 import org.greenstone.admin.GAI;
-import org.greenstone.admin.Configuration;
+import org.greenstone.util.Configuration;
 
 /** The menu bar for the Administration tools main GUI. 
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/SetServerPane.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/SetServerPane.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/gui/SetServerPane.java	(revision 22085)
@@ -55,5 +55,5 @@
 import java.sql.*;
 
-import org.greenstone.admin.Configuration;
+import org.greenstone.util.Configuration;
 import org.greenstone.core.ParsingProgress;
 import org.greenstone.admin.GAI;
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/BaseExt.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/BaseExt.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/BaseExt.java	(revision 22085)
@@ -11,5 +11,5 @@
 
 import org.greenstone.gsdl3.util.GSPath;
-import org.greenstone.gsdl3.util.GlobalProperties;
+import org.greenstone.util.GlobalProperties;
 import org.w3c.dom.*;
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/ExtPane.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/ExtPane.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/ExtPane.java	(revision 22085)
@@ -26,7 +26,8 @@
 import org.greenstone.admin.GAIManager;
 import org.greenstone.admin.GAI;
-import org.greenstone.admin.Configuration;
+
+import org.greenstone.util.Configuration;
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.GSPath;
-import org.greenstone.gsdl3.util.GlobalProperties;
 
 import org.w3c.dom.Document;
Index: /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/PropertiesStep.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/PropertiesStep.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/PropertiesStep.java	(revision 22085)
@@ -31,5 +31,5 @@
 import org.w3c.dom.Element;
 
-import org.greenstone.admin.Configuration;
+import org.greenstone.util.Configuration;
 import org.greenstone.admin.LoggedMessageArea;
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/SOAPServerlocalsite.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/SOAPServerlocalsite.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/SOAPServerlocalsite.java	(revision 22085)
@@ -21,5 +21,5 @@
 
 import org.greenstone.gsdl3.core.MessageRouter;
-import org.greenstone.gsdl3.util.GlobalProperties;
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.GSFile;
 import org.greenstone.gsdl3.util.GSXML;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java	(revision 22085)
@@ -1,4 +1,5 @@
 package org.greenstone.gsdl3.action;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.core.ModuleInterface;
 import org.greenstone.gsdl3.util.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java	(revision 22085)
@@ -19,4 +19,5 @@
 package org.greenstone.gsdl3.comms;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.*;
 import org.greenstone.gsdl3.core.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 22085)
@@ -19,4 +19,5 @@
 package org.greenstone.gsdl3.core;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.*;
 import org.greenstone.gsdl3.service.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Page.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Page.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Page.java	(revision 22085)
@@ -4,4 +4,5 @@
 import java.util.HashMap;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.*;
 import org.w3c.dom.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 22085)
@@ -1,4 +1,5 @@
 package org.greenstone.gsdl3.core;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.*;
 import org.greenstone.gsdl3.action.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 22085)
@@ -1,4 +1,5 @@
 package org.greenstone.gsdl3.core;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.*;
 import org.greenstone.gsdl3.action.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java	(revision 22085)
@@ -22,4 +22,5 @@
 
 // Greenstone classes
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.core.GSException;
 import org.greenstone.gsdl3.util.GSXML;
@@ -27,5 +28,4 @@
 import org.greenstone.gsdl3.util.MacroResolver;
 import org.greenstone.gsdl3.util.OID;
-import org.greenstone.gsdl3.util.GlobalProperties;
 import org.greenstone.gsdl3.util.GSConstants;
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java	(revision 22085)
@@ -30,7 +30,7 @@
 import org.w3c.dom.NodeList;
 
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.GSXML;
 import org.greenstone.gsdl3.util.GSPath;
-import org.greenstone.gsdl3.util.GlobalProperties;
 
 import java.net.InetAddress;
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java	(revision 22085)
@@ -3,4 +3,5 @@
 // Greenstone classes
 import org.greenstone.gsdl3.core.GSException;
+import org.greenstone.util.Misc;
 import org.greenstone.gsdl3.util.*;
 
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/IViaSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/IViaSearch.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/IViaSearch.java	(revision 22085)
@@ -2,4 +2,5 @@
 
 // Greenstone classes
+import org.greenstone.util.Misc;
 import org.greenstone.gsdl3.util.*;
 
Index: in/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GlobalProperties.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GlobalProperties.java	(revision 22084)
+++ 	(revision )
@@ -1,135 +1,0 @@
-/*
- *    GlobalProperties.java
- *    Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
- *
- *    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.gsdl3.util;
-
-import java.util.Properties;
-import java.io.File;
-import java.io.InputStream;
-
-import org.apache.log4j.*;
-
-/** holds some global properties for the application. Read from a properties file */
-public class GlobalProperties {
-
-
-    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GlobalProperties.class.getName());
-    private static Properties properties = null;
-    private static String properties_filename = "global.properties";
-    private static String gsdl3_home = null;
-    private static String gsdl3_web_address = null;
-    
-    // Note, that if the servlet is reloadable, then it is reloaded each time the file is changed.
-    static {
-        //load in the properties
-        properties = new Properties();
-        reload();
-    }
-    
-    /** get the value of the property 'key'. returns null if not found */
-    public static String getProperty(String key) {
-        return properties.getProperty(key);
-    }
-
-    /** get the value of the property 'key'. 
-     * returns default_value if not found */
-    public static String getProperty(String key, String default_value) {
-        return properties.getProperty(key, default_value);
-    }
-
-    /** some special ones */
-    public static String getGSDL3Home() {
-        return gsdl3_home;
-    }
-
-    public static String getGSDL3WebAddress() {
-        return gsdl3_web_address;
-    }
-    
-    public static void reload() {
-        try {
-
-
-            InputStream in = Class.forName("org.greenstone.gsdl3.util.GlobalProperties").getClassLoader().getResourceAsStream(properties_filename);
-            if (in != null) {
-            logger.debug("loading global properties");
-            properties.load(in);
-            in.close();
-            } else {
-            logger.error("couldn't load global properties!");
-            }
-            gsdl3_home = properties.getProperty("gsdl3.home");
-            // make sure the path separators are correct
-            File gs3_file = new File(gsdl3_home);
-            gsdl3_home = gs3_file.getPath();
-
-            //build the gsdl3 web address, in a way resilient to errors and ommisions in global.properties, simplifying where possible
-            //aiming for a string with no trailing slash, eg "http://localhost:8080/greenstone3" or "http://www.mygreenstonelibrary.com"
-            String protocolSpecifier = null, hostSpecifier = null, portSpecifier = null, contextSpecifier = null;
-
-            //protocol
-            if ( properties.getProperty("tomcat.protocol") == null || properties.getProperty("tomcat.protocol").equals("") ) {
-                protocolSpecifier = "http://";
-            } else {
-                if ( properties.getProperty("tomcat.protocol").endsWith("://") ) {
-                    protocolSpecifier = properties.getProperty("tomcat.protocol");
-                } else {
-                    protocolSpecifier = properties.getProperty("tomcat.protocol") + "://";
-                }
-            }
-
-            //hostname
-            if ( properties.getProperty("tomcat.server") == null ) {
-                hostSpecifier = "localhost";
-            } else {
-                hostSpecifier = properties.getProperty("tomcat.server");
-                while ( hostSpecifier.endsWith("/") ) {
-                    hostSpecifier = hostSpecifier.substring( 0, hostSpecifier.length()-1 );
-                }
-            }
-
-            //port
-            if (
-                properties.getProperty("tomcat.port") == null ||
-                properties.getProperty("tomcat.port").equals("") ||
-                ( protocolSpecifier.equals("http://") && properties.getProperty("tomcat.port").equals("80") ) ||
-                ( protocolSpecifier.equals("https://") && properties.getProperty("tomcat.port").equals("443") )
-                ) {
-                portSpecifier = "";
-            } else {
-                portSpecifier = ":" + properties.getProperty("tomcat.port");
-            }
-
-            //context path
-            if ( properties.getProperty("tomcat.context") == null || properties.getProperty("tomcat.context").equals("") || properties.getProperty("tomcat.context").equals("/") ) {
-                contextSpecifier = "";
-            } else {
-                contextSpecifier = properties.getProperty("tomcat.context");
-                if ( !contextSpecifier.startsWith("/") ) {
-                    contextSpecifier = "/" + contextSpecifier;
-                }
-            }
-
-            //string it all together
-            gsdl3_web_address = protocolSpecifier + hostSpecifier + portSpecifier + contextSpecifier;
-
-        } catch (Exception e) {
-            logger.error( "Exception trying to reload global.properties: " + e );
-        }
-    }
-}
Index: in/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/Misc.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/Misc.java	(revision 22084)
+++ 	(revision )
@@ -1,106 +1,0 @@
- /*
- *    Misc.java
- *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
- *
- *    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.gsdl3.util;
-
-import java.util.HashMap;
-import java.util.Set;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.Properties;
-import java.io.InputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-
-/** contains miscellaneous functions */
-public class Misc {
-    
-    public static void printHash(HashMap map) {
-	Set entries = map.entrySet();
-	Iterator i = entries.iterator();
-	while (i.hasNext()) {
-	    Map.Entry m = (Map.Entry)i.next();
-	    String name = (String)m.getKey();
-	    String value = (String)m.getValue();
-	}  
-    }
-    
-    /** Method to determine if the host system is Windows based.
-     * @return a boolean which is true if the platform is Windows, 
-     * false otherwise
-     */
-    public static boolean isWindows() {
-	Properties props = System.getProperties();
-	String os_name = props.getProperty("os.name","");
-	if(os_name.startsWith("Windows")) {
-	    return true;
-	}
-	return false;
-    }
-    
-    public static boolean isWindows9x() {
-        Properties props = System.getProperties();
-        String os_name = props.getProperty("os.name","");
-        if(os_name.startsWith("Windows") && os_name.indexOf("9") != -1) {
-            return true;
-        }
-        return false;
-    }
-
-    /** Method to determine if the host system is MacOS based.
-     * @return a boolean which is true if the platform is MacOS, false otherwise
-     */
-    public static boolean isMac() {
-        Properties props = System.getProperties();
-        String os_name = props.getProperty("os.name","");
-        if(os_name.startsWith("Mac OS")) {
-            return true;
-        }
-        return false;
-    }
-    
-    public static boolean isBigEndian() {
-
-	if (System.getProperty("sun.cpu.endian").equals("big")) {
-	    return true;
-	}
-	return false;
-
-    }
-
-    public static BufferedReader makeHttpConnection(String url_string)
-	throws java.net.MalformedURLException, java.io.IOException {
-	BufferedReader reader = null;
-	URL url = new URL(url_string);
-	HttpURLConnection connection = (HttpURLConnection)url.openConnection();
-	InputStream input = connection.getInputStream();
-	reader = new BufferedReader(new InputStreamReader(input));  
-	return reader;
-    }
-
-    public static void main(String [] args) {
-	isBigEndian();
-    }
-
-}
-
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java	(revision 22085)
@@ -18,4 +18,6 @@
  */
 package org.greenstone.gsdl3.util;
+
+import org.greenstone.util.GlobalProperties;
 
 import org.w3c.dom.*;
Index: /main/trunk/greenstone3/src/java/org/greenstone/server/BaseServer.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/BaseServer.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/server/BaseServer.java	(revision 22085)
@@ -12,4 +12,7 @@
 
 import org.apache.log4j.*;
+
+import org.greenstone.util.RunTarget;
+import org.greenstone.util.BrowserLauncher;
 
 import org.greenstone.gsdl3.util.Dictionary;
Index: /main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java	(revision 22085)
@@ -11,4 +11,6 @@
 
 import org.apache.log4j.*;
+
+import org.greenstone.util.ScriptReadWrite;
 
 public abstract class BaseServerSettings extends JDialog implements ActionListener
Index: in/trunk/greenstone3/src/java/org/greenstone/server/BrowserLauncher.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/BrowserLauncher.java	(revision 22084)
+++ 	(revision )
@@ -1,135 +1,0 @@
-package org.greenstone.server;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.greenstone.gsdl3.util.Misc;
-import org.apache.log4j.*;
-
-public class BrowserLauncher 
-    extends Thread {
-    private String url = "about:blank" ;
-    static Logger logger = Logger.getLogger(org.greenstone.server.BrowserLauncher.class.getName());
-    private String[] default_browsers = new String[]{"firefox","mozilla"};
-    private String command = "";
-    private int state = -1; //0: launch success, 1: launch failed 
-    public final  static int LAUNCHSUCCESS = 0;
-    public final static int LAUNCHFAILED = 1;
-    private String browserPath = ""; 
-
-    public BrowserLauncher(String browserPath, String url) {
-	this.url = url;
-        this.browserPath = browserPath;
-        //use the default browser
-	if (this.browserPath.equals("")){
-	    setBrowserCommand();
-	}
-	else{
-	    this.command = this.browserPath + " " + this.url;
-	}
-    }
-
-    public BrowserLauncher(){
-
-    }
-
-    // we should try and use settings from the settings panel??
-    protected void setBrowserCommand() {
-	if(Misc.isWindows()) {
-	    // we use cmd and start
-	    if (Misc.isWindows9x()) {
-		this.command = BaseProperty.WIN_9X_OPEN_COMMAND;//"command.com /c start \""+url+"\"";
-	    } else {
-		this.command = BaseProperty.WIN_OPEN_COMMAND;//"cmd.exe /c start \"\" \""+url+"\"";
-	    }
-	} else if (Misc.isMac()) {
-	    this.command = BaseProperty.MAC_OPEN_COMMAND; // "open %1"
-	} else {
-	     // we try to look for a browser
- 	    for (int i=0; i<default_browsers.length; i++) {
- 		if (isAvailable(default_browsers[i])) {
- 		    this.command = default_browsers[i] + " %1";
- 		    break;
- 		}
- 	    }
-	}
-
-	this.command = this.command.replaceAll("%1",this.url);
-    }
-
-    protected boolean isAvailable(String program) {
-	try {
-             Runtime run = Runtime.getRuntime();
-             Process process = run.exec("which "+ program);
-             BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
-	     String line = null;
-	     while ((line = br.readLine()) != null){
-		 if (line.indexOf("no "+program) !=-1){
-		     return false;
-		 }
-	     }    	
-	     
-	    return true;
-	} catch (Exception e) {
-	    return false;
-	}
-    }
-
-    public  int getBrowserState(){
-	return state;
-    }
-    
-    public void run() {
-	// Call an external process using the args.
-	if(command.equals("")) {
-	    state = LAUNCHFAILED;
-            logger.error("launching command is empty: no browser found.");
-	    return;
-	}
-	
-        try {
-	    int exitCode = 0;
-	    String prog_name = this.command.substring(0,this.command.indexOf(" "));
-	    String lower_name = prog_name.toLowerCase();
-	    if (lower_name.indexOf("mozilla") != -1 || lower_name.indexOf("firefox") != -1) { 
-		logger.info("found mozilla or firefox, trying to remotely launch it");
-                // mozilla and netscape, try using a remote command to get things in the same window
-		String new_command = prog_name +" -raise -remote openURL("+url+",new-tab)";
-		logger.info(new_command);
-		Runtime rt = Runtime.getRuntime();
-		Process process = rt.exec(new_command);
-               	state = LAUNCHSUCCESS;
-		exitCode = process.waitFor();
-		logger.info("ExitCode:" + exitCode);              
-		if (exitCode != 0) { // if Netscape or mozilla was not open
-		    logger.info("couldn't do remote, trying original command");
-                    logger.info(this.command);
-		    process = rt.exec(this.command); // try the original command
-                    state = LAUNCHSUCCESS;
-		    //for some reason the following part is not executed sometimes.
-                    exitCode = process.waitFor();
-		}
-	    } else {
-		logger.info(this.command);
-                Runtime rt = Runtime.getRuntime();
-		Process process = rt.exec(this.command);
-                state = LAUNCHSUCCESS;
-              	//for some reason the following part is not executed sometimes.
-              	exitCode = process.waitFor();
-	    }
-
-	    logger.info("ExitCode:" + exitCode);
-	    if (exitCode != 0) { // if trying to launch the browser above failed
-	       state = LAUNCHFAILED;
-	       logger.error("Failed to launch web browser when running command:");
-	       logger.error("\t" + this.command);		
-	    }
-	}
-	catch (Exception e) {
-	    logger.error(e);
-            state = LAUNCHFAILED;
-	}
-	
-    }
-}
Index: in/trunk/greenstone3/src/java/org/greenstone/server/PortFinder.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/PortFinder.java	(revision 22084)
+++ 	(revision )
@@ -1,135 +1,0 @@
-package org.greenstone.server;
-
-/** Verbatim copy of what's in GLI's org.greenstone.gatherer.util */
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.BindException;
-
-// When needing to use sockets, this class can be used to find an available port
-public class PortFinder {
-
-    // Port numbers range from 0 to 65,535. RESERVED PORTS are below 1025
-    // see http://www.gnu.org/software/hello/manual/libc/Ports.html
-    public static final int MAX_PORT = 65535;
-    public static final int PORTS_RESERVED = 1024;
-
-    // Considering a limited range of ports that will be reused (circular buffer)
-    public final int PORT_BASE;
-    public final int PORT_BLOCK_SIZE;
-
-    // Keep track of what port numbers we have checked for availability
-    private int nextFreePort;
-
-    // The socket port number that we will use
-    private int port = -1;
-
-    public PortFinder() {
-	this( PORTS_RESERVED+1, (MAX_PORT - PORTS_RESERVED) );
-    }
-
-    public PortFinder(int base, int blocksize) {
-	PORT_BASE = base;
-	PORT_BLOCK_SIZE = blocksize;
-
-	nextFreePort = PORT_BASE;
-    }
-
-    /** Circular buffer. Modifies the value of nextFreePort (the buffer index). */
-    private void incrementNextFreePort() {
-	int offset = nextFreePort - PORT_BASE;
-	offset = (offset + 1) % PORT_BLOCK_SIZE;
-	nextFreePort = PORT_BASE + offset;
-    } 
-
-    /** Finds the first available port in the range specified during Constructor call.
-     *  @return the number of an available port.	
-     */
-    public int findPortInRange(boolean verbose) throws Exception {	
-	try {
-	    boolean foundFreePort = false;
-	    for(int i = 0; i < PORT_BLOCK_SIZE; i++) {
-		
-		if(isPortAvailable(nextFreePort, verbose)) {
-		    foundFreePort = true;
-		    break;
-		    
-		} else {
-		    incrementNextFreePort();
-		}
-	    }
-	    
-	    if(foundFreePort) {
-		// Free port number currently found becomes the port number of the socket
-		// that will be used
-		this.port = nextFreePort;
-		incrementNextFreePort();
-		
-	    } else {
-		throw new Exception("Cannot find an available port in the range " 
-				    + PORT_BASE + "-" + (PORT_BASE+PORT_BLOCK_SIZE));
-	    }
-	    
-	} catch(IOException e) {
-	    System.err.println("Error when trying to find an available port. In PortFinder.findPort() " + e);
-	}
-	return port;
-    }
-
-    /** @return true if the portnumber is in the valid range. */
-    public static boolean isValidPortNumber(int portNum) {
-	return (portNum >= 0 && portNum <= MAX_PORT);
-    }
-
-    /** @return true if the portnumber is in the useable range. */
-    public static boolean isAssignablePortNumber(int portNum) {
-	return (portNum > PORTS_RESERVED && portNum <= MAX_PORT);
-    }
-
-    /** Finds an available port.
-     * @return the number of an available port.
-     */
-    public static int findAnyFreePort() throws Exception {	
-	ServerSocket tmpSocket = null;
-	int portNumber = -1;
-	try {
-	    // Creates a server socket, bound to the specified port.
-	    // A port of 0 creates a socket on any free port. 
-	    tmpSocket = new ServerSocket(0);
-	    portNumber = tmpSocket.getLocalPort();
-	    tmpSocket.close();
-	} catch(Exception e) {
-	    System.err.println("Unable to find a free port or close it. Got Exception: " + e);
-	    tmpSocket = null;
-	}
-	return portNumber;
-    }
-
-    /** @return true if the portnum is available for use */
-    public static boolean isPortAvailable(int portnum, boolean verbose) {
-	ServerSocket tmpSocket = null;
-	try {
-	    tmpSocket = new ServerSocket(portnum);
-	    tmpSocket.close();
-	    //if(verbose) {
-	    //System.err.println("Port " + portnum + " not yet in use.");
-	    //}
-	    return true;
-	    
-	} catch(BindException ex){
-	    // "Signals that an error occurred while attempting to bind a 
-	    // socket to a local address and port. Typically, the port is 
-	    // in use, or the requested local address could not be assigned."
-	    if(verbose) {
-		System.err.println("Port " + portnum + " already in use or can't be assigned.");
-	    }
-	    tmpSocket = null;
-	    return false;	    
-	} catch(Exception ex) { 
-	    // Some other problem creating or closing the server socket
-	    System.err.println("Problem creating or closing server socket at port " + portnum);
-	    tmpSocket = null;
-	    return false;
-	}
-    }
-}
Index: in/trunk/greenstone3/src/java/org/greenstone/server/RunAnt.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/RunAnt.java	(revision 22084)
+++ 	(revision )
@@ -1,25 +1,0 @@
-package org.greenstone.server;
-
-import org.greenstone.server.RunTarget;
-
-public class RunAnt extends RunTarget 
-{
-    public RunAnt()
-    {
-	super();
-
-	targetSuccess  = "BUILD SUCCESSFUL";
-	targetFailed   = "BUILD FAILED";
-	targetFinished = "Total time";
-    }
-    
-    public void setTargetCmd(String target) 
-    {
-	String osName = System.getProperty("os.name");
-      	if (osName.startsWith("Windows")) {
-	    targetCmd = "ant.bat " + target;
-	} else {
-	    targetCmd = "ant " + target;
-	}
-    }
-}
Index: in/trunk/greenstone3/src/java/org/greenstone/server/RunMake.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/RunMake.java	(revision 22084)
+++ 	(revision )
@@ -1,28 +1,0 @@
-package org.greenstone.server;
-
-import org.greenstone.server.RunTarget;
-
-public class RunMake extends RunTarget 
-{
-
-    public RunMake()
-    {
-	super();
-
-	targetSuccess  = "MAKE SUCCESSFUL";
-	targetFailed   = "MAKE FAILED";
-	targetFinished = "MAKE DONE";
-    }
-
-
-    public void setTargetCmd(String target) 
-    {
-	String osName = System.getProperty("os.name");
-      	if (osName.startsWith("Windows")) {
-	    //targetCmd = "fakemake.bat " + target;
-	    targetCmd = "gsicontrol.bat " + target;
-	} else {
-	    targetCmd = "./gsicontrol.sh " + target;
-	}
-    }
-}
Index: in/trunk/greenstone3/src/java/org/greenstone/server/RunTarget.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/RunTarget.java	(revision 22084)
+++ 	(revision )
@@ -1,79 +1,0 @@
-package org.greenstone.server;
-
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.greenstone.server.StreamGobbler;
-
-import org.apache.log4j.*;
-
-public abstract class RunTarget extends Thread 
-{
-    protected String targetCmd = "";
-    protected static Logger logger = Logger.getLogger(RunTarget.class.getName());
-
-    protected int state = -1; //success: 0 error: 1    
-    public static int SUCCESS = 0;
-    public static int FAILED  = 1; 
-
-    protected String targetSuccess;
-    protected String targetFailed;
-    protected String targetFinished;
-
-    public void run() 
-    {
-	 
-	 try {
-	     state = -1;
-	     Runtime run = Runtime.getRuntime();
-
-	     String targetCmd = getTargetCmd();
-	     logger.info("Target: " + targetCmd);
-
-             Process process = run.exec(targetCmd);
-	     BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
-	     String line = null;
-             
-	     while ((line = br.readLine()) != null) {
-
-		 logger.info(line);
-
-		 if (line.equals(targetSuccess)){
-		     state = 0;
-		 }
-		 
-		 if (line.equals(targetFailed)){
-		     state = 1; 
-		 }
-
-		 if(line.startsWith(targetFinished)){
-		     break;		 
-		 }
-	     }
-	     
-	     br.close();
-
-	     if(state < 0) {
-		 logger.info("Unexpected end of input when running target: " + targetCmd);
-	     }
-	 } catch (Exception e) {
-	     e.printStackTrace();
-	     logger.error(e);
-	     state = 1;
-	 } 
-    }
-  
-    public int getTargetState()
-    {
-	return state;     
-    }
-    
-    public abstract void setTargetCmd(String cmd);
-
-    public String getTargetCmd() 
-    {
-	return this.targetCmd;
-    }
-}
Index: in/trunk/greenstone3/src/java/org/greenstone/server/ScriptReadWrite.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/ScriptReadWrite.java	(revision 22084)
+++ 	(revision )
@@ -1,115 +1,0 @@
-package org.greenstone.server;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-
-public class ScriptReadWrite {
-
-    public ScriptReadWrite() {
-    }
-
-    public ArrayList readInFile(File file) {
-	try {
-	    ArrayList fileLines = new ArrayList();
-	    String oneLine = null;
-	    BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
-	    while ((oneLine = bufferedReader.readLine()) != null) {
-		fileLines.add(oneLine);
-	    }
-	    bufferedReader.close();
-	    return fileLines;
-	} catch (Exception e) {
-	    System.err.println("exception:" + e);
-	    return null;
-	}
-    }
-
-    public void writeOutFile(File file, ArrayList fileLines_in) {
-	try {
-	    PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(file)));
-	    for (int i = 0; i < fileLines_in.size(); i++) {
-		printWriter.println(fileLines_in.get(i));
-	    }
-	    printWriter.flush();
-	    printWriter.close();
-	} catch (Exception e) {
-	    System.err.println("exception:" + e);
-	}
-    }
-
-    public ArrayList queryReplace(ArrayList fileLines_ex, String param,
-				  String newValue) {
-	// only replace existing, don't append if param does not exist
-	return replaceOrAddLine(fileLines_ex, param, newValue, false); 
-    }
-    
-    // if the parameter exists, then a replace is performed, else the parameter-value
-    // is appended
-    public ArrayList replaceOrAddLine(ArrayList fileLines_ex, String param, String newValue, 
-				      boolean replaceElseAdd) 
-    {	
-	String oneLine = null;
-	String newLine = null;
-	String name = null;
-	// int oneLine_length = 0;
-	param = param.trim();
-	// int param_length = param.length();
-
-	for (int i = 0; i < fileLines_ex.size(); i++) {
-	    oneLine = ((String) fileLines_ex.get(i)).trim();
-	    // oneLine_length = oneLine.length();
-	    StringTokenizer st = new StringTokenizer(oneLine, "=");
-	    if (st.hasMoreTokens()) {
-		name = st.nextToken();
-		if (param.equals(name)) {
-		    newLine = param + "=" + newValue;
-		    fileLines_ex.set(i, newLine);
-		    replaceElseAdd = false; // replaced, no longer need to add in any case
-		    break;
-		}
-	    }
-	}
-	// If we've made no replacement and need to append the new item
-	if(replaceElseAdd) {
-	    fileLines_ex.add(param+"="+newValue);
-	}
-	return fileLines_ex;
-    }
-
-    public String existValue(ArrayList fileLines, String querytext) {
-	String retValue = null;
-	String oneline = null;
-	String name = null;
-	// String value=null;
-	// int oneline_length = 0;
-	querytext = querytext.trim();
-	// int querytext_length = querytext.length();
-	for (int i = 0; i < fileLines.size(); i++) {
-	    oneline = ((String) fileLines.get(i)).trim();
-	    // oneline_length = oneline.length();
-	    StringTokenizer st = new StringTokenizer(oneline, "=");
-	    if (st.hasMoreTokens()) {
-		name = st.nextToken();
-		if (querytext.equals(name)) {
-		    if (st.hasMoreTokens()) {
-			retValue = st.nextToken();
-			retValue = retValue.trim();
-			if (retValue.equals("")) {
-			    retValue = null;
-			}
-		    } else {
-			retValue = null;
-		    }
-		    break;
-		}
-	    }
-	}
-	return retValue;
-    }
-}
Index: /main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java	(revision 22085)
@@ -18,4 +18,9 @@
 
 import org.apache.log4j.*;
+
+import org.greenstone.util.PortFinder;
+import org.greenstone.util.ScriptReadWrite;
+import org.greenstone.util.RunMake;
+import org.greenstone.util.RunAnt;
 
 import org.greenstone.server.BaseServer;
Index: /main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java	(revision 22085)
@@ -12,4 +12,5 @@
 
 import org.greenstone.server.BaseServerSettings;
+import org.greenstone.util.ScriptReadWrite;
 
 public class Server2Settings extends BaseServerSettings
Index: /main/trunk/greenstone3/src/java/org/greenstone/server/Server3.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/Server3.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/server/Server3.java	(revision 22085)
@@ -4,7 +4,9 @@
 import java.io.File;
 
+import org.greenstone.util.RunAnt;
+
 import org.greenstone.server.BaseServer;
 import org.greenstone.server.BaseProperty;
-import org.greenstone.gsdl3.util.GlobalProperties;
+import org.greenstone.util.GlobalProperties;
 
 public class Server3 extends BaseServer
Index: /main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java	(revision 22084)
+++ /main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java	(revision 22085)
@@ -10,6 +10,8 @@
 import org.w3c.dom.*;
 
+import org.greenstone.util.ScriptReadWrite;
+
+import org.greenstone.util.GlobalProperties;
 import org.greenstone.gsdl3.util.GSXML;
-import org.greenstone.gsdl3.util.GlobalProperties;
 import org.greenstone.gsdl3.util.XMLConverter;
 
Index: in/trunk/greenstone3/src/java/org/greenstone/server/StreamGobbler.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/server/StreamGobbler.java	(revision 22084)
+++ 	(revision )
@@ -1,39 +1,0 @@
-package org.greenstone.server;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.apache.log4j.*;
-
-class StreamGobbler{
-    static Logger logger = Logger.getLogger(org.greenstone.server.StreamGobbler.class.getName());
-    
-    public static void logError(InputStream in)
-      {
-	  try {
-	      BufferedReader br = new BufferedReader(new InputStreamReader(in));
-	      String line = null;
-              //using null as a guard doesn't work on windows 
-  	      while ((line = br.readLine()) != null){
-		  logger.error(line);
-	      }
-	  } catch (IOException ioe) {
-	      logger.error(ioe);
-	  }
-      }
-    
-    
-    public void logInfo(InputStream in){
-	try {
-	    BufferedReader br = new BufferedReader(new InputStreamReader(in));
-	    String line = null;
-	    while ((line = br.readLine()) != null){
-		  logger.info(line);
-	      }
-	  } catch (IOException ioe) {
-	      logger.error(ioe);
-	  }
-    }
-}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/BrowserLauncher.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/BrowserLauncher.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/BrowserLauncher.java	(revision 22085)
@@ -0,0 +1,136 @@
+package org.greenstone.util;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.greenstone.server.BaseProperty;
+import org.greenstone.util.Misc;
+import org.apache.log4j.*;
+
+public class BrowserLauncher 
+    extends Thread {
+    private String url = "about:blank" ;
+    static Logger logger = Logger.getLogger(org.greenstone.util.BrowserLauncher.class.getName());
+    private String[] default_browsers = new String[]{"firefox","mozilla"};
+    private String command = "";
+    private int state = -1; //0: launch success, 1: launch failed 
+    public final  static int LAUNCHSUCCESS = 0;
+    public final static int LAUNCHFAILED = 1;
+    private String browserPath = ""; 
+
+    public BrowserLauncher(String browserPath, String url) {
+	this.url = url;
+        this.browserPath = browserPath;
+        //use the default browser
+	if (this.browserPath.equals("")){
+	    setBrowserCommand();
+	}
+	else{
+	    this.command = this.browserPath + " " + this.url;
+	}
+    }
+
+    public BrowserLauncher(){
+
+    }
+
+    // we should try and use settings from the settings panel??
+    protected void setBrowserCommand() {
+	if(Misc.isWindows()) {
+	    // we use cmd and start
+	    if (Misc.isWindows9x()) {
+		this.command = BaseProperty.WIN_9X_OPEN_COMMAND;//"command.com /c start \""+url+"\"";
+	    } else {
+		this.command = BaseProperty.WIN_OPEN_COMMAND;//"cmd.exe /c start \"\" \""+url+"\"";
+	    }
+	} else if (Misc.isMac()) {
+	    this.command = BaseProperty.MAC_OPEN_COMMAND; // "open %1"
+	} else {
+	     // we try to look for a browser
+ 	    for (int i=0; i<default_browsers.length; i++) {
+ 		if (isAvailable(default_browsers[i])) {
+ 		    this.command = default_browsers[i] + " %1";
+ 		    break;
+ 		}
+ 	    }
+	}
+
+	this.command = this.command.replaceAll("%1",this.url);
+    }
+
+    protected boolean isAvailable(String program) {
+	try {
+             Runtime run = Runtime.getRuntime();
+             Process process = run.exec("which "+ program);
+             BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
+	     String line = null;
+	     while ((line = br.readLine()) != null){
+		 if (line.indexOf("no "+program) !=-1){
+		     return false;
+		 }
+	     }    	
+	     
+	    return true;
+	} catch (Exception e) {
+	    return false;
+	}
+    }
+
+    public  int getBrowserState(){
+	return state;
+    }
+    
+    public void run() {
+	// Call an external process using the args.
+	if(command.equals("")) {
+	    state = LAUNCHFAILED;
+            logger.error("launching command is empty: no browser found.");
+	    return;
+	}
+	
+        try {
+	    int exitCode = 0;
+	    String prog_name = this.command.substring(0,this.command.indexOf(" "));
+	    String lower_name = prog_name.toLowerCase();
+	    if (lower_name.indexOf("mozilla") != -1 || lower_name.indexOf("firefox") != -1) { 
+		logger.info("found mozilla or firefox, trying to remotely launch it");
+                // mozilla and netscape, try using a remote command to get things in the same window
+		String new_command = prog_name +" -raise -remote openURL("+url+",new-tab)";
+		logger.info(new_command);
+		Runtime rt = Runtime.getRuntime();
+		Process process = rt.exec(new_command);
+               	state = LAUNCHSUCCESS;
+		exitCode = process.waitFor();
+		logger.info("ExitCode:" + exitCode);              
+		if (exitCode != 0) { // if Netscape or mozilla was not open
+		    logger.info("couldn't do remote, trying original command");
+                    logger.info(this.command);
+		    process = rt.exec(this.command); // try the original command
+                    state = LAUNCHSUCCESS;
+		    //for some reason the following part is not executed sometimes.
+                    exitCode = process.waitFor();
+		}
+	    } else {
+		logger.info(this.command);
+                Runtime rt = Runtime.getRuntime();
+		Process process = rt.exec(this.command);
+                state = LAUNCHSUCCESS;
+              	//for some reason the following part is not executed sometimes.
+              	exitCode = process.waitFor();
+	    }
+
+	    logger.info("ExitCode:" + exitCode);
+	    if (exitCode != 0) { // if trying to launch the browser above failed
+	       state = LAUNCHFAILED;
+	       logger.error("Failed to launch web browser when running command:");
+	       logger.error("\t" + this.command);		
+	    }
+	}
+	catch (Exception e) {
+	    logger.error(e);
+            state = LAUNCHFAILED;
+	}
+	
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/Configuration.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/Configuration.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/Configuration.java	(revision 22085)
@@ -0,0 +1,132 @@
+/**
+ *#########################################################################
+ * Configuration
+ * A component of the GAI application, part of the Greenstone digital
+ * library suite from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * <BR><BR>
+ *
+ * Copyright (C) 1999 New Zealand Digital Library Project
+ *
+ * <BR><BR>
+ *
+ * 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.
+ *
+ * <BR><BR>
+ *
+ * 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.
+ *
+ * <BR><BR>
+ *
+ * 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.util;
+
+import java.awt.Color;
+import java.util.Locale;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+
+// eventually this class will hold configuration settings from a config file. For now, lets use static info
+// loosely copied from Gatherer Configuration
+public class Configuration {
+    
+    static private Hashtable hash = null;
+
+    /** The first of three patterns used during tokenization, this pattern handles a comma separated list. */
+    static final private String TOKENIZER_PATTERN1 = " ,\n\t";
+    /** The second of three patterns used during tokenization, this pattern handles an underscore separated list. */
+    static final private String TOKENIZER_PATTERN2 = "_\n\t";
+    /** The last of three patterns used during tokenization, this pattern handles an comma separated list containing spaces. */
+    static final private String TOKENIZER_PATTERN3 = ",\n\t";
+
+    public Configuration() {
+	
+	hash = new Hashtable();
+	
+	
+	// load up all the initial stuff
+	hash.put("admin.log", "true");
+	hash.put("admin.conf", "true");
+	hash.put("admin.ext", "true");
+	hash.put("admin.monitor", "true");
+	hash.put("coloring.workspace_selection_foreground", "0, 0, 0");
+	hash.put("coloring.workspace_selection_background", "176, 208, 176");
+	hash.put("coloring.table_noneditable_background", "255, 255, 255");
+	hash.put("coloring.table_editable_background", "255, 255, 255");
+	hash.put("coloring.collection_tree_background", "224, 240, 224");
+	hash.put("coloring.collection_tree_foreground", "0, 0, 0");
+	hash.put("coloring.workspace_tree_foreground", "0, 0, 0");
+	hash.put("coloring.workspace_tree_background", "218, 237, 252");
+	hash.put("coloring.workspace_heading_background", "128, 180, 216");
+	hash.put("coloring.workspace_heading_foreground", "0, 0, 0");
+	
+    }
+
+    /** Retrieve whether the named property is set or not */
+    static public boolean get(String property) {
+	String value = (String)hash.get(property);
+	return (value != null && value.equalsIgnoreCase("true"));
+    }
+    
+    /** Retrieve the value of the named property as a String */
+    static public String getString(String property) {
+	return (String)hash.get(property);
+    }
+
+    /** Retrieve the value of the named property as a Locale. */
+    static public Locale getLocale(String property) {
+	Locale result = Locale.getDefault();
+	try {
+	    String raw = (String) hash.get(property);
+	    if (raw==null) {
+		return result;
+	    }
+	    // Locale is a underscore separated code.
+	    StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN2);
+	    String language = tokenizer.nextToken();
+	    if(tokenizer.hasMoreTokens()) {
+		String country = tokenizer.nextToken();
+		result = new Locale(language, country);
+	    }
+	    else {
+		result = new Locale(language);
+	    }
+	}
+	catch(Exception error) {
+	    error.printStackTrace();
+	}
+	return result;
+    }
+    
+    /** Retrieve the value of the named property as a Color. */
+    static public Color getColor(String property) {
+	Color result = Color.white; // Default
+	String raw = (String)hash.get(property);
+	if (raw == null || raw.equals("")) {
+	    return result;
+	}
+	try {
+	    // Color is a RGB triplet list, comma separated (also remove whitespace)
+	    StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);
+	    int red = Integer.parseInt(tokenizer.nextToken());
+	    int green = Integer.parseInt(tokenizer.nextToken());
+	    int blue = Integer.parseInt(tokenizer.nextToken());
+	    result = new Color(red, green, blue);
+	}
+	catch(Exception error) {
+	    error.printStackTrace();
+	}
+	return result;
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/GlobalProperties.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/GlobalProperties.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/GlobalProperties.java	(revision 22085)
@@ -0,0 +1,135 @@
+/*
+ *    GlobalProperties.java
+ *    Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
+ *
+ *    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.util;
+
+import java.util.Properties;
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.log4j.*;
+
+/** holds some global properties for the application. Read from a properties file */
+public class GlobalProperties {
+
+
+    static Logger logger = Logger.getLogger(org.greenstone.util.GlobalProperties.class.getName());
+    private static Properties properties = null;
+    private static String properties_filename = "global.properties";
+    private static String gsdl3_home = null;
+    private static String gsdl3_web_address = null;
+    
+    // Note, that if the servlet is reloadable, then it is reloaded each time the file is changed.
+    static {
+        //load in the properties
+        properties = new Properties();
+        reload();
+    }
+    
+    /** get the value of the property 'key'. returns null if not found */
+    public static String getProperty(String key) {
+        return properties.getProperty(key);
+    }
+
+    /** get the value of the property 'key'. 
+     * returns default_value if not found */
+    public static String getProperty(String key, String default_value) {
+        return properties.getProperty(key, default_value);
+    }
+
+    /** some special ones */
+    public static String getGSDL3Home() {
+        return gsdl3_home;
+    }
+
+    public static String getGSDL3WebAddress() {
+        return gsdl3_web_address;
+    }
+    
+    public static void reload() {
+        try {
+
+
+            InputStream in = Class.forName("org.greenstone.util.GlobalProperties").getClassLoader().getResourceAsStream(properties_filename);
+            if (in != null) {
+            logger.debug("loading global properties");
+            properties.load(in);
+            in.close();
+            } else {
+            logger.error("couldn't load global properties!");
+            }
+            gsdl3_home = properties.getProperty("gsdl3.home");
+            // make sure the path separators are correct
+            File gs3_file = new File(gsdl3_home);
+            gsdl3_home = gs3_file.getPath();
+
+            //build the gsdl3 web address, in a way resilient to errors and ommisions in global.properties, simplifying where possible
+            //aiming for a string with no trailing slash, eg "http://localhost:8080/greenstone3" or "http://www.mygreenstonelibrary.com"
+            String protocolSpecifier = null, hostSpecifier = null, portSpecifier = null, contextSpecifier = null;
+
+            //protocol
+            if ( properties.getProperty("tomcat.protocol") == null || properties.getProperty("tomcat.protocol").equals("") ) {
+                protocolSpecifier = "http://";
+            } else {
+                if ( properties.getProperty("tomcat.protocol").endsWith("://") ) {
+                    protocolSpecifier = properties.getProperty("tomcat.protocol");
+                } else {
+                    protocolSpecifier = properties.getProperty("tomcat.protocol") + "://";
+                }
+            }
+
+            //hostname
+            if ( properties.getProperty("tomcat.server") == null ) {
+                hostSpecifier = "localhost";
+            } else {
+                hostSpecifier = properties.getProperty("tomcat.server");
+                while ( hostSpecifier.endsWith("/") ) {
+                    hostSpecifier = hostSpecifier.substring( 0, hostSpecifier.length()-1 );
+                }
+            }
+
+            //port
+            if (
+                properties.getProperty("tomcat.port") == null ||
+                properties.getProperty("tomcat.port").equals("") ||
+                ( protocolSpecifier.equals("http://") && properties.getProperty("tomcat.port").equals("80") ) ||
+                ( protocolSpecifier.equals("https://") && properties.getProperty("tomcat.port").equals("443") )
+                ) {
+                portSpecifier = "";
+            } else {
+                portSpecifier = ":" + properties.getProperty("tomcat.port");
+            }
+
+            //context path
+            if ( properties.getProperty("tomcat.context") == null || properties.getProperty("tomcat.context").equals("") || properties.getProperty("tomcat.context").equals("/") ) {
+                contextSpecifier = "";
+            } else {
+                contextSpecifier = properties.getProperty("tomcat.context");
+                if ( !contextSpecifier.startsWith("/") ) {
+                    contextSpecifier = "/" + contextSpecifier;
+                }
+            }
+
+            //string it all together
+            gsdl3_web_address = protocolSpecifier + hostSpecifier + portSpecifier + contextSpecifier;
+
+        } catch (Exception e) {
+            logger.error( "Exception trying to reload global.properties: " + e );
+        }
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java	(revision 22085)
@@ -0,0 +1,106 @@
+ /*
+ *    Misc.java
+ *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
+ *
+ *    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.util;
+
+import java.util.HashMap;
+import java.util.Set;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.Properties;
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+/** contains miscellaneous functions */
+public class Misc {
+    
+    public static void printHash(HashMap map) {
+	Set entries = map.entrySet();
+	Iterator i = entries.iterator();
+	while (i.hasNext()) {
+	    Map.Entry m = (Map.Entry)i.next();
+	    String name = (String)m.getKey();
+	    String value = (String)m.getValue();
+	}  
+    }
+    
+    /** Method to determine if the host system is Windows based.
+     * @return a boolean which is true if the platform is Windows, 
+     * false otherwise
+     */
+    public static boolean isWindows() {
+	Properties props = System.getProperties();
+	String os_name = props.getProperty("os.name","");
+	if(os_name.startsWith("Windows")) {
+	    return true;
+	}
+	return false;
+    }
+    
+    public static boolean isWindows9x() {
+        Properties props = System.getProperties();
+        String os_name = props.getProperty("os.name","");
+        if(os_name.startsWith("Windows") && os_name.indexOf("9") != -1) {
+            return true;
+        }
+        return false;
+    }
+
+    /** Method to determine if the host system is MacOS based.
+     * @return a boolean which is true if the platform is MacOS, false otherwise
+     */
+    public static boolean isMac() {
+        Properties props = System.getProperties();
+        String os_name = props.getProperty("os.name","");
+        if(os_name.startsWith("Mac OS")) {
+            return true;
+        }
+        return false;
+    }
+    
+    public static boolean isBigEndian() {
+
+	if (System.getProperty("sun.cpu.endian").equals("big")) {
+	    return true;
+	}
+	return false;
+
+    }
+
+    public static BufferedReader makeHttpConnection(String url_string)
+	throws java.net.MalformedURLException, java.io.IOException {
+	BufferedReader reader = null;
+	URL url = new URL(url_string);
+	HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+	InputStream input = connection.getInputStream();
+	reader = new BufferedReader(new InputStreamReader(input));  
+	return reader;
+    }
+
+    public static void main(String [] args) {
+	isBigEndian();
+    }
+
+}
+
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/PortFinder.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/PortFinder.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/PortFinder.java	(revision 22085)
@@ -0,0 +1,135 @@
+package org.greenstone.util;
+
+/** Verbatim copy of what's in GLI's org.greenstone.gatherer.util */
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.BindException;
+
+// When needing to use sockets, this class can be used to find an available port
+public class PortFinder {
+
+    // Port numbers range from 0 to 65,535. RESERVED PORTS are below 1025
+    // see http://www.gnu.org/software/hello/manual/libc/Ports.html
+    public static final int MAX_PORT = 65535;
+    public static final int PORTS_RESERVED = 1024;
+
+    // Considering a limited range of ports that will be reused (circular buffer)
+    public final int PORT_BASE;
+    public final int PORT_BLOCK_SIZE;
+
+    // Keep track of what port numbers we have checked for availability
+    private int nextFreePort;
+
+    // The socket port number that we will use
+    private int port = -1;
+
+    public PortFinder() {
+	this( PORTS_RESERVED+1, (MAX_PORT - PORTS_RESERVED) );
+    }
+
+    public PortFinder(int base, int blocksize) {
+	PORT_BASE = base;
+	PORT_BLOCK_SIZE = blocksize;
+
+	nextFreePort = PORT_BASE;
+    }
+
+    /** Circular buffer. Modifies the value of nextFreePort (the buffer index). */
+    private void incrementNextFreePort() {
+	int offset = nextFreePort - PORT_BASE;
+	offset = (offset + 1) % PORT_BLOCK_SIZE;
+	nextFreePort = PORT_BASE + offset;
+    } 
+
+    /** Finds the first available port in the range specified during Constructor call.
+     *  @return the number of an available port.	
+     */
+    public int findPortInRange(boolean verbose) throws Exception {	
+	try {
+	    boolean foundFreePort = false;
+	    for(int i = 0; i < PORT_BLOCK_SIZE; i++) {
+		
+		if(isPortAvailable(nextFreePort, verbose)) {
+		    foundFreePort = true;
+		    break;
+		    
+		} else {
+		    incrementNextFreePort();
+		}
+	    }
+	    
+	    if(foundFreePort) {
+		// Free port number currently found becomes the port number of the socket
+		// that will be used
+		this.port = nextFreePort;
+		incrementNextFreePort();
+		
+	    } else {
+		throw new Exception("Cannot find an available port in the range " 
+				    + PORT_BASE + "-" + (PORT_BASE+PORT_BLOCK_SIZE));
+	    }
+	    
+	} catch(IOException e) {
+	    System.err.println("Error when trying to find an available port. In PortFinder.findPort() " + e);
+	}
+	return port;
+    }
+
+    /** @return true if the portnumber is in the valid range. */
+    public static boolean isValidPortNumber(int portNum) {
+	return (portNum >= 0 && portNum <= MAX_PORT);
+    }
+
+    /** @return true if the portnumber is in the useable range. */
+    public static boolean isAssignablePortNumber(int portNum) {
+	return (portNum > PORTS_RESERVED && portNum <= MAX_PORT);
+    }
+
+    /** Finds an available port.
+     * @return the number of an available port.
+     */
+    public static int findAnyFreePort() throws Exception {	
+	ServerSocket tmpSocket = null;
+	int portNumber = -1;
+	try {
+	    // Creates a server socket, bound to the specified port.
+	    // A port of 0 creates a socket on any free port. 
+	    tmpSocket = new ServerSocket(0);
+	    portNumber = tmpSocket.getLocalPort();
+	    tmpSocket.close();
+	} catch(Exception e) {
+	    System.err.println("Unable to find a free port or close it. Got Exception: " + e);
+	    tmpSocket = null;
+	}
+	return portNumber;
+    }
+
+    /** @return true if the portnum is available for use */
+    public static boolean isPortAvailable(int portnum, boolean verbose) {
+	ServerSocket tmpSocket = null;
+	try {
+	    tmpSocket = new ServerSocket(portnum);
+	    tmpSocket.close();
+	    //if(verbose) {
+	    //System.err.println("Port " + portnum + " not yet in use.");
+	    //}
+	    return true;
+	    
+	} catch(BindException ex){
+	    // "Signals that an error occurred while attempting to bind a 
+	    // socket to a local address and port. Typically, the port is 
+	    // in use, or the requested local address could not be assigned."
+	    if(verbose) {
+		System.err.println("Port " + portnum + " already in use or can't be assigned.");
+	    }
+	    tmpSocket = null;
+	    return false;	    
+	} catch(Exception ex) { 
+	    // Some other problem creating or closing the server socket
+	    System.err.println("Problem creating or closing server socket at port " + portnum);
+	    tmpSocket = null;
+	    return false;
+	}
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/RunAnt.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/RunAnt.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/RunAnt.java	(revision 22085)
@@ -0,0 +1,25 @@
+package org.greenstone.util;
+
+import org.greenstone.util.RunTarget;
+
+public class RunAnt extends RunTarget 
+{
+    public RunAnt()
+    {
+	super();
+
+	targetSuccess  = "BUILD SUCCESSFUL";
+	targetFailed   = "BUILD FAILED";
+	targetFinished = "Total time";
+    }
+    
+    public void setTargetCmd(String target) 
+    {
+	String osName = System.getProperty("os.name");
+      	if (osName.startsWith("Windows")) {
+	    targetCmd = "ant.bat " + target;
+	} else {
+	    targetCmd = "ant " + target;
+	}
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/RunMake.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/RunMake.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/RunMake.java	(revision 22085)
@@ -0,0 +1,28 @@
+package org.greenstone.util;
+
+import org.greenstone.util.RunTarget;
+
+public class RunMake extends RunTarget 
+{
+
+    public RunMake()
+    {
+	super();
+
+	targetSuccess  = "MAKE SUCCESSFUL";
+	targetFailed   = "MAKE FAILED";
+	targetFinished = "MAKE DONE";
+    }
+
+
+    public void setTargetCmd(String target) 
+    {
+	String osName = System.getProperty("os.name");
+      	if (osName.startsWith("Windows")) {
+	    //targetCmd = "fakemake.bat " + target;
+	    targetCmd = "gsicontrol.bat " + target;
+	} else {
+	    targetCmd = "./gsicontrol.sh " + target;
+	}
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/RunTarget.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/RunTarget.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/RunTarget.java	(revision 22085)
@@ -0,0 +1,79 @@
+package org.greenstone.util;
+
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.greenstone.util.StreamGobbler;
+
+import org.apache.log4j.*;
+
+public abstract class RunTarget extends Thread 
+{
+    protected String targetCmd = "";
+    protected static Logger logger = Logger.getLogger(RunTarget.class.getName());
+
+    protected int state = -1; //success: 0 error: 1    
+    public static int SUCCESS = 0;
+    public static int FAILED  = 1; 
+
+    protected String targetSuccess;
+    protected String targetFailed;
+    protected String targetFinished;
+
+    public void run() 
+    {
+	 
+	 try {
+	     state = -1;
+	     Runtime run = Runtime.getRuntime();
+
+	     String targetCmd = getTargetCmd();
+	     logger.info("Target: " + targetCmd);
+
+             Process process = run.exec(targetCmd);
+	     BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
+	     String line = null;
+             
+	     while ((line = br.readLine()) != null) {
+
+		 logger.info(line);
+
+		 if (line.equals(targetSuccess)){
+		     state = 0;
+		 }
+		 
+		 if (line.equals(targetFailed)){
+		     state = 1; 
+		 }
+
+		 if(line.startsWith(targetFinished)){
+		     break;		 
+		 }
+	     }
+	     
+	     br.close();
+
+	     if(state < 0) {
+		 logger.info("Unexpected end of input when running target: " + targetCmd);
+	     }
+	 } catch (Exception e) {
+	     e.printStackTrace();
+	     logger.error(e);
+	     state = 1;
+	 } 
+    }
+  
+    public int getTargetState()
+    {
+	return state;     
+    }
+    
+    public abstract void setTargetCmd(String cmd);
+
+    public String getTargetCmd() 
+    {
+	return this.targetCmd;
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/ScriptReadWrite.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/ScriptReadWrite.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/ScriptReadWrite.java	(revision 22085)
@@ -0,0 +1,115 @@
+package org.greenstone.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+public class ScriptReadWrite {
+
+    public ScriptReadWrite() {
+    }
+
+    public ArrayList readInFile(File file) {
+	try {
+	    ArrayList fileLines = new ArrayList();
+	    String oneLine = null;
+	    BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
+	    while ((oneLine = bufferedReader.readLine()) != null) {
+		fileLines.add(oneLine);
+	    }
+	    bufferedReader.close();
+	    return fileLines;
+	} catch (Exception e) {
+	    System.err.println("exception:" + e);
+	    return null;
+	}
+    }
+
+    public void writeOutFile(File file, ArrayList fileLines_in) {
+	try {
+	    PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+	    for (int i = 0; i < fileLines_in.size(); i++) {
+		printWriter.println(fileLines_in.get(i));
+	    }
+	    printWriter.flush();
+	    printWriter.close();
+	} catch (Exception e) {
+	    System.err.println("exception:" + e);
+	}
+    }
+
+    public ArrayList queryReplace(ArrayList fileLines_ex, String param,
+				  String newValue) {
+	// only replace existing, don't append if param does not exist
+	return replaceOrAddLine(fileLines_ex, param, newValue, false); 
+    }
+    
+    // if the parameter exists, then a replace is performed, else the parameter-value
+    // is appended
+    public ArrayList replaceOrAddLine(ArrayList fileLines_ex, String param, String newValue, 
+				      boolean replaceElseAdd) 
+    {	
+	String oneLine = null;
+	String newLine = null;
+	String name = null;
+	// int oneLine_length = 0;
+	param = param.trim();
+	// int param_length = param.length();
+
+	for (int i = 0; i < fileLines_ex.size(); i++) {
+	    oneLine = ((String) fileLines_ex.get(i)).trim();
+	    // oneLine_length = oneLine.length();
+	    StringTokenizer st = new StringTokenizer(oneLine, "=");
+	    if (st.hasMoreTokens()) {
+		name = st.nextToken();
+		if (param.equals(name)) {
+		    newLine = param + "=" + newValue;
+		    fileLines_ex.set(i, newLine);
+		    replaceElseAdd = false; // replaced, no longer need to add in any case
+		    break;
+		}
+	    }
+	}
+	// If we've made no replacement and need to append the new item
+	if(replaceElseAdd) {
+	    fileLines_ex.add(param+"="+newValue);
+	}
+	return fileLines_ex;
+    }
+
+    public String existValue(ArrayList fileLines, String querytext) {
+	String retValue = null;
+	String oneline = null;
+	String name = null;
+	// String value=null;
+	// int oneline_length = 0;
+	querytext = querytext.trim();
+	// int querytext_length = querytext.length();
+	for (int i = 0; i < fileLines.size(); i++) {
+	    oneline = ((String) fileLines.get(i)).trim();
+	    // oneline_length = oneline.length();
+	    StringTokenizer st = new StringTokenizer(oneline, "=");
+	    if (st.hasMoreTokens()) {
+		name = st.nextToken();
+		if (querytext.equals(name)) {
+		    if (st.hasMoreTokens()) {
+			retValue = st.nextToken();
+			retValue = retValue.trim();
+			if (retValue.equals("")) {
+			    retValue = null;
+			}
+		    } else {
+			retValue = null;
+		    }
+		    break;
+		}
+	    }
+	}
+	return retValue;
+    }
+}
Index: /main/trunk/greenstone3/src/java/org/greenstone/util/StreamGobbler.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/util/StreamGobbler.java	(revision 22085)
+++ /main/trunk/greenstone3/src/java/org/greenstone/util/StreamGobbler.java	(revision 22085)
@@ -0,0 +1,39 @@
+package org.greenstone.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.apache.log4j.*;
+
+class StreamGobbler{
+    static Logger logger = Logger.getLogger(org.greenstone.util.StreamGobbler.class.getName());
+    
+    public static void logError(InputStream in)
+      {
+	  try {
+	      BufferedReader br = new BufferedReader(new InputStreamReader(in));
+	      String line = null;
+              //using null as a guard doesn't work on windows 
+  	      while ((line = br.readLine()) != null){
+		  logger.error(line);
+	      }
+	  } catch (IOException ioe) {
+	      logger.error(ioe);
+	  }
+      }
+    
+    
+    public void logInfo(InputStream in){
+	try {
+	    BufferedReader br = new BufferedReader(new InputStreamReader(in));
+	    String line = null;
+	    while ((line = br.readLine()) != null){
+		  logger.info(line);
+	      }
+	  } catch (IOException ioe) {
+	      logger.error(ioe);
+	  }
+    }
+}
