Index: /main/trunk/gli/classes/dictionary.properties
===================================================================
--- /main/trunk/gli/classes/dictionary.properties	(revision 23142)
+++ /main/trunk/gli/classes/dictionary.properties	(revision 23143)
@@ -710,4 +710,14 @@
 GUI.Gather:Gather
 GUI.Gather_Tooltip:Select the files to include in your collection
+GUI.CollectHome.title:The collect directory has changed
+GUI.CollectHome.message:The collect directory value has been changed from:
+GUI.CollectHome.to:to:
+GUI.CollectHome.dir:{0}
+GUI.CollectHome.gli:Do you want the Librarian Interface to remember the new collect directory?
+GUI.CollectHome.server:Do you want the Greenstone Server to remember the new collect directory?
+GUI.CollectHome.resetToDefault:No, reset to default
+GUI.CollectHome.leaveAtDefault:No, leave at default
+GUI.CollectHome.reset:Reset to default
+
 #***************
 #
Index: /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 23142)
+++ /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 23143)
@@ -102,4 +102,5 @@
     static private String non_standard_collect_directory_path = null;
     static public String open_collection_file_path = null;
+	static public String gsdlsite_collecthome = "";
     /** A public reference to the FileAssociationManager. */
     static public FileAssociationManager assoc_man;
@@ -315,7 +316,7 @@
 	    if (fedora_info.isActive()) {
 		popupFedoraInfo();
-	    }	
-
+	    }
 		
+		// the no_load flag to GLI is processed at the end of handling open_collection_file_path
 		open_collection_file_path = open_collection;
 		if (open_collection_file_path == null) {
@@ -323,62 +324,9 @@
 				"general.open_collection"+Configuration.gliPropertyNameSuffix(), true);
 		}
+		
+		initCollectDirectoryPath(open_collection); 
+		
 		if (no_load || (isGsdlRemote && open_collection_file_path.equals(""))) {
 		open_collection_file_path = null;
-		//		collectDirectoryHasChanged(); // make sure gsdlsite.cfg's collecthome defaults to GS' collect
-		}
-		
-		// If opening a collection outside the standard GS collect folder, need
-	    // to open the non-standard collect folder that the collection resides in
-	    if (!isGsdlRemote
-			&& open_collection_file_path != null
-			&& !open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true)))
-		{
-			File collectFolder = null;
-			
-			if(!open_collection_file_path.equals("")) {
-			
-				if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
-				    collectFolder = new File(open_collection_file_path);
-				} 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(open_collection_file_path).getParentFile().getParentFile();
-				}	
-			
-				// Need to deal with colgroups as well: while there's an etc/collect.cfg in the current
-				// collectFolder, move one level up
-				String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
-				if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
-				    collectFolder = collectFolder.getParentFile();		    
-				}
-			}
-			
-			if(collectFolder == null || !collectFolder.exists()) {
-				// if GLI config file specified no collectDir  (open_collection_file_path is "")
-				// OR if dealing with a local server but the collectdir no longer exists, 
-				// use the default greenstone collect directory, and write that to affected files
-				
-				String defaultColDir = getDefaultGSCollectDirectoryPath(false); // no file separator at end
-				open_collection_file_path = defaultColDir;
-				
-				setCollectDirectoryPath(defaultColDir); // will ensure the required file separator at end
-				
-				Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
-						true, "");
-				
-				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
-							// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
-				}
-			} else { // remote GS, or collect dir exists (all config files will already be set since last GLI session)
-				if(collectFolder == null) {
-					setCollectDirectoryPath(getDefaultGSCollectDirectoryPath(false)); // no file separator at end
-				} else {
-					setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder
-				}					
-			}			
 		}
 		
@@ -711,7 +659,7 @@
 	// Flush debug
 	DebugStream.closeDebugStream();
-
+	
 	// If we started a server, we should try to stop it.
-	if (LocalLibraryServer.isRunning() == true) {
+	if (LocalLibraryServer.isRunning() == true) {		
 	    LocalLibraryServer.stop();
 	}
@@ -751,4 +699,9 @@
 	
     }
