Bug 43736 applied patch provided by Curt with extraction to a constant to indicate that
XMLDecoder only deals with UTF-8 encoded log files.
Previously the system default encoding was being used to read in the XML file, even though
a header DOCTYPE pre-amble was added indicating the file was in UTF-8 encoding.
This is pretty much a stop gap fix for the time being. At the moment there is no way in
Chainsaw to specify the encoding of the file about to be opened.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/companions/receivers/trunk@591552 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/log4j/xml/XMLDecoder.java b/src/main/java/org/apache/log4j/xml/XMLDecoder.java
index b9a1149..0714563 100644
--- a/src/main/java/org/apache/log4j/xml/XMLDecoder.java
+++ b/src/main/java/org/apache/log4j/xml/XMLDecoder.java
@@ -37,9 +37,9 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.Decoder;
+import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
-import org.apache.log4j.spi.LocationInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -56,17 +56,23 @@
* NOTE: Only a single LoggingEvent is returned from the decode method
* even though the DTD supports multiple events nested in an eventSet.
*
- *
+ * NOTE: This class has been created on the assumption that all XML log files
+ * are encoding in UTF-8 encoding. There is no current support for any other
+ * encoding format at this time.
+ *
* @author Scott Deboy (sdeboy@apache.org)
* @author Paul Smith (psmith@apache.org)
*
*/
public class XMLDecoder implements Decoder {
+
+ private static final String ENCODING = "UTF-8";
+
/**
* Document prolog.
*/
private static final String BEGINPART =
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ "<?xml version=\"1.0\" encoding=\"" + ENCODING + "\" ?>"
+ "<!DOCTYPE log4j:eventSet SYSTEM \"http://localhost/log4j.dtd\">"
+ "<log4j:eventSet version=\"1.2\" "
+ "xmlns:log4j=\"http://jakarta.apache.org/log4j/\">";
@@ -183,9 +189,9 @@
if (owner != null) {
reader = new LineNumberReader(new InputStreamReader(
new ProgressMonitorInputStream(owner,
- "Loading " + url , url.openStream())));
+ "Loading " + url , url.openStream()), ENCODING));
} else {
- reader = new LineNumberReader(new InputStreamReader(url.openStream()));
+ reader = new LineNumberReader(new InputStreamReader(url.openStream(), ENCODING));
}
Vector v = new Vector();