Author: veithen
Date: Tue Aug  4 21:45:05 2009
New Revision: 800994

URL: http://svn.apache.org/viewvc?rev=800994&view=rev
Log:
The StAX reference implementation fails to normalize line endings in 
prolog/epilog. Implemented a workaround to avoid a build failure on Windows.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java?rev=800994&r1=800993&r2=800994&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
 Tue Aug  4 21:45:05 2009
@@ -30,6 +30,8 @@
      */
     private final String encodingFromStartBytes;
     
+    private int depth;
+    
     public BEAStreamReaderWrapper(XMLStreamReader parent, String 
encodingFromStartBytes) {
         super(parent);
         this.encodingFromStartBytes = encodingFromStartBytes;
@@ -41,7 +43,12 @@
             // This can't be considered as compliant with the specifications.
             throw new IllegalStateException("Already reached end of document");
         } else {
-            return super.next();
+            int event = super.next();
+            switch (event) {
+                case START_ELEMENT: depth++; break;
+                case END_ELEMENT: depth--;
+            }
+            return event;
         }
     }
 
@@ -64,4 +71,31 @@
             }
         }
     }
+
+    public String getText() {
+        // The reference implementation fails to normalize line endings in the 
prolog/epilog; we work
+        // around this at least for getText since this bug causes a test 
failure in the Axiom unit
+        // tests on Windowsd.
+        if (depth == 0) {
+            String text = super.getText();
+            StringBuffer buffer = null;
+            int len = text.length();
+            for (int i=0; i<len; i++) {
+                char c = text.charAt(i);
+                if (c == '\r' && (i==len || text.charAt(i+1) == '\n')) {
+                    if (buffer == null) {
+                        buffer = new StringBuffer(len-1);
+                        buffer.append(text.substring(0, i));
+                    }
+                } else {
+                    if (buffer != null) {
+                        buffer.append(c);
+                    }
+                }
+            }
+            return buffer != null ? buffer.toString() : text;
+        } else {
+            return super.getText();
+        }
+    }
 }


Reply via email to