Index: /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 22805)
+++ /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 22806)
@@ -505,6 +505,6 @@
 	    // If opening a collection outside the standard GS collect folder, need
 	    // to open the non-standard collect folder that the collection resides in
-	    if (open_collection_file_path != null && 
-		!open_collection_file_path.startsWith(getCollectDirectoryPath())) {
+	    if (open_collection_file_path != null &&
+		!open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true))) {
 		File collectFolder = null;
 		if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
@@ -520,12 +520,30 @@
 		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();
-		    
-		}
-		setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder
-	    }
-	    
-	}
-	catch (Exception exception) {
+		    collectFolder = collectFolder.getParentFile();		    
+		}
+		
+		if(!isGsdlRemote && !collectFolder.exists()) {
+			// if dealing with a local server but the collectdir no longer exists, 
+			// use the default greenstone collect directory, and write that to affected files
+			open_collection_file_path = null; // no longer have an open collection from last time if coldir doesn't exist
+			
+			String defaultColDir = getDefaultGSCollectDirectoryPath(false); // no file separator at end			
+			
+			setCollectDirectoryPath(defaultColDir); // will ensure the required file separator at end
+			
+			Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
+					true, defaultColDir + File.separator);
+			
+			if(Gatherer.GS3) {	// GS2's gsdlsite.cfg was taken care of when LocalLibraryServer was started up
+								// (LocalLibraryServer would also already have set glisite.cfg to the correct collecthome)
+			    String gsdlsitecfg = Configuration.gsdl3_path + File.separator 
+					+ "WEB-INF" + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
+				Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", defaultColDir); // no file separator				
+			}
+		} else { // remote GS or collect dir exists
+			setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder			
+		}
+	}
+	} catch (Exception exception) {
 	    DebugStream.printStackTrace(exception);
 	}
@@ -715,16 +733,22 @@
 	}
 	
-	return getDefaultGSCollectDirectoryPath();
+	return getDefaultGSCollectDirectoryPath(true); // file separator appended
 	
     }
 
 	/** Returns the path of the Greenstone "collect" directory. */
-    static public String getDefaultGSCollectDirectoryPath() {
-		if (!GS3) {
-			return Configuration.gsdl_path + "collect" + File.separator;
+    static public String getDefaultGSCollectDirectoryPath(boolean appendSeparator) {
+		String colDir;
+		if (GS3) {
+			colDir = getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect";			
 		}
 		else {
-		    return getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect" + File.separator;
-		}
+		    colDir = Configuration.gsdl_path + "collect";
+		}
+		
+		if(appendSeparator) {
+			colDir += File.separator;
+		}
+		return colDir;
 	}	
 
@@ -802,7 +826,6 @@
 	}
 
-	// first save any open collection in the *old* location
+	// first save any open collection in the old location, then close it
 	if(Gatherer.c_man.getCollection() != null) {
-	    Gatherer.setCollectDirectoryPath(oldCollectPath); // go back to current collection's location
 	    Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
 	}
@@ -830,8 +853,8 @@
 	if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
 	    gsdlsitecfg = 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
 	    gsdlsitecfg = Configuration.gsdl_path + File.separator 
-		+ "cgi-bin" + File.separator + "gsdlsite.cfg";
+			+ "cgi-bin" + File.separator + "gsdlsite.cfg";
 	}
 
Index: /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 22805)
+++ /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 22806)
@@ -694,38 +694,51 @@
 	    }
 		
-		// We're in the constructor, so we'll be running the LLS the first time,  if we're 
-		// running *server.exe* and if the current collect dir at Local Lib's startup is 
-		// anything other than the default GS collect dir, then use that:
-		if (isPersistentServer) { // server.exe, so we're dealing with a local GS2
-			String collectDir = Configuration.getString("general.open_collection_gs2", true);
-
-		    // If opening a collection outside the standard GS collect folder, need
-		    // to open the non-standard collect folder that the collection resides in
-		    if (!collectDir.startsWith(Gatherer.getDefaultGSCollectDirectoryPath())) {
-				File collectFolder = null;
-				if(!collectDir.endsWith("gli.col")) { // then it's a collect folder
-				    collectFolder = new File(collectDir);
-				} else {
-				    // the filepath is a gli.col file. To get the collect folder: the 1st level
-				    // up is collection folder, 2 two levels up is the containing collect folder
-				    collectFolder = new File(collectDir).getParentFile().getParentFile();
+		// GS2. We're in the constructor, so we'll be running the LLS the first time
+		// Set the correct collectdir (from last time) before the server is started up
+		String collectDir = Configuration.getString("general.open_collection_gs2", true);
+		String defaultColDir = Gatherer.getDefaultGSCollectDirectoryPath(false); // no file separator at end
+		// If opening a collection outside the standard GS collect folder, need
+		// to open the non-standard collect folder that the collection resides in
+		if (!collectDir.startsWith(defaultColDir + File.separator)) {
+			File collectFolder = null;
+			if(!collectDir.endsWith("gli.col")) { // then it's a collect folder
+				collectFolder = new File(collectDir);
+			} else {
+				// the filepath is a gli.col file. To get the collect folder: the 1st level
+				// up is collection folder, 2 two levels up is the containing collect folder
+				collectFolder = new File(collectDir).getParentFile().getParentFile();
+			}
+
+			// Need to deal with colgroups as well: while there's an etc/collect.cfg
+			// in the current collectFolder, move one level up
+			if(new File(collectFolder.getAbsolutePath()+File.separator+Utility.CONFIG_FILE).exists()) {
+				collectFolder = collectFolder.getParentFile();			    
+			}
+			
+			// if the collectdir from last time no longer exists this time,
+			// go back to Greenstone default collect dir
+			if(collectFolder.exists()) {
+				collectDir = collectFolder.getAbsolutePath();				
+				if(collectDir.endsWith(File.separator)) {
+					collectDir = collectDir.substring(0, collectDir.length()-1); 
 				}
-
-				// Need to deal with colgroups as well: while there's an etc/collect.cfg in the current
-				// collectFolder, move one level up
-				if(new File(collectFolder.getAbsolutePath()+File.separator+Utility.CONFIG_FILE).exists()) {
-				    collectFolder = collectFolder.getParentFile();			    
-				}	
-				collectDir = collectFolder.getAbsolutePath();				
-				
-				// write out the non-standard collectDir (minus file separator at end) to the lls site conf 
-				// file being used
-				if(collectDir.endsWith(File.separator)) {
-					collectDir = collectDir.substring(0, collectDir.length()); 
-				}
+			} else {
+				collectDir = defaultColDir;				
+				// necessary for local apache web server: update gsdlsite.cfg with the reverted collectdir
+				String gsdlsitecfg = Configuration.gsdl_path + File.separator 
+					+ "cgi-bin" + File.separator + "gsdlsite.cfg";
+				Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir); // no file separator at end
+			}
+			
+			// if we're running *server.exe* and if the current collect dir at Local Lib's startup
+			// is anything other than the default GS collect dir or if we changed back to the default 
+			// collect dir because the non-standard collectDir didn't exist, then write out 
+			// the new collectDir (minus file separator at end) to the lls site conf in use
+			if (isPersistentServer) { // server.exe, so we're dealing with a local GS2			
 				put(COLLECTHOME, collectDir);
 				save();
 				lastModified = configFile.lastModified();
 			}
+			
 		} // now the correct current collect dir will get loaded when the server is started up hereafter		
 	}
