classpathx-xml
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Classpathx-xml] ReaderInputStream vs XmlParser declared and detecte


From: Mark Wielaard
Subject: Re: [Classpathx-xml] ReaderInputStream vs XmlParser declared and detected encodings
Date: Sun, 05 Dec 2004 23:39:46 +0100

Hi,

On Sun, 2004-12-05 at 16:46, Mark Wielaard wrote:
> But this seems a deeper problem with handling InputStream <-> Reader
> interaction combined with XML documents that declare their own encoding.
> I don't have a clue how to handle it properly though since when you use
> a Reader you do that to hide the underlying encoding in the first place,
> so it doesn't mix well with documents declaring their own encoding
> format...

Sigh. And indeed I ran into some more problems like these.
Attached is a patch that got me a little further.

There is one bugfix not related to Readers/InputStreams, encoders and
friends in gnu/xml/libxmlj/transform/GnomeTransformer.java for the case
source == null (plus some extra code to make debugging easier).

Cheers,

Mark
Index: gnu/xml/dom/ls/ReaderInputStream.java
===================================================================
RCS file: 
/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java,v
retrieving revision 1.1
diff -u -r1.1 ReaderInputStream.java
--- gnu/xml/dom/ls/ReaderInputStream.java       4 Dec 2004 21:12:26 -0000       
1.1
+++ gnu/xml/dom/ls/ReaderInputStream.java       5 Dec 2004 22:36:30 -0000
@@ -47,17 +47,17 @@
  *
  * @author <a href='mailto:address@hidden'>Chris Burdess</a>
  */
-class ReaderInputStream
+public class ReaderInputStream
   extends InputStream
 {
 
   private Reader reader;
   private String encoding;
 
-  ReaderInputStream(Reader reader)
+  public ReaderInputStream(Reader reader)
   {
     this.reader = reader;
-    encoding = "UTF16";
+    encoding = "UTF-8";
   }
 
   void setEncoding(String encoding)
Index: gnu/xml/dom/ls/WriterOutputStream.java
===================================================================
RCS file: 
/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/dom/ls/WriterOutputStream.java,v
retrieving revision 1.1
diff -u -r1.1 WriterOutputStream.java
--- gnu/xml/dom/ls/WriterOutputStream.java      4 Dec 2004 21:12:26 -0000       
1.1
+++ gnu/xml/dom/ls/WriterOutputStream.java      5 Dec 2004 22:36:30 -0000
@@ -47,17 +47,17 @@
  *
  * @author <a href='mailto:address@hidden'>Chris Burdess</a>
  */
-class WriterOutputStream
+public class WriterOutputStream
   extends OutputStream
 {
 
   private Writer writer;
   private String encoding;
 
-  WriterOutputStream(Writer writer)
+  public WriterOutputStream(Writer writer)
   {
     this.writer = writer;
-    this.encoding = "UTF16";
+    this.encoding = "UTF-8";
   }
 
   void setEncoding(String encoding)
Index: gnu/xml/libxmlj/transform/GnomeTransformer.java
===================================================================
RCS file: 
/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/libxmlj/transform/GnomeTransformer.java,v
retrieving revision 1.8
diff -u -r1.8 GnomeTransformer.java
--- gnu/xml/libxmlj/transform/GnomeTransformer.java     4 Dec 2004 21:12:27 
-0000       1.8
+++ gnu/xml/libxmlj/transform/GnomeTransformer.java     5 Dec 2004 22:36:30 
-0000
@@ -141,7 +141,7 @@
       {
         stylesheet = newStylesheet ();
       } 
-    if (source instanceof StreamSource)
+    else if (source instanceof StreamSource)
       {
         try
           {
@@ -180,7 +180,7 @@
       }
     else
       {
-        String msg = "Source type not supported";
+        String msg = "Source type not supported (" + source + ")";
         throw new TransformerConfigurationException (msg);
       }
   }
@@ -344,7 +344,7 @@
               }
             else
               {
-                String msg = "Result type not supported";
+                String msg = "Result type not supported (" + result + ")";
                 throw new TransformerConfigurationException (msg);
               }
           }
@@ -359,7 +359,7 @@
         Node node = ds.getNode ();
         if (!(node instanceof GnomeDocument))
           {
-            String msg = "Node is not a GnomeDocument";
+            String msg = "Node is not a GnomeDocument (" + node + ")";
             throw new TransformerException (msg);
           }
         GnomeDocument doc = (GnomeDocument) node;
Index: gnu/xml/libxmlj/util/XMLJ.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/gnu/xml/libxmlj/util/XMLJ.java,v
retrieving revision 1.7
diff -u -r1.7 XMLJ.java
--- gnu/xml/libxmlj/util/XMLJ.java      4 Dec 2004 21:12:28 -0000       1.7
+++ gnu/xml/libxmlj/util/XMLJ.java      5 Dec 2004 22:36:30 -0000
@@ -43,6 +43,8 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PushbackInputStream;
+import java.io.Reader;
+import java.io.Writer;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -57,6 +59,9 @@
 
 import gnu.xml.libxmlj.transform.GnomeTransformerFactory;
 
+import gnu.xml.dom.ls.ReaderInputStream;
+import gnu.xml.dom.ls.WriterOutputStream;
+
 /**
  * Utility functions for libxmlj.
  */
@@ -107,6 +112,12 @@
     String systemId = input.getSystemId ();
     if (in == null)
       {
+       Reader r = input.getCharacterStream();
+       if (r != null)
+         in = new ReaderInputStream(r);
+      }
+    if (in == null)
+      {
         in = getInputStream(systemId);
       }
     return new NamedInputStream (systemId, in, LOOKAHEAD);
@@ -199,6 +210,12 @@
       }
     if (out == null)
       {
+       Writer w = ((StreamResult) result).getWriter ();
+       if (w != null)
+         out = new WriterOutputStream (w);
+      }
+    if (out == null)
+      {
         String systemId = result.getSystemId ();
         if (systemId == null)
           {
@@ -216,6 +233,7 @@
             out = new FileOutputStream (systemId);
           }
       }
+
     return out;
   }
 

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]