Index: /gli/trunk/src/org/greenstone/gatherer/collection/CollectionManager.java
===================================================================
--- /gli/trunk/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 16249)
+++ /gli/trunk/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 16250)
@@ -557,13 +557,128 @@
 	    collection.import_options.setValue("removeold", true, null);
 
-	    //try to obtain email address of collection owner if it exists... 
-	    String stmp = Configuration.getEmail(); 
-	    if(stmp != null) {
-		collection.schedule_options.setValue("toaddr", false, Configuration.getEmail());
-	    }
-
-	    //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender". 
-	    File mcfg = new File(LocalGreenstone.getDirectoryPath()+"etc" + File.separator + "main.cfg");
-	    BufferedReader maincfg = new BufferedReader(new FileReader(mcfg)); 	    
+	    // for remote case, scheduling causes an Exception on creating a new collection that 
+	    // can't be recovered from. 
+	    if (!Gatherer.isGsdlRemote) {
+		scheduling();
+	    }
+	    	    
+	    MetadataSetManager.clearMetadataSets();
+	    MetadataXMLFileManager.clearMetadataXMLFiles();
+	    DocXMLFileManager.clearDocXMLFiles();
+
+	    // Import default metadata sets, if any
+	    // for (int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) {
+	    // importMetadataSet((MetadataSet) metadata_sets.get(i));
+	    // }
+
+	    ProfileXMLFileManager.loadProfileXMLFile(new File(collection_directory_path + "metadata"));
+
+	    // Before creating the CollectionDesignManager check if we are basing it upon some other collection
+	    if (base_collection_directory != null) {
+		DebugStream.println("Basing new collection on existing one: " + base_collection_directory);
+
+		// If we're using a remote Greenstone server, download the collection shell to get the files needed
+		if (Gatherer.isGsdlRemote) {
+		    String base_collection_name = base_collection_directory.getName();
+		    RemoteGreenstoneServer.downloadCollection(base_collection_name);
+		}
+
+		collection.setBaseCollection(base_collection_directory.getAbsolutePath());
+		// copy over other needed directories
+		copyExtraBaseCollStuff(new File(collection_directory_path), base_collection_directory);
+
+		// Try to import any existing metadata sets for this collection
+		// Look in base_collection_directory/metadata and import any metadata sets found.
+		File base_metadata_directory = new File(base_collection_directory, "metadata");
+		ArrayList base_metadata_sets = MetadataSetManager.listMetadataSets(base_metadata_directory);
+		if (base_metadata_sets != null) {
+		    for (int i = 0; i < base_metadata_sets.size(); i++) {
+			importMetadataSet((MetadataSet) base_metadata_sets.get(i));
+		    }
+		}
+		else {
+		    DebugStream.println("This base collection has no metadata directory.");
+		}
+
+		// Now we update our collect.cfg
+		DebugStream.println("Copy and update " + file_name + " from base collection.");
+
+		if (Gatherer.GS3 == true) {
+		    updateCollectionConfigXML(new File(base_collection_directory, Utility.CONFIG_GS3_FILE),
+					new File(collection_directory_path, Utility.CONFIG_GS3_FILE)); 
+		} else {
+		    updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE),
+					new File(collection_directory_path, Utility.CONFIG_FILE),
+					description, email, title);
+		}
+	    }
+
+	    // Load the default metadata sets
+	    addDefaultMetadataSets();
+
+	    // Make sure we always have the extracted metadata set
+	    addRequiredMetadataSets();
+
+	    collection.cdm = new CollectionDesignManager(new File(getLoadedCollectionCfgFilePath()));
+
+	    // We always set title and description here rather than calling mkcol.pl with Unicode arguments
+	    CollectionMeta collection_name_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
+	    collection_name_collectionmeta.setValue(title);
+	    CollectionMeta collection_extra_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
+	    collection_extra_collectionmeta.setValue(description);
+
+	    // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically. This update is done to the internal xml structure which may be saved into collect.cfg or collectionConfig.xml accordingly.
+	    if (base_collection_directory != null) {
+		// Update the creator and maintainer
+		CollectionMeta creator_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getCreator());
+		creator_collectionmeta.setValue(email);
+		creator_collectionmeta = null;
+		CollectionMeta maintainer_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getMaintainer());
+		maintainer_collectionmeta.setValue(email);
+		maintainer_collectionmeta = null;
+
+		// All collections based on others are automatically public
+		CollectionMeta public_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getPublic());
+		public_collectionmeta.setValue(StaticStrings.TRUE_STR);
+		public_collectionmeta = null;
+
+		// Finally reset the icons
+		CollectionMeta icon_collection_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR);
+		icon_collection_collectionmeta.setValue(StaticStrings.EMPTY_STR);
+		icon_collection_collectionmeta = null;
+		CollectionMeta icon_collection_small_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
+		icon_collection_small_collectionmeta.setValue(StaticStrings.EMPTY_STR);
+		icon_collection_small_collectionmeta = null;
+	    }
+
+	    saveCollection();
+
+	    // Create a lock file
+	    createLockFile(new File(collection_directory_path, LOCK_FILE));
+
+	    // We're done. Let everyone know.
+	    Gatherer.refresh(Gatherer.COLLECTION_OPENED);
+	}
+	catch (Exception error) {
+	    DebugStream.printStackTrace(error);
+	}
+    }
+
+    private void scheduling() 
+	throws Exception
+    {
+	//try to obtain email address of collection owner if it exists... 
+	String stmp = Configuration.getEmail(); 
+	if(stmp != null) {
+	    collection.schedule_options.setValue("toaddr", false, Configuration.getEmail());
+	}
+	
+	//The next few items deal with updating the SMTP server, and the to: and from: addresses
+	//from main.cfg and the collection configuration. if no changes are made, or the 
+	//values are result to NULL, any existing values are kept. 
+
+	//try to obtain email address of Greenstone installation webmaster for - used to indicate "sender". 
+	File mcfg = new File(LocalGreenstone.getDirectoryPath() + File.separator + "etc" + File.separator + "main.cfg");
+	BufferedReader maincfg = new BufferedReader(new FileReader(mcfg)); 	    
 	    stmp = "";
 	    String fromaddr = ""; 
@@ -598,5 +713,5 @@
             maincfg.close();
 
-            //try if lookup failes
+            //try if lookup fails
             if(smtptmp.equals("NULL") || smtptmp.equals("null")) {
 		String email2=fromaddr; 
@@ -611,104 +726,4 @@
 	    }
 
-	    MetadataSetManager.clearMetadataSets();
-	    MetadataXMLFileManager.clearMetadataXMLFiles();
-	    DocXMLFileManager.clearDocXMLFiles();
-
-	    // Import default metadata sets, if any
-	    // for (int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) {
-	    // importMetadataSet((MetadataSet) metadata_sets.get(i));
-	    // }
-
-	    ProfileXMLFileManager.loadProfileXMLFile(new File(collection_directory_path + "metadata"));
-
-	    // Before creating the CollectionDesignManager check if we are basing it upon some other collection
-	    if (base_collection_directory != null) {
-		DebugStream.println("Basing new collection on existing one: " + base_collection_directory);
-
-		// If we're using a remote Greenstone server, download the collection shell to get the files needed
-		if (Gatherer.isGsdlRemote) {
-		    String base_collection_name = base_collection_directory.getName();
-		    RemoteGreenstoneServer.downloadCollection(base_collection_name);
-		}
-
-		collection.setBaseCollection(base_collection_directory.getAbsolutePath());
-		// copy over other needed directories
-		copyExtraBaseCollStuff(new File(collection_directory_path), base_collection_directory);
-
-		// Try to import any existing metadata sets for this collection
-		// Look in base_collection_directory/metadata and import any metadata sets found.
-		File base_metadata_directory = new File(base_collection_directory, "metadata");
-		ArrayList base_metadata_sets = MetadataSetManager.listMetadataSets(base_metadata_directory);
-		if (base_metadata_sets != null) {
-		    for (int i = 0; i < base_metadata_sets.size(); i++) {
-			importMetadataSet((MetadataSet) base_metadata_sets.get(i));
-		    }
-		}
-		else {
-		    DebugStream.println("This base collection has no metadata directory.");
-		}
-
-		// Now we update our collect.cfg
-		DebugStream.println("Copy and update " + file_name + " from base collection.");
-
-		if (Gatherer.GS3 == true) {
-		    updateCollectionConfigXML(new File(base_collection_directory, Utility.CONFIG_GS3_FILE),
-					new File(collection_directory_path, Utility.CONFIG_GS3_FILE)); 
-		} else {
-		    updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE),
-					new File(collection_directory_path, Utility.CONFIG_FILE),
-					description, email, title);
-		}
-	    }
-
-	    // Load the default metadata sets
-	    addDefaultMetadataSets();
-
-	    // Make sure we always have the extracted metadata set
-	    addRequiredMetadataSets();
-
-	    collection.cdm = new CollectionDesignManager(new File(getLoadedCollectionCfgFilePath()));
-
-	    // We always set title and description here rather than calling mkcol.pl with Unicode arguments
-	    CollectionMeta collection_name_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
-	    collection_name_collectionmeta.setValue(title);
-	    CollectionMeta collection_extra_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
-	    collection_extra_collectionmeta.setValue(description);
-
-	    // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically. This update is done to the internal xml structure which may be saved into collect.cfg or collectionConfig.xml accordingly.
-	    if (base_collection_directory != null) {
-		// Update the creator and maintainer
-		CollectionMeta creator_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getCreator());
-		creator_collectionmeta.setValue(email);
-		creator_collectionmeta = null;
-		CollectionMeta maintainer_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getMaintainer());
-		maintainer_collectionmeta.setValue(email);
-		maintainer_collectionmeta = null;
-
-		// All collections based on others are automatically public
-		CollectionMeta public_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getPublic());
-		public_collectionmeta.setValue(StaticStrings.TRUE_STR);
-		public_collectionmeta = null;
-
-		// Finally reset the icons
-		CollectionMeta icon_collection_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR);
-		icon_collection_collectionmeta.setValue(StaticStrings.EMPTY_STR);
-		icon_collection_collectionmeta = null;
-		CollectionMeta icon_collection_small_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
-		icon_collection_small_collectionmeta.setValue(StaticStrings.EMPTY_STR);
-		icon_collection_small_collectionmeta = null;
-	    }
-
-	    saveCollection();
-
-	    // Create a lock file
-	    createLockFile(new File(collection_directory_path, LOCK_FILE));
-
-	    // We're done. Let everyone know.
-	    Gatherer.refresh(Gatherer.COLLECTION_OPENED);
-	}
-	catch (Exception error) {
-	    DebugStream.printStackTrace(error);
-	}
     }
 
