Index: /main/trunk/gli/classes/dictionary.properties
===================================================================
--- /main/trunk/gli/classes/dictionary.properties	(revision 22660)
+++ /main/trunk/gli/classes/dictionary.properties	(revision 22661)
@@ -632,4 +632,5 @@
 General.Outstanding_Processes_Title:Waiting To Exit
 General.Pure_Cancel_Tooltip:Abort this action (no changes will be made)
+General.Reconfigure:Reconfigure your web server manually
 General.Review_Output:Please review output below:
 General.Redo:Redo
@@ -1011,4 +1012,5 @@
 Server.QuitTimeOut:The greenstone local library has not responded to the\nautomatic close command for {0} seconds. Do you\nwish to wait for another {0} seconds?
 Server.StartUpTimeOut:The greenstone local library has not responded to the\nstart command for {0} seconds. Do you\nwish to wait for another {0} seconds?
+Server.Reconfigure:You just changed collecthome.\nAs GLI didn't start your webserver, it can't reconfigure this automatically.\nPlease reconfigure your server manually to work with the change to collecthome.
 #
 #***** Sources *****
Index: /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 22660)
+++ /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 22661)
@@ -829,5 +829,15 @@
 
 	// non-destructive update of gsdl(3)site.cfg (comments preserved)
-	Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", Gatherer.getCollectDirectoryPath());
+	String collectDir = Gatherer.getCollectDirectoryPath();
+	collectDir = collectDir.substring(0, collectDir.length()-1); // remove file separator at end	
+	Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir);
+
+	if(!Gatherer.GS3 && Gatherer.isLocalLibrary) {
+	    // for Images in the collection to work, the apache web server 
+	    // configuration's COLLECTHOME should be updated on collectdir change. 
+	    // Does nothing for server.exe at the moment
+
+	    LocalLibraryServer.reconfigure();
+	}
     }
 
Index: /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 22660)
+++ /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 22661)
@@ -58,4 +58,6 @@
     // The socket port number that we will use to communicate the termination
     static private int port;
+    static private Socket clientSocket = null;
+    static private Writer clientSocketWriter = null;
 
     // The server is persistent if it does not have to reload all the values
