ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1741108 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl: common/factory/BuilderFactory.java stream/xop/ stream/xop/XOPDecodingFilter.java stream/xop/XOPDecodingFilterHandler.java
Date Tue, 26 Apr 2016 21:34:58 GMT
Author: veithen
Date: Tue Apr 26 21:34:58 2016
New Revision: 1741108

URL: http://svn.apache.org/viewvc?rev=1741108&view=rev
Log:
Reimplement the XOP decoding logic using the new stream API to decouple it from the StAX API.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilter.java
  (with props)
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilterHandler.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java?rev=1741108&r1=1741107&r2=1741108&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java
Tue Apr 26 21:34:58 2016
@@ -45,6 +45,7 @@ import org.apache.axiom.om.OMXMLParserWr
 import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl;
 import org.apache.axiom.om.impl.stream.stax.StAXPullInput;
+import org.apache.axiom.om.impl.stream.xop.XOPDecodingFilter;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAPFactory;
@@ -57,7 +58,6 @@ import org.apache.axiom.soap.impl.intf.A
 import org.apache.axiom.util.stax.XMLEventUtils;
 import org.apache.axiom.util.stax.XMLFragmentStreamReader;
 import org.apache.axiom.util.stax.xop.MimePartProvider;
-import org.apache.axiom.util.stax.xop.XOPDecodingStreamReader;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 
@@ -245,9 +245,9 @@ abstract class BuilderFactory<T extends
             InputSource rootPart, MimePartProvider mimePartProvider) {
         SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, false);
         return createBuilder(nodeFactory,
-                new StAXPullInput(
-                        new XOPDecodingStreamReader(sourceInfo.getReader(), mimePartProvider),
true,
-                        sourceInfo.getCloseable()),
+                new FilteredXmlInput(
+                        new StAXPullInput(sourceInfo.getReader(), true, sourceInfo.getCloseable()),
+                        new XOPDecodingFilter(mimePartProvider)),
                 false,
                 mimePartProvider instanceof Detachable ? (Detachable) mimePartProvider :
null);
     }

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilter.java?rev=1741108&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilter.java
(added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilter.java
Tue Apr 26 21:34:58 2016
@@ -0,0 +1,36 @@
+/*
+ * 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.om.impl.stream.xop;
+
+import org.apache.axiom.core.stream.XmlFilter;
+import org.apache.axiom.core.stream.XmlHandler;
+import org.apache.axiom.util.stax.xop.MimePartProvider;
+
+public final class XOPDecodingFilter implements XmlFilter {
+    private final MimePartProvider mimePartProvider;
+
+    public XOPDecodingFilter(MimePartProvider mimePartProvider) {
+        this.mimePartProvider = mimePartProvider;
+    }
+
+    @Override
+    public XmlHandler createFilterHandler(XmlHandler parent) {
+        return new XOPDecodingFilterHandler(parent, mimePartProvider);
+    }
+}

Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilterHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilterHandler.java?rev=1741108&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilterHandler.java
(added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilterHandler.java
Tue Apr 26 21:34:58 2016
@@ -0,0 +1,194 @@
+/*
+ * 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.om.impl.stream.xop;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.core.stream.StreamException;
+import org.apache.axiom.core.stream.XmlHandler;
+import org.apache.axiom.core.stream.XmlHandlerWrapper;
+import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
+import org.apache.axiom.om.impl.intf.TextContent;
+import org.apache.axiom.util.stax.xop.MimePartProvider;
+
+final class XOPDecodingFilterHandler extends XmlHandlerWrapper {
+    private static class DataHandlerProviderImpl implements DataHandlerProvider {
+        private final MimePartProvider mimePartProvider;
+        private final String contentID;
+        
+        public DataHandlerProviderImpl(MimePartProvider mimePartProvider, String contentID)
{
+            this.mimePartProvider = mimePartProvider;
+            this.contentID = contentID;
+        }
+
+        public boolean isLoaded() {
+            return mimePartProvider.isLoaded(contentID);
+        }
+
+        public DataHandler getDataHandler() throws IOException {
+            return mimePartProvider.getDataHandler(contentID);
+        }
+    }
+
+    private static final String SOLE_CHILD_MSG =
+            "Expected xop:Include as the sole child of an element information item (see section
" +
+            "3.2 of http://www.w3.org/TR/xop10/)";
+
+    private enum State {
+        AFTER_START_ELEMENT, CONTENT_SEEN, IN_XOP_INCLUDE, AFTER_XOP_INCLUDE
+    }
+
+    private final MimePartProvider mimePartProvider;
+    private State state = State.CONTENT_SEEN;
+    private String contentID;
+
+    XOPDecodingFilterHandler(XmlHandler parent, MimePartProvider mimePartProvider) {
+        super(parent);
+        this.mimePartProvider = mimePartProvider;
+    }
+
+    private void inContent() throws StreamException {
+        switch (state) {
+            case IN_XOP_INCLUDE:
+                throw new StreamException(
+                        "Expected xop:Include element information item to be empty");
+            case AFTER_XOP_INCLUDE:
+                throw new StreamException(SOLE_CHILD_MSG);
+            default:
+                state = State.CONTENT_SEEN;
+        }
+    }
+
+    @Override
+    public void startElement(String namespaceURI, String localName, String prefix)
+            throws StreamException {
+        if (localName.equals("Include")
+                && namespaceURI.equals("http://www.w3.org/2004/08/xop/include"))
{
+            if (state == State.AFTER_START_ELEMENT) {
+                state = State.IN_XOP_INCLUDE;
+            } else {
+                throw new StreamException(SOLE_CHILD_MSG);
+            }
+        } else {
+            inContent();
+            super.startElement(namespaceURI, localName, prefix);
+        }
+    }
+
+    @Override
+    public void endElement() throws StreamException {
+        if (state == State.IN_XOP_INCLUDE) {
+            if (contentID == null) {
+                throw new StreamException("No href attribute found on xop:Include element");
+            }
+            super.processCharacterData(new TextContent(contentID, new DataHandlerProviderImpl(mimePartProvider,
contentID), true), false);
+            contentID = null;
+            state = State.AFTER_XOP_INCLUDE;
+        } else {
+            state = State.CONTENT_SEEN;
+            super.endElement();
+        }
+    }
+
+    @Override
+    public void processAttribute(String namespaceURI, String localName, String prefix, String
value,
+            String type, boolean specified) throws StreamException {
+        if (state == State.IN_XOP_INCLUDE) {
+            if (namespaceURI.isEmpty() && localName.equals("href")) {
+                if (!value.startsWith("cid:")) {
+                    throw new StreamException("Expected href attribute containing a URL in
the cid scheme");
+                }
+                try {
+                    // URIs should always be decoded using UTF-8. On the other hand, since
non ASCII
+                    // characters are not allowed in content IDs, we can simply decode using
ASCII
+                    // (which is a subset of UTF-8)
+                    contentID = URLDecoder.decode(value.substring(4), "ascii");
+                } catch (UnsupportedEncodingException ex) {
+                    // We should never get here
+                    throw new StreamException(ex);
+                }
+            } else {
+                throw new StreamException("Encountered unexpected attribute " + new QName(namespaceURI,
localName) + " on xop:Include element");
+            }
+        } else {
+            super.processAttribute(namespaceURI, localName, prefix, value, type, specified);
+        }
+    }
+
+    @Override
+    public void attributesCompleted() throws StreamException {
+        if (state != State.IN_XOP_INCLUDE) {
+            super.attributesCompleted();
+            state = State.AFTER_START_ELEMENT;
+        }
+    }
+
+    @Override
+    public void processCharacterData(Object data, boolean ignorable) throws StreamException
{
+        inContent();
+        super.processCharacterData(data, ignorable);
+    }
+
+    @Override
+    public void startProcessingInstruction(String target) throws StreamException {
+        inContent();
+        super.startProcessingInstruction(target);
+    }
+
+    @Override
+    public void endProcessingInstruction() throws StreamException {
+        inContent();
+        super.endProcessingInstruction();
+    }
+
+    @Override
+    public void startComment() throws StreamException {
+        inContent();
+        super.startComment();
+    }
+
+    @Override
+    public void endComment() throws StreamException {
+        inContent();
+        super.endComment();
+    }
+
+    @Override
+    public void startCDATASection() throws StreamException {
+        inContent();
+        super.startCDATASection();
+    }
+
+    @Override
+    public void endCDATASection() throws StreamException {
+        inContent();
+        super.endCDATASection();
+    }
+
+    @Override
+    public void processEntityReference(String name, String replacementText) throws StreamException
{
+        inContent();
+        super.processEntityReference(name, replacementText);
+    }
+}

Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/xop/XOPDecodingFilterHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message