@@ -1198,136 +1213,78 @@
 		return;
 	    }
-
-	    //THIS LOOKS LIKE THE BEST PLACE TO TRY AND UPDATE .col FILES FOR EXISTING COLLECTIONS...Wendy
+	    
+	    if (!Gatherer.isGsdlRemote) {
+		//THIS LOOKS LIKE THE BEST PLACE TO TRY AND UPDATE .col FILES FOR EXISTING COLLECTIONS...Wendy
  
-	    //First, see if "Schedule" exists in the XMl File... 
-	    BufferedReader bir = new BufferedReader(new FileReader(collection_file)); 
-	    boolean flag = false; 
-	    try {
-		String stmp = new String(); 
+		//First, see if "Schedule" exists in the XMl File... 
+		BufferedReader bir = new BufferedReader(new FileReader(collection_file)); 
+		boolean flag = false; 
+		try {
+		    String stmp = new String(); 
 	       
-		while((stmp = bir.readLine()) != null) {
-		    stmp = stmp.trim();  
-		    if(stmp.equals("<Schedule>") || stmp.equals("<Schedule/>")) {
-		       flag = true; 
-		       break; 
+		    while((stmp = bir.readLine()) != null) {
+			stmp = stmp.trim();  
+			if(stmp.equals("<Schedule>") || stmp.equals("<Schedule/>")) {
+			    flag = true; 
+			    break; 
+			}
 		    }
-		}
-		bir.close(); 
-
-	    } catch (IOException ioe) {
-		//do something here
-	    }
-
-	    //modify if old .col (i.e. no Schedule exists in XML file)
-	    if(!flag) {
-		File new_collection_file = new File(collection_directory.getAbsolutePath() + "/tmp.col");
-
-
-		BufferedWriter bor = new BufferedWriter(new FileWriter(new_collection_file)); 
-		bir = new BufferedReader(new FileReader(collection_file)); 
-
-		try { 
-		    String stmp = new String(); 
-		    while((stmp = bir.readLine()) != null) {
-			String stmp2 = stmp.trim(); 
-			if(stmp2.startsWith("<!ELEMENT Argument")) {
-			    bor.write("  <!ELEMENT Schedule          (Arguments*)>\n"); 			   
-		        }
-                        else if(stmp2.equals("</BuildConfig>")) {
-                               bor.write("      <Schedule/>\n"); 
-                        }
-
-                        bor.write(stmp + "\n"); 
-
+		    bir.close(); 
+		    
+		} catch (IOException ioe) {
+		    Debug.printStackTrace(ioe);
+		}
+		
+		//modify if old .col (i.e. no Schedule exists in XML file)
+		if(!flag) {
+		    File new_collection_file = new File(collection_directory.getAbsolutePath() + "/tmp.col");
+		    
+		    
+		    BufferedWriter bor = new BufferedWriter(new FileWriter(new_collection_file)); 
+		    bir = new BufferedReader(new FileReader(collection_file)); 
+		    
+		    try { 
+			String stmp = new String(); 
+			while((stmp = bir.readLine()) != null) {
+			    String stmp2 = stmp.trim(); 
+			    if(stmp2.startsWith("<!ELEMENT Argument")) {
+				bor.write("  <!ELEMENT Schedule          (Arguments*)>\n"); 			   
+			    }
+			    else if(stmp2.equals("</BuildConfig>")) {
+				bor.write("      <Schedule/>\n"); 
+			    }
+			    
+			    bor.write(stmp + "\n"); 
+			    
+			}
+			bir.close(); 
+			bor.close();
+		    } catch (IOException ioe) {  
+			Debug.printStackTrace(ioe);
+		    }  
+		    
+		    //copy over tmp.col to replace 
+		    try { 
+			collection_file.delete();
+			new_collection_file.renameTo(collection_file); 
+		    } catch (Exception e) { 
+			Debug.printStackTrace(ioe);
+		    } 
+		}
+		
+		// Open the collection file
+		this.collection = new Collection(collection_file);
+		if (collection.error) {
+		    collection = null;
+		    // Remove lock file
+		    if (lock_file.exists()) {
+			lock_file.delete();
 		    }
-                    bir.close(); 
-                    bor.close();
-                } catch (IOException ioe) {  
-                  //do something here
-                }  
-
-		//copy over tmp.col to replace 
-		try { 
-		collection_file.delete();
-		new_collection_file.renameTo(collection_file); 
-		} catch (Exception e) { 
-		    //do something here 
-		} 
-	    }
-
-	    // Open the collection file
-	    this.collection = new Collection(collection_file);
-	    if (collection.error) {
-		collection = null;
-		// Remove lock file
-		if (lock_file.exists()) {
-		    lock_file.delete();
-		}
-		throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error
-	    }
-
-
-	    //try to obtain email address of collection owner if it exists... 
-	    String stmp = Configuration.getEmail(); 
-	    if(stmp != null) {
-		collection.schedule_options.setValue("toaddr", false, Configuration.getEmail());
-	    }
-
-
-
-	    //The next few items deal with updating the SMTP server, and the to: and from: addresses
-	    //from main.cfg and the collection configuration. if no changes are made, or the 
-	    //values are result to NULL, any existing values are kept. 
-
-	    //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender". 
-	    File mcfg = new File(LocalGreenstone.getDirectoryPath()+"etc" + File.separator + "main.cfg");
-	    BufferedReader maincfg = new BufferedReader(new FileReader(mcfg)); 	    
-	    stmp = "";
-	    String fromaddr = ""; 
-	    while((stmp = maincfg.readLine()) != null) { 
-		if(stmp.startsWith("maintainer")) {
-		       fromaddr = stmp.substring(10); //length of MailServer 
-		   fromaddr = fromaddr.trim();  
-		   break; 
-		}
-	    }
-	    maincfg.close(); 
-	    if(!fromaddr.equals("NULL") && !fromaddr.equals("null")) {
-		collection.schedule_options.setValue("fromaddr", false, fromaddr);	    
-	    }
-
-	    //try to obtain an smtp server address from main.cfg. If that fails,
-	    //try mail.server if an email address exists. If that fails,
-	    //maybe a message to set attribute in main.cfg? 
-	    //i'm pretty sure there exists functionality to do this, but 
-	    //i'll finish this faster if I just wrote it
-
-
-	    maincfg = new BufferedReader(new FileReader(mcfg)); 	  
-	    String smtptmp = "NULL";
-	    while((stmp = maincfg.readLine()) != null) { 
-		if(stmp.startsWith("MailServer")) {
-		       smtptmp = stmp.substring(10); //length of MailServer 
-		   smtptmp = smtptmp.trim(); 
-		   break; 
-		}
-	    }
-            maincfg.close();
-
-            //try if lookup failes
-            if(smtptmp.equals("NULL") || smtptmp.equals("null")) {
-		String email2=fromaddr; 
-		if(!email2.equals("NULL") && !email2.equals("null")) {
-		    int loc = email2.indexOf('@'); 
-		    email2 = email2.substring(loc+1); 
-		    smtptmp = "mail."+email2;
-	        }
-            }
-	    if(!smtptmp.equals("NULL") && !smtptmp.equals("null")) { 
-		collection.schedule_options.setValue("smtp", false, smtptmp);
-	    }
-
-
+		    throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error
+		}
+		
+		scheduling();
+	    }
+	  
             MetadataSetManager.clearMetadataSets();
 	    MetadataSetManager.loadMetadataSets(collection_metadata_directory);
