Index: main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 24499)
+++ main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 24505)
@@ -1,3 +1,2 @@
-/**
 /**
  *############################################################################
@@ -237,5 +236,6 @@
 	    return true;
 	} else if(llssite_cfg_file.isIndependentGSI()) {
-	    // there is a url, it's not pending, and it is llssite.cfg: meaning GSI has started up
+	    // There is already a url and it's not pending: meaning the server 
+		// has started up and that GSI was launched outside of GLI 
 	    running = true;
 	    return true;    
@@ -254,5 +254,5 @@
 	    // If it is already running then set the Greenstone web server address and we're done
 	    // E.g. if previously GLI was not properly shut down, the URL property (signifying 
-	    // the server is still running) would still be in the glisite_cfg file.
+	    // the server is still running) would still be in the config file.
 	    try {
 		Configuration.library_url = new URL(url);
@@ -582,10 +582,7 @@
 	    }
 	}
-	else { // NO URL in current ConfigFile, check the other configfile for a URL 
-	    // to see if the server was restarted using that file.
-	    // Otherwise need to restart the server again with GLIsite.cfg
-	    llssite_cfg_file.save(); // save the configfile, because we may be reloading another
-
-	    if(llssite_cfg_file.usingLLS_configFile()) { // if a GSI is already using llssite_cfg, this would have loaded it in
+	else { // NO URL in current mode of configFile, try other mode (e.g. "gli.url")
+		   
+		if(llssite_cfg_file.usingGSImode()) { // if a GSI is already using llssite_cfg, this would have loaded it in
 		url = llssite_cfg_file.getURL(); //if(isURLPending()) {
 		if(url.equals(LLSSiteConfig.URL_PENDING)) {
@@ -597,7 +594,7 @@
 	    } else {
 		// else we try using the glisite configfile
-		llssite_cfg_file.useGLISiteCfg(local_library_server_file);
+		llssite_cfg_file.useGLImode();
 	    	//llssite_cfg_file.set();
-		
+				
 		// since we're going to restart the server, make sure to reset all
 		// the client socket and its writer (for communicating with the web server) 
@@ -657,11 +654,10 @@
 	private File configFile;
 
-	private File llssite_cfg;
-	private File glisite_cfg;
 	private String autoenter_initial;
 	private String start_browser_initial;
 
 	private long lastModified = 0;
-    
+    private boolean isIndependentGSI;
+	
 	static final private String GLI_PREFIX = "gli";
 	static final private String GSI_AUTOENTER = "autoenter";
@@ -670,5 +666,4 @@
 	static final private String ENTERLIB = "enterlib";
 	static final private String FALSE = "0";
-	static final private String GLISITE_CFG = "glisite.cfg";
 	static final private String GSDL = "greenstone"; // httpprefix is no longer /gsdl but /greenstone
 	static final private String LLSSITE_CFG = "llssite.cfg";
@@ -680,5 +675,6 @@
 	static final private String GSI_STARTBROWSER = "start_browser";
 	static final private String TRUE = "1";
-	static final private String URL = "url";
+	static final private String URL = GLI_PREFIX+"."+"url";
+	static final private String GSI_URL = "url";
 	static final private String COLLECTHOME = "collecthome";
 	static final private String GLIMODE = "--mode="+GLI_PREFIX;
@@ -689,19 +685,34 @@
 	public LLSSiteConfig(File server_exe) {
 	    debug("New LLSSiteConfig for: " + server_exe.getAbsolutePath());
-	    
-	    llssite_cfg = new File(server_exe.getParentFile(), LLSSITE_CFG);
-	    glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG);
-
-	    configFile = null;
+		
+		configFile = new File(server_exe.getParentFile(), LLSSITE_CFG);
+		if(!configFile.exists()) { // create it from the template
+			File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in");
+		
+			// need to generate llssite_cfg from llssite_cfg_in
+			if(llssite_cfg_in.exists()) {
+				copyConfigFile(llssite_cfg_in, configFile, true);   // adjust for gli
+			}
+			else {
+				debug("File llssite.cfg.in can't be found. Can't create llssite.cfg frrom llssite.cfg.in.");				
+			}
+		}			
+		
+		// use the config file now
+	    if(configFile.exists()) {
+			// first test if server was started independently of GLI
+			// if so, the config file we'd be using would be llssite.cfg
+			if(!usingGSImode()) { // if we were using llssite_cfg, this would have loaded it in
+				// else we try using the glisite configfile
+				useGLImode();
+			}
+			
+	    } else {
+			System.err.println("**** ERROR. Configfile is null.");				
+			configFile = null;
+		}
 
 	    autoenter_initial = null;
 	    start_browser_initial = null;
-	    
-	    // first test if server was started independently of GLI
-	    // if so, the config file we'd be using would be llssite.cfg
-	    if(!usingLLS_configFile()) { // if we were using llssite_cfg, this would have loaded it in
-		// else we try using the glisite configfile
-		useGLISiteCfg(server_exe);
-	    }
 		
 		// GS2. We're in the constructor, so we'll be running the LLS the first time
@@ -733,32 +744,8 @@
 
 	/** Tries to get a glisite.cfg file and then loads it, setting it as the configFile */
