ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1733645 - in /webservices/axiom/branches/stax-stream/aspects: core-aspects/src/main/java/org/apache/axiom/core/stream/ core-aspects/src/main/java/org/apache/axiom/core/stream/stax/ om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/
Date Fri, 04 Mar 2016 20:05:18 GMT
Author: veithen
Date: Fri Mar  4 20:05:18 2016
New Revision: 1733645

URL: http://svn.apache.org/viewvc?rev=1733645&view=rev
Log:
Make more test cases pass.

Added:
    webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
  (with props)
Modified:
    webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/StAXPivot.java
    webservices/axiom/branches/stax-stream/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj

Added: webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java?rev=1733645&view=auto
==============================================================================
--- webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
(added)
+++ webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
Fri Mar  4 20:05:18 2016
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.core.stream;
+
+public final class NamespaceURIInterningFilterHandler extends XmlHandlerWrapper {
+    public NamespaceURIInterningFilterHandler(XmlHandler parent) {
+        super(parent);
+    }
+
+    @Override
+    public void startElement(String namespaceURI, String localName, String prefix) throws
StreamException {
+        super.startElement(namespaceURI.intern(), localName, prefix);
+    }
+
+    @Override
+    public void processAttribute(String namespaceURI, String localName, String prefix, String
value, String type, boolean specified) throws StreamException {
+        super.processAttribute(namespaceURI.intern(), localName, prefix, value, type, specified);
+    }
+
+    @Override
+    public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException
{
+        super.processNamespaceDeclaration(prefix, namespaceURI.intern());
+    }
+}

Propchange: webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/StAXPivot.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/StAXPivot.java?rev=1733645&r1=1733644&r2=1733645&view=diff
==============================================================================
--- webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/StAXPivot.java
(original)
+++ webservices/axiom/branches/stax-stream/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/StAXPivot.java
Fri Mar  4 20:05:18 2016
@@ -174,7 +174,8 @@ public final class StAXPivot implements
     private String rootName;
     private String publicId;
     private String systemId;
-    private Object text;
+    private Object characterData;
+    private String text;
     // Entity reference name or processing instruction target
     private String name;
     
