Index: /main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java	(revision 33747)
+++ /main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java	(revision 33748)
@@ -76,5 +76,11 @@
 	/** Compiled pattern for hex entities of characters. These are of the forn "&#x....;" with 1 to 4 digits */
 	public static final Pattern HEX_PATTERN = Pattern.compile("(&#x[0-9a-zA-Z]{1,4}+;)");
-	
+
+    /** The hex entity version of the ampersand character.
+     * We use this in place of the ampersand character in filenames in metadata.xml files to
+     * preserve the reference to the literal ampersand in the real file name on the file system.
+     */
+    public static final String HEX_ENTITY_AMPERSAND = FilenameEncoding.hexEntityForChar("&"); //"&#x26;";
+    
 
 //*********************** BUSY REFRESHING / REQUIRING  REFRESH *********************
@@ -371,6 +377,11 @@
 	
     public static String fileToURLEncoding(File file) {
+	// on a UTF-8 file system, DO NOT do the stuff further below,
+	// just return input filename param, but with any & in the filename replaced with its hex entity
 		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) {
-		    return file.getAbsolutePath();
+		    // protect ampersands in filenames by converting it to its hex entity
+		    String filepath = file.getAbsolutePath();
+		    filepath = filepath.replace("&", HEX_ENTITY_AMPERSAND);
+		    return filepath;
 		}
 		
@@ -419,5 +430,5 @@
 			
 			// Before proceeding, protect & in the filename too.
-			// &'s ASCII code is 36 in decimal, and 26 in hex, so replace with &#x26;
+			// &'s ASCII code is 36 in decimal, and 26 in hex, so replace with &#x26; (HEX_ENTITY_AMPERSAND)
 			// But dangerous to do simple replace if there are &#x...; entities in the filename already!
 			// That is, we'll want to protect & by replacing with &'s hex value, but we don't want to replace the & in "&#x....;" with the same!
@@ -434,5 +445,5 @@
 			//filename_url_encoded = filename_url_encoded.replace("%2B", "&#x2B;"); // Don't do this, won't get regex escaped when converted back to a + by caller
 			filename_url_encoded = filename_url_encoded.replace("%2B", "+"); // + signs are special, as they will need to be escaped since the caller wants the filename representing a regex
