Index: trunk/gli/src/org/greenstone/gatherer/util/AppendLineOnlyFileDocument.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/util/AppendLineOnlyFileDocument.java	(revision 7061)
+++ trunk/gli/src/org/greenstone/gatherer/util/AppendLineOnlyFileDocument.java	(revision 7062)
@@ -137,13 +137,12 @@
     public void appendLine(String str) {
 	// Ensure the string ends in a newline
-	if(!str.endsWith("\n")) {
-	    str = str + "\n";
-	}
 	try {
-	    int str_length = str.length();
+	    if (!str.endsWith("\n")) {
+		str = str + "\n";
+	    }
+	    int str_length = str.getBytes("UTF-8").length;
 	    long start_offset = length;
 	    long end_offset = start_offset + (long) str_length;
 	    length = length + str_length;
-	    //write(start_offset, end_offset, str, str_length);
 	    // Create a new element to represent this line
 	    AppendLineOnlyFileDocumentElement new_line_element = new AppendLineOnlyFileDocumentElement(start_offset, end_offset, str);
@@ -246,46 +245,60 @@
     public String getText(int offset, int l) 
 	throws BadLocationException {
-	String request = "getText(" + offset + ", " + l + ")";
-	///ystem.err.println(request);
-	String text = null;
-	if(text == null || text.length() < l) {
-	    try {
-		int file_length = (int) file.length();
-		///ystem.err.println("file_length = " + file_length + ", length = " + length);
-		if(l == 0) {
-		    text = StaticStrings.EMPTY_STR;
-		}
-		else if(0 <= offset && offset < length && (offset + l) <= length) {
-		    if(offset < file_length) {
-			text = read((long)offset, l);
-			if(text.length() != l) {
-			    ///ystem.err.println("Asked for " + l + " characters of text. But only read " + text.length());
-			    throw new BadLocationException("AppendLineOnlyDocument.getText(" + offset + ", " + l + ")", offset); 
-			}
-		    }
-		    else {
-			int index = root_element.getElementIndex(offset);
-			if(index < root_element.getElementCount()) {
-			    AppendLineOnlyFileDocumentElement element = (AppendLineOnlyFileDocumentElement) root_element.getElement(index);
-			    text = element.getContent();
-			}
-			else {
-			    ///ystem.err.println("Index is " + index + " but there are only " + root_element.getElementCount() + " children.");
-			    throw new BadLocationException("AppendLineOnlyDocument.getText(" + offset + ", " + l + ")", offset); 
-			}
-		    }
+
+	if (l == 0) {
+	    return "";
+	}
+
+	try {
+	    return read((long) offset, l);
+	}
+	catch (Exception ex) {
+	}
+
+	return "";
+
+//  	// System.err.println("AppendLineOnlyFileDocument::getText() request...");
+//  	String request = "getText(" + offset + ", " + l + ")";
+//  	///ystem.err.println(request);
+//  	String text = null;
+//  	if(text == null || text.length() < l) {
+//  	    try {
+//  		int file_length = (int) file.length();
+//  		///ystem.err.println("file_length = " + file_length + ", length = " + length);
+//  		if(l == 0) {
+//  		    text = StaticStrings.EMPTY_STR;
+//  		}
+//  		else if(0 <= offset && offset < length && (offset + l) <= length) {
+//  		    if(offset < file_length) {
+//  			text = read((long)offset, l);
+//  			if(text.length() != l) {
+//  			    ///ystem.err.println("Asked for " + l + " characters of text. But only read " + text.length());
+//  			    throw new BadLocationException("AppendLineOnlyDocument.getText(" + offset + ", " + l + ")", offset); 
+//  			}
+//  		    }
+//  		    else {
+//  			int index = root_element.getElementIndex(offset);
+//  			if(index < root_element.getElementCount()) {
+//  			    AppendLineOnlyFileDocumentElement element = (AppendLineOnlyFileDocumentElement) root_element.getElement(index);
+//  			    text = element.getContent();
+//  			}
+//  			else {
+//  			    ///ystem.err.println("Index is " + index + " but there are only " + root_element.getElementCount() + " children.");
+//  			    throw new BadLocationException("AppendLineOnlyDocument.getText(" + offset + ", " + l + ")", offset); 
+//  			}
+//  		    }
 		    
-		}
-	    }
-	    catch (IOException error) {
-		Gatherer.printStackTrace(error);
-	    }
-	    if(text == null) {
-		///ystem.err.println("Text is null.");
-		throw new BadLocationException("AppendLineOnlyDocument.getText(" + offset + ", " + l + ")", offset);
-	    }
-	}
-	request = null;
-	return text;
+//  		}
+//  	    }
+//  	    catch (IOException error) {
+//  		Gatherer.printStackTrace(error);
+//  	    }
+//  	    if(text == null) {
+//  		///ystem.err.println("Text is null.");
+//  		throw new BadLocationException("AppendLineOnlyDocument.getText(" + offset + ", " + l + ")", offset);
+//  	    }
+//  	}
+//  	request = null;
+//  	return text;
     }
 
@@ -375,6 +388,6 @@
 	file.seek(start_offset);
 	int result = file.read(buffer, 0, l);
+	return new String(buffer, "UTF-8");
 	//print("read() complete");
-	return new String(buffer);
     }
 
@@ -390,5 +403,5 @@
 	file.setLength(end_offset);
 	file.seek(start_offset);
-	file.write(str.getBytes(), 0, l);
+	file.write(str.getBytes("UTF-8"), 0, l);
 	//print("write() complete");
     }
@@ -779,5 +792,5 @@
 		    if(content != null) {
 			try {
-			    write(element.getStartOffset(), element.getEndOffset(), content, content.length());
+			    write(element.getStartOffset(), element.getEndOffset(), content, content.getBytes("UTF-8").length);
 			}
 			catch(Exception error) {