@@ -312,13 +313,22 @@ public final class StAXPivot implements
 
     @Override
     public void processCharacterData(Object data, boolean ignorable) throws StreamException
{
-        if (state == STATE_COLLECT_TEXT) {
-            accumulator.append(data);
-        } else {
-            checkState();
-            eventType = ignorable ? SPACE : CHARACTERS;
-            text = data;
-            state = STATE_EVENT_COMPLETE;
+        switch (state) {
+            case STATE_DEFAULT:
+                eventType = ignorable ? SPACE : CHARACTERS;
+                characterData = data;
+                state = STATE_EVENT_COMPLETE;
+                return;
+            case STATE_COLLECT_TEXT:
+                accumulator.append(data);
+                return;
+            case STATE_NEXT_TAG:
+                // TODO: check that the character data only contains whitespace!
+                break;
+            case STATE_SKIP_CONTENT:
+                break;
+            default:
+                throw new IllegalStateException();
         }
     }
 
@@ -400,6 +410,17 @@ public final class StAXPivot implements
     public int next() throws XMLStreamException {
         try {
             switch (eventType) {
+                case CHARACTERS:
+                case SPACE:
+                    characterData = null;
+                    // Fall through
+                case CDATA:
+                case COMMENT:
+                case PROCESSING_INSTRUCTION:
+                case DTD:
+                case ENTITY_REFERENCE:
+                    text = null;
+                    break;
                 case START_ELEMENT:
                     depth++;
                     break;
@@ -466,8 +487,8 @@ public final class StAXPivot implements
 
     @Override
     public int nextTag() throws XMLStreamException {
-        // TODO Auto-generated method stub
-        return 0;
+        state = STATE_NEXT_TAG;
+        return next();
     }
 
     @Override
@@ -530,7 +551,7 @@ public final class StAXPivot implements
                 // points to a character data event that consists of all whitespace". This
                 // means that this method may return true for a CHARACTER event and we need
                 // to scan the text of the node.
-                String text = this.text.toString();
+                String text = internalGetText();
                 for (int i=0; i<text.length(); i++) {
                     char c = text.charAt(i);
                     if (c != ' ' && c != '\t' && c != '\r' && c !=
'\n') {
@@ -678,6 +699,13 @@ public final class StAXPivot implements
         return eventType;
     }
 
+    private String internalGetText() {
+        if (text == null && characterData != null) {
+            text = characterData.toString();
+        }
+        return text;
+    }
+    
     @Override
     public String getText() {
         switch (eventType) {
@@ -687,7 +715,7 @@ public final class StAXPivot implements
             case COMMENT:
             case DTD:
             case ENTITY_REFERENCE:
-                return text == null ? null : text.toString();
+                return internalGetText();
             default:
                 throw new IllegalStateException();
         }
@@ -701,17 +729,18 @@ public final class StAXPivot implements
             case SPACE:
             case COMMENT:
                 // TODO: optimize this
-                return text.toString().toCharArray();
+                return internalGetText().toCharArray();
             default:
                 throw new IllegalStateException();
         }
     }
 
     @Override
-    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
-            throws XMLStreamException {
-        // TODO Auto-generated method stub
-        return 0;
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
throws XMLStreamException {
+        String text = internalGetText();
+        int copied = Math.min(length, text.length()-sourceStart);
+        text.getChars(sourceStart, sourceStart + copied, target, targetStart);
+        return copied;
     }
 
     @Override
@@ -735,7 +764,7 @@ public final class StAXPivot implements
             case SPACE:
             case COMMENT:
                 // TODO: optimize this
-                return text.toString().length();
+                return internalGetText().length();
             default:
                 throw new IllegalStateException();
         }
@@ -824,7 +853,7 @@ public final class StAXPivot implements
     @Override
     public String getPIData() {
         if (eventType == PROCESSING_INSTRUCTION) {
-            return text.toString();
+            return text;
         } else {
             throw new IllegalStateException();
         }
@@ -847,6 +876,6 @@ public final class StAXPivot implements
 
     @Override
     public Object getCharacterData() {
-        return text;
+        return characterData;
     }
 }

Modified: webservices/axiom/branches/stax-stream/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/stax-stream/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj?rev=1733645&r1=1733644&r2=1733645&view=diff
==============================================================================
--- webservices/axiom/branches/stax-stream/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
(original)
+++ webservices/axiom/branches/stax-stream/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
Fri Mar  4 20:05:18 2016
@@ -38,6 +38,7 @@ import org.apache.axiom.core.CoreNode;
 import org.apache.axiom.core.ElementMatcher;
 import org.apache.axiom.core.Mapper;
 import org.apache.axiom.core.stream.NamespaceRepairingFilterHandler;
+import org.apache.axiom.core.stream.NamespaceURIInterningFilterHandler;
 import org.apache.axiom.core.stream.StreamException;
 import org.apache.axiom.core.stream.XmlHandler;
 import org.apache.axiom.core.stream.sax.XmlHandlerContentHandler;
@@ -61,6 +62,7 @@ import org.apache.axiom.om.impl.common.O
 import org.apache.axiom.om.impl.common.SAXResultContentHandler;
 import org.apache.axiom.om.impl.common.serializer.pull.OMXMLStreamReaderExAdapter;
 import org.apache.axiom.om.impl.common.serializer.pull.PullSerializer;
+import org.apache.axiom.om.impl.common.serializer.push.NamespaceContextPreservationFilterHandler;
 import org.apache.axiom.om.impl.common.serializer.push.XmlDeclarationRewriterHandler;
 import org.apache.axiom.om.impl.common.serializer.push.XsiTypeFilterHandler;
 import org.apache.axiom.om.impl.common.serializer.push.sax.XMLReaderImpl;
@@ -128,8 +130,18 @@ public aspect AxiomContainerSupport {
 //        return reader;
         
         StAXPivot pivot = new StAXPivot(AxiomXMLStreamReaderExtensionFactory.INSTANCE);
+        XmlHandler handler = pivot;
+        if (configuration.isNamespaceURIInterning()) {
+            handler = new NamespaceURIInterningFilterHandler(handler);
+        }
+        if (configuration.isPreserveNamespaceContext()) {
+            CoreElement contextElement = getContextElement();
+            if (contextElement != null) {
+                handler = new NamespaceContextPreservationFilterHandler(handler, contextElement);
+            }
+        }
         try {
-            pivot.setReader(coreGetReader(pivot, cache));
+            pivot.setReader(coreGetReader(handler, cache));
         } catch (StreamException ex) {
             throw new OMException(ex);
         }



Mime
View raw message