-			filename_url_encoded = filename_url_encoded.replace("%26", "&#x26;"); // convert URL encoding for ampersand into hex entity for ampersand
+			filename_url_encoded = filename_url_encoded.replace("%26", HEX_ENTITY_AMPERSAND); // convert URL encoding for ampersand into hex entity for ampersand
 		}
 		catch (Exception e) {
@@ -530,6 +541,8 @@
 	*/
 	public static String fullFilepathToURLEncoding(String filename) {
-		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { // on a UTF-8 file system, DO NOT do the stuff below, just return input param
-		    return filename;
+	    // on a UTF-8 file system, DO NOT do the stuff further below,
+	    // just return input filename param, but with any & in the filename replaced with its hex entity
+		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) {
+		    return filename.replace("&", HEX_ENTITY_AMPERSAND);
 		}
 		
@@ -554,5 +567,5 @@
 	public static String relativeFilenameToURLEncoding(String filename) {
 		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { // on a UTF-8 file system, DO NOT do the stuff below, just return input param
-		    return filename;
+		    return filename.replace("&", HEX_ENTITY_AMPERSAND);
 		}
 		
@@ -567,5 +580,5 @@
 	public static String filenameToURLEncodingWithPrefixRemoved(String filename, String removeFilePathPrefix) {
 		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { // on a UTF-8 file system, DO NOT do the stuff below, just return input param
-		    return filename;
+		    return filename.replace("&", HEX_ENTITY_AMPERSAND);
 		}
 		
Index: /main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java	(revision 33747)
+++ /main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java	(revision 33748)
@@ -87,5 +87,11 @@
 	// Determine the file's path relative to the location of the metadata.xml file
 	String metadata_xml_file_directory_path = FilenameEncoding.fileToURLEncoding(getParentFile());
-	String file_relative_path = file_node.getURLEncodedFilePath().substring(metadata_xml_file_directory_path.length());
+
+	String file_relative_path = file_node.getURLEncodedFilePath();
+	if(!FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) {
+	    file_relative_path = file_relative_path.replace("&", FilenameEncoding.HEX_ENTITY_AMPERSAND);
+	}
+	file_relative_path = file_relative_path.substring(metadata_xml_file_directory_path.length());
+	
 	if (file_relative_path.startsWith(FilenameEncoding.URL_FILE_SEPARATOR)) {
 	    file_relative_path = file_relative_path.substring(FilenameEncoding.URL_FILE_SEPARATOR.length());
@@ -103,4 +109,5 @@
 	}
 
+	// LEAVE THIS DEBUGGING STATEMENT IN - USEFUL TO DEBUG FILENAME ENCODING ISSUES WHEN META ASSIGNED
 	//System.err.println("MetadataXMLFile.addMetadata() Adding meta for file regexp: "
 	//	+ file_path_regexp + " - " + org.greenstone.gatherer.util.Utility.debugUnicodeString(file_path_regexp));
@@ -220,4 +227,6 @@
 
 
+    // DO NOT REMOVE THE System.err DEBUGGING STATEMENTS FROM THIS METHOD: HELPS WITH TESTING/DEBUGGING
+    // WHEN FILE-LEVEL META IS ASSIGNED TO NON-ASCII ENCODED FILENAMES OR WITH FILENAMES CONTAINING +/ampersand
     public ArrayList getMetadataAssignedToFile(File file, boolean fileEncodingOnly)
     {
@@ -652,9 +661,9 @@
 	 * At the end of this function, the doc will be modified with the re-encoded filenames.
 	 * 
+	 * DO NOT REMOVE THE DEBUGGING STATEMENTS IN THIS FUNCTION, AS THEY'RE USEFUL
+	 * FOR DEBUGGING ENCODING ISSUES TO DO WITH FILE LEVEL META ASSIGNED TO FILENAMES
+	 * THAT ARE NON-ASCII OR CONTAIN +/ampersands IN THEM.
 	*/
 	static private void reEncodeFilenamesInMetadataXML(Document doc) {
-		if(!FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) {
-		    return;
-		}
 		
 		String curr_directory_path = FilenameEncoding.fullFilepathToURLEncoding("."); // returns the curr dir path after removing the /./ at end		
@@ -677,8 +686,12 @@
 					
 					//System.err.println("Filename before reencoding was: " + filename);					
-					
+
+				    String encoded_filename = filename;
+				    if(!FilenameEncoding.MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) {
+					encoded_filename = encoded_filename.replace("&", FilenameEncoding.HEX_ENTITY_AMPERSAND);
+				    } else {
 					// Can't convert to URI with backslash-escaped chars (backslash used in regexed filename are illegal in URI object
 					// created by filenameToURLEncoding). So replace backslashes in regex with url-encoded hex-value of backslash, %5C.
-					String encoded_filename = filename.replace("\\", "%5C");
+					encoded_filename = filename.replace("\\", "%5C");
 					
 					// get the URL encoded filename preserving special encodings, with any curr_directory_path prefix removed
@@ -687,8 +700,8 @@
 					// Reintrodudce the backslash characters in place of their %5C hex placeholders
 					encoded_filename = encoded_filename.replace("%5C", "\\");
-					
-					// Update filename element in DOM
-					XMLTools.setElementTextValue(filename_element, encoded_filename);
-					//System.err.println("Filename after reencoding was: " + encoded_filename);
+				    }
+				    // Update filename element in DOM
+				    XMLTools.setElementTextValue(filename_element, encoded_filename);
+				    //System.err.println("Filename after reencoding was: " + encoded_filename);
 				}
 			}