-	public void useGLISiteCfg(File server_exe)
+	public void useGLImode()
 	{
-	    if(!glisite_cfg.exists()) { // create it from the templates or the llssite.cfg file
-		
-		File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in");
-		File glisite_cfg_in = new File(server_exe.getParentFile(), GLISITE_CFG+".in");
-		
-		// need to generate glisite_cfg from glisite_cfg_in, llssite_cfg or llssite.cfg.in
-		if(glisite_cfg_in.exists()) {
-		    copyConfigFile(glisite_cfg_in, glisite_cfg, false);    
-		} 
-		else if(llssite_cfg_in.exists()) { 
-		    copyConfigFile(llssite_cfg_in, glisite_cfg_in, true); // adjust for glisite.cfg
-		    copyConfigFile(glisite_cfg_in, glisite_cfg, false);    
-		}
-		else if(llssite_cfg.exists()) {
-		    copyConfigFile(llssite_cfg, glisite_cfg, true);        // adjust for glisite.cfg
-		}
-		else {
-		    debug("Neither the file glisite.cfg nor llssite.cfg can be found!");
-		}
-	    }
-	    // use the config file now
-	    if(glisite_cfg.exists()) {
-		configFile = glisite_cfg;
-		load(false); // force reload
-		lastModified = configFile.lastModified();
-	    } 
+	    isIndependentGSI = false;
+		load(true); // reload if modified 
 	}
 
@@ -770,17 +757,11 @@
 	 * and, if so, it would have loaded in the llssite_cfg configFile.
 	 */
-	public boolean usingLLS_configFile() {
-	    if(!llssite_cfg.exists()) {
-		return false;
-	    }
-
-	    // Now to check if the configfile contains the URL line
-	    configFile = llssite_cfg;
+	public boolean usingGSImode() {
+	    // Now to check if the configfile contains the GSI_URL line		
 	    load(false); // force load
-
+		isIndependentGSI = true;
 	    if(getURL() == null) {
-		configFile = null;
-		clear(); // we're not using llssite_cfg, so clear the values we just read
-		return false;
+			isIndependentGSI = false;
+			return false;
 	    }
 
@@ -797,5 +778,5 @@
 	 * In such a case, GLI would be using llssite_cfg. */
 	public boolean isIndependentGSI() {
-	    return (configFile == llssite_cfg);
+	    return isIndependentGSI;
 	}
 
@@ -832,6 +813,7 @@
 
 	public String getURL() {
+		String urlPropertyName = isIndependentGSI() ? GSI_URL : URL;
 	    // URL is made from url and portnumber
-	    String url = (String) get(URL);
+	    String url = (String) get(urlPropertyName);
 
 	    // server interface is already up, independent of GLI
@@ -928,8 +910,9 @@
 	    }
 	    else {
+		String urlPropertyName = isIndependentGSI() ? GSI_URL : URL;
 		debug("Restore Initial Settings");
 		put(AUTOENTER, autoenter_initial);
 		put(STARTBROWSER, start_browser_initial);
-		remove(URL);
+		remove(urlPropertyName);
 		save();
 	    }
@@ -956,8 +939,6 @@
 
 	private void save() {
-	    //debug("Save: " + llssite_cfg.getAbsolutePath());
 	    debug("Save: " + configFile.getAbsolutePath());
 	    try {
-		//BufferedWriter out = new BufferedWriter(new FileWriter(llssite_cfg, false));
 		BufferedWriter out = new BufferedWriter(new FileWriter(configFile, false));
 		for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
@@ -968,7 +949,7 @@
 			out.write('=');
 			
-			// if the server is using llssite.cfg, don't overwrite its default
+			// if the GSI was launched outside of GLI, don't overwrite its default
 			// autoenter and startbrowser values
-			if(configFile == llssite_cfg && (key == GSI_AUTOENTER || key == GSI_STARTBROWSER)) {
+			if(isIndependentGSI && (key == GSI_AUTOENTER || key == GSI_STARTBROWSER)) {
 			    if(key == GSI_AUTOENTER) {
 				out.write(autoenter_initial, 0, autoenter_initial.length());
@@ -994,5 +975,5 @@
 	    // dest_cfg file should not yet exist
 	    // If setToGliSiteDefaults is true, then GLIsite.cfg's default configuration 
-	    // is applied to concerned lines: autoenter=1, and startbrowser=0
+	    // is applied to concerned lines: gli.autoenter=1, and gli.startbrowser=0
 
 	    try {
