Author: mrglavas
Date: Sun Feb 12 13:43:49 2006
New Revision: 377247

URL: http://svn.apache.org/viewcvs?rev=377247&view=rev
Log:
Fixing a bug. The DOM parser sets the input encoding on the document during the 
startDocument 
event. The problem is that this occurs before the XML declaration has been read 
so the encoding
stored in the DOM may be the auto-detected encoding and not the actual encoding 
of the document.

For a document such as:
<?xml version="1.0" encoding="US-ASCII"?>
<root/>

the actual encoding was being reported as UTF-8 instead of US-ASCII.

The actual encoding of the document may not be determined by the scanner until 
after the xmlDecl 
event has been reported down the pipeline. To get the "final" encoding we now 
read the locator in 
endDocument() and set the encoding it returns on the document.

Modified:
    xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java

Modified: xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java
URL: 
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java?rev=377247&r1=377246&r2=377247&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java Sun 
Feb 12 13:43:49 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -254,7 +254,6 @@
     /** Base uri stack*/
     protected Stack fBaseURIStack = new Stack ();
 
-
     /** LSParserFilter: the QNAME of rejected element*/
     protected final QName fRejectedElement = new QName ();
 
@@ -266,6 +265,9 @@
 
     /** Attribute QName. */
     private QName fAttrQName = new QName ();
+    
+    /** Document locator. */
+    private XMLLocator fLocator;
 
     // handlers
 
@@ -730,6 +732,7 @@
     NamespaceContext namespaceContext, Augmentations augs)
     throws XNIException {
 
+        fLocator = locator;
         if (!fDeferNodeExpansion) {
             if (fDocumentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
                 fDocument = new DocumentImpl ();
@@ -1424,13 +1427,20 @@
         if (!fDeferNodeExpansion) {
             // REVISIT: when DOM Level 3 is REC rely on Document.support
             //          instead of specific class
-            // set DOM error checking back on
+            // set the actual encoding and set DOM error checking back on
             if (fDocumentImpl != null) {
+                if (fLocator != null) {
+                    fDocumentImpl.setInputEncoding (fLocator.getEncoding());
+                }
                 fDocumentImpl.setStrictErrorChecking (true);
             }
             fCurrentNode = null;
         }
         else {
+            // set the actual encoding
+            if (fLocator != null) {
+                fDeferredDocumentImpl.setInputEncoding 
(fLocator.getEncoding());
+            }
             fCurrentNodeIndex = -1;
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to