xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject svn commit: r581481 - /xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeTextReader.java
Date Wed, 03 Oct 2007 03:01:33 GMT
Author: mrglavas
Date: Tue Oct  2 20:01:32 2007
New Revision: 581481

URL: http://svn.apache.org/viewvc?rev=581481&view=rev
Log:
Plugging the new UTF16Reader into the XInclude text reader and doing a bit of re-factoring.

Modified:
    xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeTextReader.java

Modified: xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeTextReader.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeTextReader.java?rev=581481&r1=581480&r2=581481&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeTextReader.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeTextReader.java Tue Oct  2 20:01:32
2007
@@ -33,6 +33,7 @@
 import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.io.ASCIIReader;
 import org.apache.xerces.impl.io.Latin1Reader;
+import org.apache.xerces.impl.io.UTF16Reader;
 import org.apache.xerces.impl.io.UTF8Reader;
 import org.apache.xerces.impl.msg.XMLMessageFormatter;
 import org.apache.xerces.util.EncodingMap;
@@ -224,15 +225,17 @@
             // eat the Byte Order Mark
             encoding = consumeBOM(stream, encoding);
             
-            // If the document is UTF-8 or US-ASCII use 
-            // the Xerces readers for these encodings. For
-            // US-ASCII consult the encoding map since
-            // this encoding has many aliases.
+            // If the document is UTF-8, UTF-16, US-ASCII or ISO-8859-1 use 
+            // the Xerces readers for these encodings. For US-ASCII and ISO-8859-1
+            // consult the encoding map since these encodings have many aliases.
             if (encoding.equals("UTF-8")) {
-                return new UTF8Reader(stream, 
-                    fTempString.ch.length, 
-                    fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), 
-                    fErrorReporter.getLocale() );
+                return createUTF8Reader(stream);
+            }
+            else if (encoding.equals("UTF-16BE")) {
+                return createUTF16Reader(stream, true);
+            }
+            else if (encoding.equals("UTF-16LE")) {
+                return createUTF16Reader(stream, false);
             }
             
             // Try to use a Java reader.
@@ -250,16 +253,43 @@
                     new Object[] {encoding} ) );
             }
             else if (javaEncoding.equals("ASCII")) {
-                return new ASCIIReader(stream,
-                    fTempString.ch.length,
-                    fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), 
-                    fErrorReporter.getLocale() );
+                return createASCIIReader(stream);
             }
             else if (javaEncoding.equals("ISO8859_1")) {
-                return new Latin1Reader(stream, fTempString.ch.length);
+                return createLatin1Reader(stream);
             }
             return new InputStreamReader(stream, javaEncoding);
         }
+    }
+    
+    /** Create a new UTF-8 reader from the InputStream. **/
+    private Reader createUTF8Reader(InputStream stream) {
+        return new UTF8Reader(stream, 
+                fTempString.ch.length, 
+                fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), 
+                fErrorReporter.getLocale());
+    }
+
+    /** Create a new UTF-16 reader from the InputStream. **/
+    private Reader createUTF16Reader(InputStream stream, boolean isBigEndian) {
+        return new UTF16Reader(stream,
+                (fTempString.ch.length << 1),
+                isBigEndian,
+                fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), 
+                fErrorReporter.getLocale());
+    }
+    
+    /** Create a new ASCII reader from the InputStream. **/
+    private Reader createASCIIReader(InputStream stream) {
+        return new ASCIIReader(stream,
+                fTempString.ch.length,
+                fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), 
+                fErrorReporter.getLocale());
+    }
+    
+    /** Create a new ISO-8859-1 reader from the InputStream. **/
+    private Reader createLatin1Reader(InputStream stream) {
+        return new Latin1Reader(stream, fTempString.ch.length);
     }
 
     /** 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org


Mime
View raw message