@@ -125,9 +127,13 @@
 	    
 	try {
-	    Socket clientSocket = new Socket("localhost", port);
-	    Writer writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
-	    writer.write(message);
-	    writer.close();
-	    writer = null;
+	    if(clientSocket == null) {
+		clientSocket = new Socket("localhost", port);
+	    }
+	    if(clientSocketWriter == null) {
+		clientSocketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
+	    }
+	    clientSocketWriter.write(message);
+	    clientSocketWriter.flush();
+	    
 	} catch (Exception e) {
 	    System.err.println("An exception occurred when trying to send the message: " + message 
@@ -286,4 +292,70 @@
     }
 
+    /** Call this when the collect directory has changed. Only works when using 
+     * the web server launched by GLI. */
+    static public void reconfigure() {
+	if(isPersistentServer) {
+	    System.err.println("***** Reconfigure is not yet implemented for server.exe");
+	    return;
+	}
+
+	// can't control the GSI/server if it was launched independent of GLI
+	if(llssite_cfg_file.isIndependentGSI()) {
+	    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Server.Reconfigure"), Dictionary.get("General.Reconfigure"), JOptionPane.INFORMATION_MESSAGE);
+	    return;
+	}
+
+	// someone may have closed the web server
+	if(checkServerRunning()) { // need a server to be running in order for us to send a reconfigure message to it
+	    return; // it has reconfigured and restarted the server
+	}
+
+	// If it was already running, tell the server a reconfigure is required on next restart
+	// and then restart
+	if(running && sendMessageToServer("RECONFIGURE\n")) {
+	    // restart
+	    if(running) {
+		running = false;
+
+		if(sendMessageToServer("RESTART\n")) { //if(sendMessageToServer("RECONFIGURE\n")) {
+		    // wait for the server to update the URL in the gli config file
+		    llssite_cfg_file.setLastModified();
+		    
+		    int attempt_count = 0;
+		    while (!llssite_cfg_file.isModified()) {
+			new OneSecondWait();  // Wait one second (give or take)
+			attempt_count++;
+			
+			// After waiting for the specified time, ask the user whether they want to wait for that long again
+			if (attempt_count == WAITING_TIME) {
+			    break; // can't be waiting forever, we'll be waiting again below
+			}
+		    }		    
+
+		    try {		
+			testServerRunning(); // will set running = true when the server is up and running successfully
+		    } catch (IOException bad_url_connection) {
+			try {
+			    // If this fails then we try changing the url to be localhost
+			    Configuration.library_url = new URL(llssite_cfg_file.getLocalHostURL());
+			    DebugStream.println("Try connecting to server on local host: '" + Configuration.library_url + "'");
+			    URLConnection connection = Configuration.library_url.openConnection();
+			    connection.getContent();
+			    running = true;
+			    
+			} catch (IOException worse_url_connection) {
+			    DebugStream.println("Can't connect to server on either address.");
+			    Configuration.library_url = null;
+			    running = false;
+			}
+		    }
+		} 
+	    }
+	} else {
+	    System.err.println("GLI was unable to send a reconfigure request to the local library server."
+		       + "\nPlease reconfigure and restart the local Greenstone server manually.");
+	}
+    }
+
 
     static public void stop()
@@ -303,5 +375,16 @@
 	    config(QUIT_COMMAND);
 	} else {
-	    if(sendMessageToServer("QUIT")) {
+	    boolean success = sendMessageToServer("QUIT\n");
+	    try {
+		if(clientSocketWriter != null) {
+		    clientSocketWriter.close();
+		    clientSocketWriter = null;
+		}
+		clientSocket = null;
+	    } catch(Exception e) {
+		System.err.println("An exception occurred when trying to close the socket"
+				   + "\nto the LocalLibraryServer.\n" + e);
+	    }
+	    if(success) {		
 		Gatherer.terminateApplication(ID);
 	    } else {
@@ -446,6 +529,9 @@
     }
 
-    static public void checkServerRunning() {
-	if (!running) return; // don't worry about it if it's not supposed to be running 
+    /** @returns true if it had to restart the server. Returns false if it didn't restart it. */
+    static public boolean checkServerRunning() {
+	boolean serverRestarted = false;
+
+	if (!running) return false; // don't worry about it if it's not supposed to be running 
 	llssite_cfg_file.load(true); // don't force reload, load only if modified
 	
@@ -454,5 +540,5 @@
 	    if(url.equals(LLSSiteConfig.URL_PENDING)) {
 		running = false;
-		return;
+		return false;
 	    }
 
@@ -480,9 +566,26 @@
 		    running = true;
 		}
-		return; // don't need to launch the server, one has been independently launched
+		return false; // don't need to launch the server, one has been independently launched
 	    } else {
 		// else we try using the glisite configfile
 		llssite_cfg_file.useGLISiteCfg(local_library_server_file);
 	    	//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) 
+		// will only be reinstantiated if they are first nulled
+		if(clientSocket != null) {
+		    clientSocket = null;
+		}
+		if(clientSocketWriter != null) {
+		    try{ 
+			clientSocketWriter.close();
+			clientSocketWriter = null;
+		    } catch(Exception e) {
+			System.err.println("Unable to close the client socket outputstream.");
+		    } finally {
+			clientSocketWriter = null;
+		    }
+		}
 	    
 		// Spawn local library server process
@@ -496,4 +599,5 @@
 		try {
 		    testServerRunning(); // don't return until the webserver is up and running
+		    serverRestarted = true;
 		} catch (IOException bad_url_connection) {
 		    DebugStream.println("Can't connect to server on address " + Configuration.library_url);
@@ -502,4 +606,5 @@
 	    }
 	}
+	return serverRestarted;
     }
 
@@ -645,5 +750,5 @@
 	    url.append((String)get(PORTNUMBER));
 	    String enterlib = (String)get(ENTERLIB);
-	    if(enterlib == null || enterlib.length() == 0) {
+	    if(!isPersistentServer || enterlib == null || enterlib.length() == 0) {
 		// Use the default /gsdl and hope for the best.
 		url.append(SEPARATOR);
@@ -702,4 +807,10 @@
 	    debug("Found Local Library Address: " + url);
 	    return url;
+	}
+
+	public void setLastModified() {
+	    if(isModified()) {
+		lastModified = configFile.lastModified();
+	    } 
 	}
 
