Index: /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 7206)
+++ /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 7207)
@@ -49,4 +49,5 @@
 import org.greenstone.gatherer.cdm.CollectionMeta;
 import org.greenstone.gatherer.cdm.CollectionMetaManager;
+import org.greenstone.gatherer.cdm.CommandTokenizer;
 import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
 import org.greenstone.gatherer.collection.Collection;
@@ -256,5 +257,4 @@
 	    makeCollection(description, email, name, title);
 	    progress.setProgress(1);
-
 	    String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator;
 
@@ -1037,4 +1037,5 @@
 	process.addGShellListener(this);
 	process.run(); // Don't bother threading this... yet
+       
     }
 
@@ -1105,4 +1106,5 @@
 	}
 	else if(event.getStatus() == GShell.ERROR || event.getStatus() == GShell.CANCELLED) {
+	    Gatherer.println("There was an error in the gshell:"+ event.getMessage());
 	    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready_Failed"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.ERROR_MESSAGE);
 	    Gatherer.g_man.collectionChanged(ready());
@@ -1367,4 +1369,9 @@
 	    String command = null;
 	    while((command = in.readLine()) != null) {
+		if (command.length()==0) {
+		    // output a new line
+		    out.newLine();
+		    continue;
+		}
 		// We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat.
 		while(command.trim().endsWith("\\")) {
@@ -1375,21 +1382,29 @@
 		    }
 		}
-		///ystem.err.println("Read: " + command);
-		// Now we've finished parsing a line, determine what to do with it.
-		String command_lc = command.toLowerCase();
-		if (command_lc.startsWith(StaticStrings.COLLECTIONMETADATA_STR)) {
-		    // we don't want to import collectionname, collectionextra, iconcollection, iconcollectionsmall from the base collection
-		    StringTokenizer tokeniser = new StringTokenizer(command_lc);
-		    tokeniser.nextToken(); // remove the first one
-		    String meta_name = tokeniser.nextToken();
-		    tokeniser = null;
-		    if (meta_name.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR) ) {
-			continue;
+		// commands can extend over more than one line so use the CommandTokenizer which takes care of that
+		CommandTokenizer tokenizer = new CommandTokenizer(command, in, false);
+		String command_type_str = tokenizer.nextToken().toLowerCase();
+
+		if (command_type_str.equals(StaticStrings.COLLECTIONMETADATA_STR)) {
+		    // read the whole thing in, but for collectionname, collectionextra, iconcollection, iconcollectionsmall we will ignore them
+		    StringBuffer new_command = new StringBuffer(command_type_str);
+		    String meta_name = tokenizer.nextToken();
+		    new_command.append(' ');
+		    new_command.append(meta_name);
+		    while (tokenizer.hasMoreTokens()) {
+			new_command.append(' ');
+			new_command.append(tokenizer.nextToken());
 		    }
-		}
-		// Just before we try more general parsing there are the special cases to check. These are explicit changes required by some collections to produce sensible results.
-		if(command_lc.startsWith(Utility.CFG_CLASSIFY)) {
-		    StringTokenizer tokenizer = new StringTokenizer(command);
-		    StringBuffer text = new StringBuffer(tokenizer.nextToken());
+		    if (meta_name.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR)) {
+			// dont save
+		    } else {
+			write(out, new_command.toString());
+		    }
+		    new_command = null;
+		    continue;
+		} // if collectionmeta
+
+		if(command_type_str.equals(Utility.CFG_CLASSIFY)) {
+		    StringBuffer text = new StringBuffer(command_type_str);
 		    // Read in the classifier command watching for hfile, metadata and sort arguments.
 		    String buttonname = null;
@@ -1397,4 +1412,5 @@
 		    String new_metadata = null;
 		    String old_metadata = null;
+		
 		    while(tokenizer.hasMoreTokens()) {
 			String token = tokenizer.nextToken();
@@ -1454,6 +1470,5 @@
 			token = null;
 		    }
-		    tokenizer = null;
-		    
+		   
 		    // If we replaced the metadata argument and didn't encounter a buttonname, then add one now pointing back to the old metadata name in order to accomodate macro files which required such names (buttonname is metadata name by default)!
 		    if(old_metadata != null && new_metadata != null && buttonname == null) {
@@ -1468,4 +1483,5 @@
 			command = command.replaceAll(hfile, new_metadata + ".txt");
 		    }
+		
 		    buttonname = null;
 		    hfile = null;
@@ -1473,8 +1489,17 @@
 		    old_metadata = null;
 		    write(out, command);
-		}
-		else {
+		 } else {
+		     // the rest of the commands just want a string - we read in all the tokens from the tokeniser and get rid of it.
+		    StringBuffer new_command = new StringBuffer(command_type_str);
+		    while (tokenizer.hasMoreTokens()) {
+			new_command.append(' ');
+			new_command.append(tokenizer.nextToken());
+		    }
+
+		    command = new_command.toString();
+		    
 		    // There is still one special case, that of the format command. In such a command we have to search for [<target>] to ensure we don't change parts of the format which have nothing to do with the metadata elements.
-		    boolean format_command = command_lc.startsWith(Utility.CFG_FORMAT);
+		    // we really want to build up the whole command here
+		    boolean format_command = command_type_str.equals(Utility.CFG_FORMAT);
 		    // Replace mapping strings
 		    if(mappings != null) {
@@ -1490,5 +1515,6 @@
 		    }
 		    write(out, command);
-		}
+		 }
+		tokenizer = null;
 	    }
 	    in.close();
@@ -1506,5 +1532,4 @@
     private void write(BufferedWriter out, String message)
 	throws Exception {
-	///ystem.err.println("Writing: " + message);
 	out.write(message, 0, message.length());
 	out.newLine();