+	
+	// if we need to know whether the local server we are running is server.exe vs apache web server
+	static public boolean isPersistentServer() {
+		return (!isGsdlRemote && LocalLibraryServer.isPersistentServer());
+	}
 
 	/** Returns the path of the Greenstone "collect" directory. */
@@ -835,4 +788,72 @@
     }
 
+
+	public static void initCollectDirectoryPath(String open_collection) {		
+		String defaultColdir = getDefaultGSCollectDirectoryPath(false); // no file separator at end
+		String coldir = defaultColdir;
+		// If local GS and opening a collection outside the standard GS collect folder,
+	    // need to open the non-standard collect folder that the collection resides in
+	    if (!isGsdlRemote 
+				&& !open_collection_file_path.startsWith(defaultColdir))
+		{
+			File collectFolder = null;
+			
+			if(!open_collection_file_path.equals("")) {			
+				if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
+				    collectFolder = new File(open_collection_file_path);
+				} else {
+				    // the filepath is a gli.col file. To get the collect folder: the 1st level up
+				    // is the collection folder, 2 two levels up is the containing collect folder
+				    collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
+				}	
+			
+				// Need to deal with colgroups as well: while there's an etc/collect.cfg
+				// in the current collectFolder, move one level up
+				String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
+				if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
+				    collectFolder = collectFolder.getParentFile();		    
+				}
+			}		
+			
+			if(collectFolder == null || !collectFolder.exists()) {
+				// if GLI config file specified no collectDir (open_collection_file_path is "")
+				// OR 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 = defaultColdir;		// default GS collect dir
+				// Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, "");
+			} else { // use the coldir value specified in the flags to GLI or from the last GLI session				
+				coldir = collectFolder.getAbsolutePath();
+			}			
+			// set it as the current folder
+			setCollectDirectoryPath(coldir); // will ensure the required file separator at end
+		}
+		
+		if(!isGsdlRemote) {
+			// LocalLibraryServer would  already have set glisite.cfg to the correct collecthome for server.exe
+			// Here we set collecthome in gsdl(3)site.cfg for the GS2 apache web server and GS3 tomcat server
+			String gsdlsitecfg = getGsdlSiteConfigFile();			
+			// update the gsdlsite config file and store the old value for use when we exit GLI
+			if(coldir.equals(defaultColdir)) {				
+				gsdlsite_collecthome = Utility.updatePropertyConfigFile(
+					gsdlsitecfg, "collecthome", null);						
+			} else {
+				gsdlsite_collecthome = Utility.updatePropertyConfigFile(
+					gsdlsitecfg, "collecthome", coldir); // no file separator
+					// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
+			}
+		}		
+	}
+   
+    /** depending on the version of GS being run, return the path to the current GS' installation's gsdl(3)site.cfg */
+    public static String getGsdlSiteConfigFile() {
+		if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
+			return Configuration.gsdl3_path + File.separator + "WEB-INF" 
+				+ File.separator + "cgi" + File.separator + "gsdl3site.cfg";
+		} else { // cgi-bin/gsdlsite.cfg
+			return Configuration.gsdl_path + File.separator 
+				+ "cgi-bin" + File.separator + "gsdlsite.cfg";
+		}
+    }
 
     public static void collectDirectoryHasChanged(
@@ -885,19 +906,10 @@
 			    return;
 			}	
-
-			String gsdlsitecfg = "";
-			if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
-			    gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF" 
-					+ File.separator + "cgi" + File.separator + "gsdl3site.cfg";
-			} else { // cgi-bin/gsdlsite.cfg
-			    gsdlsitecfg = Configuration.gsdl_path + File.separator 
-					+ "cgi-bin" + File.separator + "gsdlsite.cfg";
-			}
-
+			
 			// non-destructive update of gsdl(3)site.cfg (comments preserved)
 			String collectDir = Gatherer.getCollectDirectoryPath();
 			//collectDir = "\"" + collectDir.substring(0, collectDir.length()-1) + "\""; // remove file separator at end	
 			collectDir = collectDir.substring(0, collectDir.length()-1); // remove file separator at end	
-			Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir);
+			Utility.updatePropertyConfigFile(getGsdlSiteConfigFile(), "collecthome", collectDir);
 					// if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
 			
Index: /main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 23142)
+++ /main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 23143)
@@ -1558,10 +1558,9 @@
     public void openCollectionFromLastTime() {
       // If there was an open collection last session, reopen it. 
-	  // Skip if there was none or only a collect folder instead of any previously-opened collection	  
-      if (Gatherer.open_collection_file_path != null 
-			&& !(new File(Gatherer.open_collection_file_path).isDirectory())) {
-		 // Load the collection now
-		 loadCollection(Gatherer.open_collection_file_path);
-      }
+	  // (this method doesn't get called if there was no open collection or only a collect folder 
+	  // instead of any previously-opened collection)
+	  
+		// Load the collection now
+		loadCollection(Gatherer.open_collection_file_path);      
     }
 
Index: /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 23142)
+++ /main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java	(revision 23143)
@@ -70,4 +70,8 @@
     static private boolean isPersistentServer = false;
 
+	static public boolean isPersistentServer() {
+		return isPersistentServer;
+	}
+	
     static public void addCollection(String collection_name)
     {
@@ -395,5 +399,5 @@
 	if (isPersistentServer) {
 	    config(QUIT_COMMAND);
-	} else {
+	} else {		
 	    boolean success = sendMessageToServer("QUIT\n");
 	    try {
@@ -697,22 +701,14 @@
 		// Set the correct collectdir (from last time) before the server is started up
 		
-		//String collectDir = Configuration.getString("general.open_collection_gs2", true);
 		String orig_collection_path = Configuration.getString("general.open_collection_gs2", true);
-		String collectDir = Gatherer.getCollectDirectoryPath();
+		String collectDir = Gatherer.getCollectDirectoryPath();					// Gatherer would've set this up
 		String defaultColDir = Gatherer.getDefaultGSCollectDirectoryPath(true); // with 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.
-		// Also, would have been forced to change the loaded collection--and hence collectDir--
-		// to the default coldir if orig_col_path was "" or led to a collectdir that didn't exist
-		// (in the last case, gsdlsite.cfg already corrected in Gatherer if coldir was changed).	
-		
+				
 		if(orig_collection_path.equals("")) { // default GS collect dir path
 			return;
 		}
 		
-		if (Gatherer.open_collection_file_path != null // may be null if no_load was specified on GLI startup			
-			&& (!orig_collection_path.startsWith(collectDir) // if coldir would've been changed on startup OR if coldir is non-standard collect folder
-				|| !collectDir.equals(defaultColDir))) 
+		if (!orig_collection_path.startsWith(collectDir) // if coldir would've been changed on startup OR if coldir is non-standard collect folder
+				|| !collectDir.equals(defaultColDir))
 		{			
 			// if we're running *server.exe* and if the current collect dir at Local Lib's startup is
@@ -720,4 +716,5 @@
 			// dir because the non-standard collectDir didn't exist/wasn't specified in the GLI config
 			// file, then write out the new collectDir (minus file separator at end) to the lls site conf in use
+			// Regardless of what collecthome value was in the llssite/glisite file, we end up resetting it here
 			if (isPersistentServer) { // server.exe, so we're dealing with a local GS2			
 				put(COLLECTHOME, collectDir);
Index: /main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java	(revision 23142)
+++ /main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java	(revision 23143)
@@ -104,8 +104,4 @@
     private TabUpdater tab_updater = null;
 
-
-
-
-
   final static String newline = "\n";
     final static String space = "    ";
@@ -502,4 +498,5 @@
     public void exit(int exit_status)
     {
+	boolean collection_open = false;
 	// If we have a collection open remember it for next time, then save it and close it
 	if (Gatherer.c_man.ready()) {
@@ -515,4 +512,5 @@
 		}
 	    saveThenCloseCurrentCollection();
+		collection_open = true;
 	}
 	else {
@@ -528,4 +526,38 @@
 		}
 	}
+	
+	
+	// Basically, if GLI coldir != gsdlsite_colhome, we ask them if they want to save GLI coldir as gsdlsite_colhome
+	// If gsdlsite_colhome = "" (meaning default GS coldir) and GLI is also set to defaultGScoldir, no saving necessary.
+	// We ONLY do this for the local included apache web server, since the issue revolves around gsdlsite.cfg containing
+	// the global collecthome when using the apache web server. This is not an issue for remote GS or server.exe (the latter
+	// has separate config files specifying collecthome for when GLI is running whereas when just the server.exe is running).
+	if(!Gatherer.isGsdlRemote && !Gatherer.isPersistentServer()) {		
+	
+		String defaultColDir = Gatherer.getDefaultGSCollectDirectoryPath(false); // no filesep at end
+		String gliColDir = Gatherer.getCollectDirectoryPath();
+		String serverColDir = Gatherer.gsdlsite_collecthome;
+		
+		boolean showSettingsDlg = true;
+		// if collectdir was changed during GLI session (to something different from what's in gsdlsite), need to ask what to store
+		if(gliColDir.equals(Gatherer.gsdlsite_collecthome+File.separator)) {	
+			showSettingsDlg = false;
+		} else if(Gatherer.gsdlsite_collecthome.equals("") // both set to default coldir
+				&& gliColDir.equals(defaultColDir+File.separator)) {
+			showSettingsDlg = false;
+		} 
+		if(showSettingsDlg) {
+			
+			// else we will be showing the Collect Directory Settings Dialog
+			if(gliColDir.endsWith(File.separator)) {
+				gliColDir = gliColDir.substring(0, gliColDir.length()-1);
+			}
+			
+			if(serverColDir.equals("")) {
+				serverColDir = defaultColDir;
+			}	
+			collectDirSettingsDialog(defaultColDir, serverColDir, gliColDir, collection_open);
+		}
+	}
 
 	// Store the current position and size of the GLI for next time
@@ -544,4 +576,141 @@
     }
 
+	public void collectDirSettingsDialog(final String defaultColDir,
+		final String from, final String to, final boolean collection_open) 
+	{	
+		final JDialog colHomeDialog 
+			= new JDialog(this, Dictionary.get("GUI.CollectHome.title"), true); // this = Gatherer.g_man
+		colHomeDialog.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+		
+		
+		JRadioButton gliYes = new JRadioButton(Dictionary.get("General.Yes"), true);
+						// the default selection for GLI, collecthome=to
+		JRadioButton serverYes = new JRadioButton(Dictionary.get("General.Yes")); // not selected for the server		
+		JRadioButton gliNo = null;
+		JRadioButton gliThirdOption = null;
+		JRadioButton serverNo = null;
+		JRadioButton serverThirdOption = null;
+		
+		if(from.equals(defaultColDir)) { 
+			gliNo = new JRadioButton(Dictionary.get("GUI.CollectHome.resetToDefault"));
+			serverNo = new JRadioButton(Dictionary.get("GUI.CollectHome.leaveAtDefault"), true);
+						// default selection for server, collecthome=from
+		} else {
+			gliNo = new JRadioButton(Dictionary.get("General.No"));
+			serverNo = new JRadioButton(Dictionary.get("General.No"), true); // default selection for server 
+			if(!to.equals(defaultColDir)) { // neither from nor to is the default GS collect dir, so give them that as the third option
+				gliThirdOption = new JRadioButton(Dictionary.get("GUI.CollectHome.reset"));
+				serverThirdOption = new JRadioButton(Dictionary.get("GUI.CollectHome.reset"));		
+			}
+		}
+		
+		JPanel gliPanel = new JPanel(); // flowlayout by default
+		ButtonGroup gliGroup = new ButtonGroup();
+		JPanel serverPanel = new JPanel(); // flowlayout by default
+		ButtonGroup serverGroup = new ButtonGroup();
+		
+		gliGroup.add(gliYes);
+		gliPanel.add(gliYes);
+		serverGroup.add(serverYes);
+		serverPanel.add(serverYes);		
+		
+		gliGroup.add(gliNo);
+		gliPanel.add(gliNo);
+		serverGroup.add(serverNo);
+		serverPanel.add(serverNo);
+			
+		if(gliThirdOption != null) {
+			gliThirdOption = new JRadioButton("Reset to default");
+			serverThirdOption = new JRadioButton("Reset to default");
+			
+			gliGroup.add(gliThirdOption);
+			gliPanel.add(gliThirdOption);
+			serverGroup.add(serverThirdOption);
+			serverPanel.add(serverThirdOption);
+		}
+		
+		// vars need to be final to use them in the actionlistener below
+		final JRadioButton gli_yes = gliYes;
+		final JRadioButton gli_no = gliNo;
+		final JRadioButton gli_optional = gliThirdOption;
+		final JRadioButton server_yes = serverYes;
+		final JRadioButton server_no = serverNo;
+		final JRadioButton server_optional = serverThirdOption;
+		
+		JButton okButton = new JButton(Dictionary.get("General.OK"));
+		okButton.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				// store the option chosen for GLI
+				String gliColDir = to;	
+				if(gli_optional != null && gli_optional.isSelected()) {
+					// defaultColDir
+					gliColDir = "";
+				} else if(gli_yes.isSelected()) {
+					gliColDir = to;
+				} else if (gli_no.isSelected()) {
+					gliColDir = from;
+				}
+				if(defaultColDir.equals(gliColDir)) {
+					gliColDir = "";
+				}
+				if(!(collection_open && gli_yes.isSelected())) { // don't overwrite open collections
+					Configuration.setString(
+						"general.open_collection"+Configuration.gliPropertyNameSuffix(), 
+						true, gliColDir);
+				}
+				
+				// store the option chosen for the server's settings
+				String serverColDir = from;
+				if(server_optional != null && server_optional.isSelected()) {
+					// defaultColDir
+					serverColDir = null;
+				} else if(server_yes.isSelected()) {
+					serverColDir = to;
+				} else if (server_no.isSelected()) {
+					serverColDir = from;
+				}
+				if(serverColDir != null && defaultColDir.equals(serverColDir)) {					
+					serverColDir = null;
+				}
+								
+				Gatherer.gsdlsite_collecthome = Utility.updatePropertyConfigFile(
+					Gatherer.getGsdlSiteConfigFile(), "collecthome", serverColDir);	
+				
+				colHomeDialog.dispose();
+			}
+		});
+		
+		//String[] dirs = {from, to};		
+		//JLabel message = new JLabel(Dictionary.get("GUI.CollectHome.message", dirs));
+		JLabel message = new JLabel(Dictionary.get("GUI.CollectHome.message"));
+		JLabel fromDirLine = new JLabel(Dictionary.get("GUI.CollectHome.dir", from));
+		fromDirLine.setBorder(BorderFactory.createEmptyBorder(0,25,0,0)); // padding
+		JLabel toLine = new JLabel(Dictionary.get("GUI.CollectHome.to"));
+		JLabel toDirLine = new JLabel(Dictionary.get("GUI.CollectHome.dir", to));
+		toDirLine.setBorder(BorderFactory.createEmptyBorder(0,25,0,0)); // padding
+		JLabel gliOption = new JLabel(Dictionary.get("GUI.CollectHome.gli"));
+		JLabel serverOption = new JLabel(Dictionary.get("GUI.CollectHome.server"));		
+		
+		JPanel mainPanel = new JPanel();
+		mainPanel.setLayout(new GridLayout(9, 1));
+		mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); // padding
+		mainPanel.add(message);
+		mainPanel.add(fromDirLine);		
+		mainPanel.add(toLine);
+		mainPanel.add(toDirLine);
+		mainPanel.add(gliOption);
+		mainPanel.add(gliPanel);
+		mainPanel.add(serverOption);
+		mainPanel.add(serverPanel);
+		mainPanel.add(okButton);		
+		Container c = colHomeDialog.getContentPane();
+		c.setLayout(new BorderLayout());
+		c.add(mainPanel, BorderLayout.CENTER);
+		colHomeDialog.getRootPane().setDefaultButton(okButton);
+		
+		colHomeDialog.pack();
+		colHomeDialog.setVisible(true);
+	}
+	
 
     /** This method is called when the collection is being built, and is used to disable all controls in all pane which could change the state of the collection.
Index: /main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java	(revision 23142)
+++ /main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java	(revision 23143)
@@ -461,23 +461,31 @@
 
     
-    /** Write out a property line--a (property, value) pair--to the gsdl(3)site.cfg file.
+  /** Write out a property line--a (property, value) pair--to the gsdl(3)site.cfg file.
      * If the file already contains the line as-is, it is not re-written.	
      * If the file doesn't contain the line, it is appended.
      * If the file contained a different value for the property, the line is corrected
      * and the file is written out.
+     * If the propertyValue parameter is null, the property line is removed from the file.
      * Not using the Properties class, as we want to keep the file's contents in the 
      * same order and preserve all the comments in as they're meant to help the user.
-     */
-    public static void updatePropertyConfigFile(String filename, String propertyName, String propertyValue) {
+     * Return the old value for the property, if it existed, else "".	 
+     */
+    public static String updatePropertyConfigFile(
+		String filename, String propertyName, String propertyValue) 
+	{	
 	File propFile = new File(filename);
+	String oldValue = "";
 	if(!propFile.exists()) {
 		System.err.println("*** Unable to update property " + propertyName + " in file " 
 				+ filename + "to\n" + propertyValue + ". File does not exist.\n");
-		return;
+		return oldValue;
 	}	
 	BufferedReader fin = null;
 	BufferedWriter fout = null;
 	StringBuffer contents = new StringBuffer();
-	String insertLine = propertyName+"\t"+propertyValue+"\n"; // new line after every propertyLine
+	String insertLine = null;
+	if(propertyValue != null) {
+		insertLine = propertyName+"\t"+propertyValue+"\n"; // new line after every propertyLine
+	}
 	boolean found = false;
 	try {
@@ -485,36 +493,44 @@
 	    String line = "";
 	    while((line = fin.readLine()) != null) {
-		if(line.startsWith(propertyName)) { // won't match comment
-		    found = true;
-		    if(line.equals(insertLine)) { // file is already correct, nothing to do
+			line = line.trim(); // remove any preceding (surrounding) whitespace
+			if(line.startsWith(propertyName)) { // won't match comment
+			    found = true;
+				// store the previous value for the property
+				oldValue = line;
+				oldValue = oldValue.substring(propertyName.length());
+				oldValue = oldValue.trim();
+				
+				if(propertyValue != null) { // line should be removed if propertyValue == null
+				    if(line.equals(insertLine)) { // file is already correct, nothing to do
+						fin.close();
+						fin = null;
+						break;
+				    } else {
+						contents.append(insertLine);
+				    }
+				}
+			} else { // any other line
+			    contents.append(line);		    
+			    contents.append("\n"); // ensures the required new line at end of file
+			}
+	    }		
+
+	    if(fin != null) { // need to write something out to the file
 			fin.close();
 			fin = null;
-			break;
-		    } else {
-			contents.append(insertLine);
-		    }
-
-		} else { // any other line
-		    contents.append(line);		    
-		    contents.append("\n"); // ensures the required new line at end of file
-		}
-	    }
-
-	    if(fin != null) { // need to write something out to the file
-		fin.close();
-		fin = null;
-
-		// if collecthome wasn't already specified in the file, append it
-		if(!found) { 
-		    fout = new BufferedWriter(new FileWriter(filename, true)); // append mode
-		    fout.write(insertLine, 0, insertLine.length());
-		} else {
-		    
-		    fout = new BufferedWriter(new FileWriter(filename)); // hopefully this will overwrite
-		    fout.write(contents.toString(), 0, contents.length());
-		}
-
-		fout.close();
-		fout = null;
+
+			// if collecthome/property wasn't already specified in the file, append it
+			// but only if we have a value to write out to the file
+			if(!found && propertyValue != null) {		
+				fout = new BufferedWriter(new FileWriter(filename, true)); // append mode
+				fout.write(insertLine, 0, insertLine.length());
+			} else {		    
+				fout = new BufferedWriter(new FileWriter(filename)); // hopefully this will overwrite
+				fout.write(contents.toString(), 0, contents.length());
+			}
+
+			fout.close();
+			fout = null;
+			
 	    } // else the file is fine
 	} catch(IOException e) {
@@ -538,6 +554,5 @@
 	    
 	}
-	
-    }
-   
+		return oldValue;
+    }
 }
