cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1070973 [1/2] - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/ common/common/src/main/java/org/apache/cxf/staxutils/transform/ rt/core/src/main/java/org/apache/cxf/feature/ rt/core/src/main/java/org/apache/cxf/intercept...
Date Tue, 15 Feb 2011 17:07:09 GMT
Author: sergeyb
Date: Tue Feb 15 17:07:08 2011
New Revision: 1070973

URL: http://svn.apache.org/viewvc?rev=1070973&view=rev
Log:
[CXF-3338] Adding StaxTransformFeature

Added:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java   (with props)
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java   (with props)
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java   (with props)
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java   (with props)
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java   (with props)
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java   (with props)
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java   (with props)
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java   (with props)
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java   (with props)
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java   (with props)
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Tue Feb 15 17:07:08 2011
@@ -28,9 +28,11 @@ import java.io.OutputStream;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.WeakHashMap;
 import java.util.logging.Level;
@@ -455,4 +457,35 @@ public final class XMLUtils {
         trans.transform(src, res);
         return res.getNode();
     }
+    
+    public static QName convertStringToQName(String expandedQName) {
+        return convertStringToQName(expandedQName, "");
+    }
+    
+    public static QName convertStringToQName(String expandedQName, String prefix) {
+        int ind1 = expandedQName.indexOf('{');
+        if (ind1 != 0) {
+            return new QName(expandedQName);
+        }
+        
+        int ind2 = expandedQName.indexOf('}');
+        if (ind2 <= ind1 + 1 || ind2 >= expandedQName.length() - 1) {
+            return null;
+        }
+        String ns = expandedQName.substring(ind1 + 1, ind2);
+        String localName = expandedQName.substring(ind2 + 1);
+        return new QName(ns, localName, prefix);
+    }
+    
+    public static Set<QName> convertStringsToQNames(List<String> expandedQNames) {
+        Set<QName> dropElements = Collections.emptySet();
+        if (expandedQNames != null) {
+            dropElements = new LinkedHashSet<QName>(expandedQNames.size());
+            for (String val : expandedQNames) {
+                dropElements.add(XMLUtils.convertStringToQName(val));
+            }
+        }
+        return dropElements;
+    }
+    
 }

Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.cxf.staxutils.transform;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+
+class DelegatingNamespaceContext implements NamespaceContext {
+
+    private NamespaceContext nc;
+    private Map<String, String> nsMap;
+    
+    public DelegatingNamespaceContext(NamespaceContext nc, Map<String, String> nsMap) {
+        this.nc = nc;
+        this.nsMap = nsMap;
+    }
+    
+    public String getNamespaceURI(String prefix) {
+        return nc.getNamespaceURI(prefix);
+    }
+
+    public String getPrefix(String ns) {
+        String value = nsMap.get(ns);
+        if (value != null && value.length() == 0) {
+            return null;
+        }
+        return value != null ? nc.getPrefix(value) : nc.getPrefix(ns);
+    }
+
+    public Iterator getPrefixes(String ns) {
+        return nc.getPrefixes(ns);
+    }
+    
+}

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,47 @@
+/**
+ * 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.cxf.staxutils.transform;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
+
+public class IgnoreNamespacesWriter extends DelegatingXMLStreamWriter {
+    
+    public IgnoreNamespacesWriter(XMLStreamWriter writer) {
+        super(writer);
+    }
+
+    public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
+        super.writeStartElement(local);
+    }
+    
+    public void writeStartElement(String uri, String local) throws XMLStreamException {
+        super.writeStartElement(local);
+    }
+    
+    public void setPrefix(String pfx, String uri) throws XMLStreamException {
+        // completed
+    }
+    
+    public void setDefaultNamespace(String uri) throws XMLStreamException {
+        // completed
+    }
+}

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,126 @@
+/**
+ * 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.cxf.staxutils.transform;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
+
+public class InTransformReader extends DepthXMLStreamReader {
+    
+    private static final String INTERN_NAMES = "org.codehaus.stax2.internNames";
+    private static final String INTERN_NS = "org.codehaus.stax2.internNsUris";
+    
+    private QNamesMap inElementsMap;
+    private Map<QName, QName> inAppendMap = new HashMap<QName, QName>(5);
+    private Map<String, String> nsMap = new HashMap<String, String>(5);
+    private QName currentQName;
+    private QName previousQName;
+    private int previousDepth = -1;
+    
+    public InTransformReader(XMLStreamReader reader, 
+                             Map<String, String> inMap,
+                             Map<String, String> appendMap) {
+        super(reader);
+        inElementsMap = new QNamesMap(inMap == null ? 0 : inMap.size());
+        TransformUtils.convertToQNamesMap(inMap, inElementsMap, nsMap);
+        TransformUtils.convertToMapOfQNames(appendMap, inAppendMap);
+    }
+    
+    public int next() throws XMLStreamException {
+        if (currentQName != null) {
+            return XMLStreamConstants.START_ELEMENT;
+        } else if (previousDepth != -1 && previousDepth == getDepth() + 1) {
+            previousDepth = -1;
+            return XMLStreamConstants.END_ELEMENT;
+        } else {
+            return super.next();
+        }
+    }
+    
+    public Object getProperty(String name) throws IllegalArgumentException {
+
+        if (INTERN_NAMES.equals(name) || INTERN_NS.equals(name)) {
+            return Boolean.FALSE;
+        }
+        return super.getProperty(name);
+    }
+
+    public String getLocalName() {
+        QName cQName = getCurrentName();
+        if (cQName != null) {
+            String name = cQName.getLocalPart();
+            resetCurrentQName();
+            return name;
+        }
+        return super.getLocalName();
+    }
+
+    private QName getCurrentName() {
+        return currentQName != null ? currentQName 
+            : previousQName != null ? previousQName : null;
+    }
+    
+    private void resetCurrentQName() {
+        currentQName = previousQName;
+        previousQName = null;
+    }
+    
+    public NamespaceContext getNamespaceContext() {
+        return new DelegatingNamespaceContext(super.getNamespaceContext(), nsMap);
+    }
+
+    public String getNamespaceURI() {
+     
+        QName theName = readCurrentElement();
+        QName appendQName = inAppendMap.remove(theName);
+        if (appendQName != null) {
+            previousDepth = getDepth();
+            previousQName = theName;
+            currentQName = appendQName;
+            return currentQName.getNamespaceURI();
+        }
+        QName expected = inElementsMap.get(theName);
+        if (expected == null) {
+            return theName.getNamespaceURI();
+        }
+        currentQName = expected;
+        return currentQName.getNamespaceURI();
+    }
+    
+    private QName readCurrentElement() {
+        if (currentQName != null) {
+            return currentQName;
+        }
+        String ns = super.getNamespaceURI();
+        String name = super.getLocalName();
+        return new QName(ns, name);
+    }
+    
+    public QName getName() { 
+        return new QName(getNamespaceURI(), getLocalName());
+    }
+}

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,202 @@
+/**
+ * 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.cxf.staxutils.transform;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
+
+public class OutTransformWriter extends DelegatingXMLStreamWriter {
+    private QNamesMap elementsMap;
+    private Map<QName, QName> appendMap = new HashMap<QName, QName>(5);
+    private Map<String, String> nsMap = new HashMap<String, String>(5);
+    private Set<String> prefixes = new HashSet<String>(2);
+    private Set<String> writtenUris = new HashSet<String>(2);
+    
+    private Set<QName> dropElements;
+    private List<Integer> droppingIndexes = new LinkedList<Integer>();
+    private List<QName> appendedElements = new LinkedList<QName>();
+    private List<Integer> appendedIndexes = new LinkedList<Integer>();
+    private int currentDepth;
+    private boolean attributesToElements;
+    
+    public OutTransformWriter(XMLStreamWriter writer, 
+                              Map<String, String> outMap,
+                              Map<String, String> append,
+                              List<String> dropEls,
+                              boolean attributesToElements) {
+        super(writer);
+        elementsMap = new QNamesMap(outMap == null ? 0 : outMap.size());
+        TransformUtils.convertToQNamesMap(outMap, elementsMap, nsMap);
+        TransformUtils.convertToMapOfQNames(append, appendMap);
+        dropElements = XMLUtils.convertStringsToQNames(dropEls);
+        this.attributesToElements = attributesToElements;
+    }
+
+    @Override
+    public void writeNamespace(String prefix, String uri) throws XMLStreamException {
+        if (matchesDropped()) {
+            return;
+        }
+        if (writtenUris.contains(uri)) {
+            return;
+        }
+        String value = nsMap.get(uri);
+        if (value != null && value.length() == 0) {
+            return;
+        }
+        super.writeNamespace(prefix, value != null ? value : uri);
+    }
+    
+    @Override
+    public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
+        currentDepth++;
+        QName currentQName = new QName(uri, local);
+        
+        QName appendQName = appendMap.get(currentQName);
+        if (appendQName != null && !appendedElements.contains(appendQName)) {
+            currentDepth++;
+            String theprefix = uri.equals(appendQName.getNamespaceURI()) ? prefix : "";
+            write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(), theprefix));
+            if (theprefix.length() > 0) {
+                super.writeNamespace(theprefix, uri);
+                writtenUris.add(uri);
+            }
+            appendedElements.add(appendQName);
+            appendedIndexes.add(currentDepth - 1);
+        }
+        
+        if (dropElements.contains(currentQName)) {
+            droppingIndexes.add(currentDepth - 1);
+            return;
+        }
+        write(new QName(uri, local, prefix));
+    }
+    
+    @Override
+    public void writeEndElement() throws XMLStreamException {
+        --currentDepth;
+        if (indexRemoved(droppingIndexes)) {
+            return;
+        }
+        super.writeEndElement();
+        if (indexRemoved(appendedIndexes)) {
+            super.writeEndElement();
+        }
+    }
+    
+    @Override
+    public void writeCharacters(String text) throws XMLStreamException {
+        if (matchesDropped()) {
+            return;
+        }
+        super.writeCharacters(text);
+    }
+    
+    private void write(QName qname) throws XMLStreamException {
+        QName name = elementsMap.get(qname);
+        if (name == null) {
+            name = qname;
+        }
+        boolean writeNs = false;
+        String prefix = "";
+        if (name.getNamespaceURI().length() > 0) {
+            if (qname.getPrefix().length() == 0) {
+                prefix = findUniquePrefix();
+                writeNs = true;
+            } else {
+                prefix = qname.getPrefix();
+                prefixes.add(prefix);
+            }
+            prefixes.add(prefix);
+        }
+        super.writeStartElement(prefix, name.getLocalPart(), name.getNamespaceURI());
+        if (writeNs) {
+            this.writeNamespace(prefix, name.getNamespaceURI());
+        }
+    }
+    
+    private String findUniquePrefix() {
+        
+        int i = 0;
+        while (true) {
+            if (!prefixes.contains("ps" + ++i)) {
+                return "ps" + i;
+            }
+        }
+    }
+    
+    private boolean matchesDropped() {
+        int size = droppingIndexes.size();
+        if (size > 0 && droppingIndexes.get(size - 1) == currentDepth - 1) {
+            return true;
+        }
+        return false;
+    }
+    
+    private boolean indexRemoved(List<Integer> indexes) {
+        int size = indexes.size();
+        if (size > 0 && indexes.get(size - 1) == currentDepth) {
+            indexes.remove(size - 1);
+            return true;
+        }
+        return false;
+    }
+    
+    @Override
+    public NamespaceContext getNamespaceContext() {
+        return new DelegatingNamespaceContext(super.getNamespaceContext(), nsMap);
+    }
+    
+    @Override
+    public void writeAttribute(String uri, String local, String value) throws XMLStreamException {
+        if (!attributesToElements) {
+            super.writeAttribute(uri, local, value);
+        } else {
+            writeAttributeAsElement(uri, local, value);
+        }
+    }
+
+    @Override
+    public void writeAttribute(String local, String value) throws XMLStreamException {
+        if (!attributesToElements) {
+            super.writeAttribute(local, value);
+        } else {
+            writeAttributeAsElement("", local, value);
+        }
+    }
+    
+    private void writeAttributeAsElement(String uri, String local, String value)
+        throws XMLStreamException {
+        this.writeStartElement(uri, local);
+        this.writeCharacters(value);
+        this.writeEndElement();
+    }
+}

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,54 @@
+/**
+ * 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.cxf.staxutils.transform;
+
+import javax.xml.namespace.QName;
+
+class QNamesMap {
+    private QName[] keys;
+    private QName[] values;
+    private int index;
+    
+    public QNamesMap(int size) {
+        keys = new QName[size];
+        values = new QName[size];
+    }
+    
+    public void put(QName key, QName value) {
+        keys[index] = key;
+        values[index] = value;
+        index++;
+    }
+    
+    public QName get(QName key) {
+        for (int i = 0; i < keys.length; i++) {
+            if (keys[i].getNamespaceURI().equals(key.getNamespaceURI())) {
+                if (keys[i].getLocalPart().equals(key.getLocalPart())) {
+                    return values[i];
+                } else if ("*".equals(keys[i].getLocalPart())) {
+                    // assume it is something like {somens}* : *
+                    return "*".equals(values[i]) ? new QName(key.getLocalPart()) 
+                        : new QName(values[i].getNamespaceURI(), key.getLocalPart());
+                }
+            }
+        }
+        return null;    
+    }
+}

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/QNamesMap.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,106 @@
+/**
+ * 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.cxf.staxutils.transform;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.staxutils.StaxStreamFilter;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public final class TransformUtils {
+    private TransformUtils() {
+        
+    }
+    
+    public static XMLStreamReader createNewReaderIfNeeded(XMLStreamReader reader, InputStream is) {
+        return reader == null ? StaxUtils.createXMLStreamReader(is) : reader;
+    }
+    
+    public static XMLStreamWriter createNewWriterIfNeeded(XMLStreamWriter writer, OutputStream os) {
+        return writer == null ? StaxUtils.createXMLStreamWriter(os) : writer;
+    }
+    
+    public static XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer,
+                                                                OutputStream os,
+                                                                Map<String, String> outElementsMap,
+                                                                List<String> outDropElements,
+                                                                Map<String, String> outAppendMap,
+                                                                boolean attributesToElements) {
+        if (outElementsMap != null || outDropElements != null 
+            || outAppendMap != null || attributesToElements) {
+            writer = createNewWriterIfNeeded(writer, os);
+            writer = new OutTransformWriter(writer, outElementsMap, outAppendMap,
+                                            outDropElements, attributesToElements);
+        }
+        return writer;
+    }
+    
+    public static XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader, 
+                                                                InputStream is,
+                                                                List<String> inDropElements,
+                                                                Map<String, String> inElementsMap,
+                                                                Map<String, String> inAppendMap) {
+        if (inDropElements != null) {
+            Set<QName> dropElements = XMLUtils.convertStringsToQNames(inDropElements);
+            reader = StaxUtils.createFilteredReader(createNewReaderIfNeeded(reader, is),
+                                               new StaxStreamFilter(dropElements.toArray(new QName[]{})));    
+        }
+        if (inElementsMap != null || inAppendMap != null) {
+            reader = new InTransformReader(createNewReaderIfNeeded(reader, is),
+                                           inElementsMap, inAppendMap);
+        }
+        return reader;
+    }
+    
+    protected static void convertToQNamesMap(Map<String, String> map,
+                                             QNamesMap elementsMap,
+                                             Map<String, String> nsMap) {
+        if (map != null) {
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                QName lname = XMLUtils.convertStringToQName(entry.getKey());
+                QName rname = XMLUtils.convertStringToQName(entry.getValue());
+                elementsMap.put(lname, rname);
+                if (nsMap != null) {
+                    nsMap.put(lname.getNamespaceURI(), rname.getNamespaceURI());
+                }
+            }
+        }
+    }
+    
+    protected static void convertToMapOfQNames(Map<String, String> map,
+                                               Map<QName, QName> elementsMap) {
+        if (map != null) {
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                QName lname = XMLUtils.convertStringToQName(entry.getKey());
+                QName rname = XMLUtils.convertStringToQName(entry.getValue());
+                elementsMap.put(lname, rname);
+            }
+        }
+    }
+    
+}

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/TransformUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,86 @@
+/**
+ * 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.cxf.feature;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.interceptor.InterceptorProvider;
+import org.apache.cxf.interceptor.transform.TransformInInterceptor;
+import org.apache.cxf.interceptor.transform.TransformOutInterceptor;
+
+/**
+ * <pre>
+ * <![CDATA[
+    <jaxws:endpoint ...>
+      <jaxws:features>
+       <bean class="org.apache.cxf.feature.StaxTransformFeature"/>
+      </jaxws:features>
+    </jaxws:endpoint>
+  ]]>
+  </pre>
+ */
+@NoJSR250Annotations
+public class StaxTransformFeature extends AbstractFeature {
+    
+    private TransformInInterceptor in = new TransformInInterceptor();
+    private TransformOutInterceptor out = new TransformOutInterceptor();
+    
+    public StaxTransformFeature() {
+        //
+    }
+    
+    @Override
+    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+        
+        provider.getInInterceptors().add(in);
+        provider.getOutInterceptors().add(out);
+        provider.getOutFaultInterceptors().add(out);
+    }
+
+    public void setOutTransformElements(Map<String, String> outElements) {
+        out.setOutTransformElements(outElements);
+    }
+    
+    public void setAttributesToElements(boolean value) {
+        out.setAttributesToElements(value);
+    }
+    
+    public void setOutAppendElements(Map<String, String> map) {
+        out.setOutAppendElements(map);
+    }
+
+    public void setOutDropElements(List<String> dropElementsSet) {
+        out.setOutDropElements(dropElementsSet);
+    }
+    
+    public void setInAppendElements(Map<String, String> inElements) {
+        in.setInAppendElements(inElements);
+    }
+    
+    public void setInDropElements(List<String> dropElementsSet) {
+        in.setInDropElements(dropElementsSet);
+    }
+    
+    public void setInTransformElements(Map<String, String> inElements) {
+        in.setInTransformElements(inElements);
+    }
+}

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java Tue Feb 15 17:07:08 2011
@@ -24,14 +24,12 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.ResourceBundle;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
 import com.sun.xml.fastinfoset.stax.StAXDocumentSerializer;
 
-import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
@@ -45,8 +43,7 @@ import org.apache.cxf.phase.Phase;
 public class FIStaxOutInterceptor extends AbstractPhaseInterceptor<Message> {
     public static final String FI_ENABLED = "org.apache.cxf.fastinfoset.enabled";
     private static final String OUTPUT_STREAM_HOLDER = FIStaxOutInterceptor.class.getName() + ".outputstream";
-    private static final FIStaxOutEndingInterceptor ENDING = new FIStaxOutEndingInterceptor();
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(FIStaxOutInterceptor.class);
+    private static final StaxOutEndingInterceptor ENDING = new StaxOutEndingInterceptor(OUTPUT_STREAM_HOLDER);
 
     boolean force;
     
@@ -143,38 +140,6 @@ public class FIStaxOutInterceptor extend
         */
         return new StAXDocumentSerializer(out);
     }
-    public static class FIStaxOutEndingInterceptor extends AbstractPhaseInterceptor<Message> {
-        public FIStaxOutEndingInterceptor() {
-            super(Phase.PRE_STREAM_ENDING);
-            getAfter().add(AttachmentOutInterceptor.AttachmentOutEndingInterceptor.class.getName());
-        }
-
-        public void handleMessage(Message message) throws Fault {
-            try {
-                XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
-                if (xtw != null) {
-                    xtw.writeEndDocument();
-                    xtw.flush();
-                    xtw.close();
-                }
-                /*
-                if (xtw instanceof StAXDocumentSerializer) {
-                    ((StAXDocumentSerializer)xtw).setOutputStream(null);
-                    message.getExchange().get(Endpoint.class)
-                        .put(StAXDocumentSerializer.class.getName(), xtw);
-                }
-                */
-
-                OutputStream os = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
-                if (os != null) {
-                    message.setContent(OutputStream.class, os);
-                }
-                message.removeContent(XMLStreamWriter.class);
-            } catch (XMLStreamException e) {
-                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
-            }
-        }
-
-    }    
+        
 
 }

Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,63 @@
+/**
+ * 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.cxf.interceptor;
+
+import java.io.OutputStream;
+import java.util.ResourceBundle;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class StaxOutEndingInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(StaxOutEndingInterceptor.class);
+    
+    private String outStreamHolder;
+    
+    public StaxOutEndingInterceptor(String outStreamHolder) {
+        super(Phase.PRE_STREAM_ENDING);
+        getAfter().add(AttachmentOutInterceptor.AttachmentOutEndingInterceptor.class.getName());
+        this.outStreamHolder = outStreamHolder;
+    }
+
+    public void handleMessage(Message message) throws Fault {
+        try {
+            XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
+            if (xtw != null) {
+                xtw.writeEndDocument();
+                xtw.flush();
+                xtw.close();
+            }
+       
+            OutputStream os = (OutputStream)message.get(outStreamHolder);
+            if (os != null) {
+                message.setContent(OutputStream.class, os);
+            }
+            message.removeContent(XMLStreamWriter.class);
+        } catch (XMLStreamException e) {
+            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
+        }
+    }
+
+}

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutEndingInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java Tue Feb 15 17:07:08 2011
@@ -44,7 +44,7 @@ import org.apache.cxf.staxutils.StaxUtil
 public class StaxOutInterceptor extends AbstractPhaseInterceptor<Message> {
     public static final String OUTPUT_STREAM_HOLDER = StaxOutInterceptor.class.getName() + ".outputstream";
     public static final String FORCE_START_DOCUMENT = "org.apache.cxf.stax.force-start-document";
-    public static final StaxOutEndingInterceptor ENDING = new StaxOutEndingInterceptor();
+    public static final StaxOutEndingInterceptor ENDING = new StaxOutEndingInterceptor(OUTPUT_STREAM_HOLDER);
     
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(StaxOutInterceptor.class);
     private static Map<Object, XMLOutputFactory> factories = new HashMap<Object, XMLOutputFactory>();
@@ -151,30 +151,4 @@ public class StaxOutInterceptor extends 
         return null;
     }
     
-    public static class StaxOutEndingInterceptor extends AbstractPhaseInterceptor<Message> {
-        public StaxOutEndingInterceptor() {
-            super(Phase.PRE_STREAM_ENDING);
-            getAfter().add(AttachmentOutInterceptor.AttachmentOutEndingInterceptor.class.getName());
-        }
-
-        public void handleMessage(Message message) throws Fault {
-            try {
-                XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
-                if (xtw != null) {
-                    xtw.writeEndDocument();
-                    xtw.flush();
-                    xtw.close();
-                }
-
-                OutputStream os = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
-                if (os != null) {
-                    message.setContent(OutputStream.class, os);
-                }
-                message.removeContent(XMLStreamWriter.class);
-            } catch (XMLStreamException e) {
-                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
-            }
-        }
-
-    }    
 }

Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,81 @@
+/**
+ * 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.cxf.interceptor.transform;
+
+
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.interceptor.StaxInInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.transform.TransformUtils;
+
+
+/**
+ * Creates an XMLStreamReader from the InputStream on the Message.
+ */
+public class TransformInInterceptor extends AbstractPhaseInterceptor<Message> {
+    
+    protected List<String> inDropElements;
+    protected Map<String, String> inElementsMap;
+    protected Map<String, String> inAppendMap;
+    
+    public TransformInInterceptor() {
+        super(Phase.POST_STREAM);
+        addBefore(StaxInInterceptor.class.getName());
+    }
+    
+    public void handleMessage(Message message) {
+        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
+        InputStream is = message.getContent(InputStream.class);
+        
+        XMLStreamReader transformReader = createTransformReaderIfNeeded(reader, is);
+        if (transformReader != null) {
+            message.setContent(XMLStreamReader.class, transformReader);
+            message.removeContent(InputStream.class);
+        }
+         
+    }
+    
+    protected XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader, InputStream is) {
+        return TransformUtils.createTransformReaderIfNeeded(reader, is,
+                                                            inDropElements,
+                                                            inElementsMap,
+                                                            inAppendMap);
+    }
+    
+    public void setInAppendElements(Map<String, String> inElements) {
+        this.inAppendMap = inElements;
+    }
+    
+    public void setInDropElements(List<String> dropElementsSet) {
+        this.inDropElements = dropElementsSet;
+    }
+    
+    public void setInTransformElements(Map<String, String> inElements) {
+        this.inElementsMap = inElements;
+    }
+   
+}

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java?rev=1070973&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java Tue Feb 15 17:07:08 2011
@@ -0,0 +1,109 @@
+/**
+ * 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.cxf.interceptor.transform;
+
+
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
+import org.apache.cxf.interceptor.StaxOutEndingInterceptor;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.transform.TransformUtils;
+
+
+/**
+ * Creates an XMLStreamReader from the InputStream on the Message.
+ */
+public class TransformOutInterceptor extends AbstractPhaseInterceptor<Message> {
+    
+    private static final String OUTPUT_STREAM_HOLDER = 
+        TransformOutInterceptor.class.getName() + ".outputstream";
+    private static final StaxOutEndingInterceptor ENDING = new StaxOutEndingInterceptor(OUTPUT_STREAM_HOLDER);
+    
+    private Map<String, String> outElementsMap;
+    private Map<String, String> outAppendMap;
+    private List<String> outDropElements;
+    private boolean attributesToElements;
+    
+    public TransformOutInterceptor() {
+        super(Phase.PRE_STREAM);
+        addBefore(StaxOutInterceptor.class.getName());
+    }
+    
+    @Override
+    public void handleFault(Message message) {
+        super.handleFault(message);
+        OutputStream os = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
+        if (os != null) {
+            message.setContent(OutputStream.class, os);
+        }
+    }
+    
+    public void handleMessage(Message message) {
+        XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
+        OutputStream out = message.getContent(OutputStream.class);
+        
+        XMLStreamWriter transformWriter = createTransformWriterIfNeeded(writer, out);
+        if (transformWriter != null) {
+            message.setContent(XMLStreamWriter.class, transformWriter);
+            if (MessageUtils.isRequestor(message)) {
+                message.removeContent(OutputStream.class);
+                message.put(OUTPUT_STREAM_HOLDER, out);
+                message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION,
+                            Boolean.TRUE);
+                message.getInterceptorChain().add(ENDING);
+            }
+        }
+    }
+   
+    protected XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer, OutputStream os) {
+        return TransformUtils.createTransformWriterIfNeeded(writer, os, 
+                                                      outElementsMap,
+                                                      outDropElements,
+                                                      outAppendMap,
+                                                      attributesToElements);
+    }
+    
+    public void setOutTransformElements(Map<String, String> outElements) {
+        this.outElementsMap = outElements;
+    }
+    
+    public void setOutAppendElements(Map<String, String> map) {
+        this.outAppendMap = map;
+    }
+
+    public void setOutDropElements(List<String> dropElementsSet) {
+        this.outDropElements = dropElementsSet;
+    }
+
+    public void setAttributesToElements(boolean value) {
+        this.attributesToElements = value;
+    }
+    
+    
+}

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java Tue Feb 15 17:07:08 2011
@@ -72,6 +72,7 @@ import org.apache.cxf.common.xmlschema.X
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.jaxb.JAXBBeanInfo;
 import org.apache.cxf.jaxb.JAXBContextProxy;
 import org.apache.cxf.jaxb.JAXBUtils;
@@ -1079,7 +1080,7 @@ public class WadlGenerator implements Re
                 name = type.getAnnotation(XMLName.class);
             }
             if (name != null) {
-                QName qname = JAXRSUtils.convertStringToQName(name.value(), name.prefix());
+                QName qname = XMLUtils.convertStringToQName(name.value(), name.prefix());
                 if (qname.getPrefix().length() > 0) {
                     return qname;
                 } else {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Tue Feb 15 17:07:08 2011
@@ -27,12 +27,8 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -55,10 +51,7 @@ import javax.xml.bind.annotation.XmlAnyE
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.validation.Schema;
@@ -79,10 +72,7 @@ import org.apache.cxf.jaxrs.utils.Resour
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
-import org.apache.cxf.staxutils.DepthXMLStreamReader;
-import org.apache.cxf.staxutils.StaxStreamFilter;
-import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.transform.TransformUtils;
 
 public abstract class AbstractJAXBProvider extends AbstractConfigurableProvider
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
@@ -583,74 +573,6 @@ public abstract class AbstractJAXBProvid
         this.inDropElements = dropElementsSet;
     }
     
-    protected static Set<QName> convertToSetOfQNames(List<String> dropEls) {
-        Set<QName> dropElements = Collections.emptySet();
-        if (dropEls != null) {
-            dropElements = new LinkedHashSet<QName>(dropEls.size());
-            for (String val : dropEls) {
-                dropElements.add(JAXRSUtils.convertStringToQName(val));
-            }
-        }
-        return dropElements;
-    }
-    
-    protected XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader, InputStream is) {
-        if (inDropElements != null) {
-            Set<QName> dropElements = convertToSetOfQNames(inDropElements);
-            reader = StaxUtils.createFilteredReader(createNewReaderIfNeeded(reader, is),
-                                               new StaxStreamFilter(dropElements.toArray(new QName[]{})));    
-        }
-        if (inElementsMap != null || inAppendMap != null) {
-            reader = new InTransformReader(createNewReaderIfNeeded(reader, is),
-                                           inElementsMap, inAppendMap);
-        }
-        return reader;
-    }
-    
-    protected XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer,
-                                                            OutputStream os) {
-        if (outElementsMap != null || outDropElements != null 
-            || outAppendMap != null || attributesToElements) {
-            writer = createNewWriterIfNeeded(writer, os);
-            writer = new OutTransformWriter(writer, outElementsMap, outAppendMap,
-                                            outDropElements, attributesToElements);
-        }
-        return writer;
-    }
-    
-    protected XMLStreamReader createNewReaderIfNeeded(XMLStreamReader reader, InputStream is) {
-        return reader == null ? StaxUtils.createXMLStreamReader(is) : reader;
-    }
-    
-    protected XMLStreamWriter createNewWriterIfNeeded(XMLStreamWriter writer, OutputStream os) {
-        return writer == null ? StaxUtils.createXMLStreamWriter(os) : writer;
-    }
-    
-    protected static void convertToQNamesMap(Map<String, String> map,
-                                             QNamesMap elementsMap,
-                                             Map<String, String> nsMap) {
-        if (map != null) {
-            for (Map.Entry<String, String> entry : map.entrySet()) {
-                QName lname = JAXRSUtils.convertStringToQName(entry.getKey());
-                QName rname = JAXRSUtils.convertStringToQName(entry.getValue());
-                elementsMap.put(lname, rname);
-                if (nsMap != null) {
-                    nsMap.put(lname.getNamespaceURI(), rname.getNamespaceURI());
-                }
-            }
-        }
-    }
-    
-    protected static void convertToMapOfQNames(Map<String, String> map,
-                                               Map<QName, QName> elementsMap) {
-        if (map != null) {
-            for (Map.Entry<String, String> entry : map.entrySet()) {
-                QName lname = JAXRSUtils.convertStringToQName(entry.getKey());
-                QName rname = JAXRSUtils.convertStringToQName(entry.getValue());
-                elementsMap.put(lname, rname);
-            }
-        }
-    }
     
     
     public void setAttributesToElements(boolean value) {
@@ -710,323 +632,19 @@ public abstract class AbstractJAXBProvid
         
     }
     
-    protected static class OutTransformWriter extends DelegatingXMLStreamWriter {
-        private QNamesMap elementsMap;
-        private Map<QName, QName> appendMap = new HashMap<QName, QName>(5);
-        private Map<String, String> nsMap = new HashMap<String, String>(5);
-        private Set<String> prefixes = new HashSet<String>(2);
-        private Set<String> writtenUris = new HashSet<String>(2);
-        
-        private Set<QName> dropElements;
-        private List<Integer> droppingIndexes = new LinkedList<Integer>();
-        private List<QName> appendedElements = new LinkedList<QName>();
-        private List<Integer> appendedIndexes = new LinkedList<Integer>();
-        private int currentDepth;
-        private boolean attributesToElements;
-        
-        public OutTransformWriter(XMLStreamWriter writer, 
-                                  Map<String, String> outMap,
-                                  Map<String, String> append,
-                                  List<String> dropEls,
-                                  boolean attributesToElements) {
-            super(writer);
-            elementsMap = new QNamesMap(outMap == null ? 0 : outMap.size());
-            convertToQNamesMap(outMap, elementsMap, nsMap);
-            convertToMapOfQNames(append, appendMap);
-            dropElements = convertToSetOfQNames(dropEls);
-            this.attributesToElements = attributesToElements;
-        }
-
-        @Override
-        public void writeNamespace(String prefix, String uri) throws XMLStreamException {
-            if (matchesDropped()) {
-                return;
-            }
-            if (writtenUris.contains(uri)) {
-                return;
-            }
-            String value = nsMap.get(uri);
-            if (value != null && value.length() == 0) {
-                return;
-            }
-            super.writeNamespace(prefix, value != null ? value : uri);
-        }
-        
-        @Override
-        public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
-            currentDepth++;
-            QName currentQName = new QName(uri, local);
-            
-            QName appendQName = appendMap.get(currentQName);
-            if (appendQName != null && !appendedElements.contains(appendQName)) {
-                currentDepth++;
-                String theprefix = uri.equals(appendQName.getNamespaceURI()) ? prefix : "";
-                write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(), theprefix));
-                if (theprefix.length() > 0) {
-                    super.writeNamespace(theprefix, uri);
-                    writtenUris.add(uri);
-                }
-                appendedElements.add(appendQName);
-                appendedIndexes.add(currentDepth - 1);
-            }
-            
-            if (dropElements.contains(currentQName)) {
-                droppingIndexes.add(currentDepth - 1);
-                return;
-            }
-            write(new QName(uri, local, prefix));
-        }
-        
-        @Override
-        public void writeEndElement() throws XMLStreamException {
-            --currentDepth;
-            if (indexRemoved(droppingIndexes)) {
-                return;
-            }
-            super.writeEndElement();
-            if (indexRemoved(appendedIndexes)) {
-                super.writeEndElement();
-            }
-        }
-        
-        @Override
-        public void writeCharacters(String text) throws XMLStreamException {
-            if (matchesDropped()) {
-                return;
-            }
-            super.writeCharacters(text);
-        }
-        
-        private void write(QName qname) throws XMLStreamException {
-            QName name = elementsMap.get(qname);
-            if (name == null) {
-                name = qname;
-            }
-            boolean writeNs = false;
-            String prefix = "";
-            if (name.getNamespaceURI().length() > 0) {
-                if (qname.getPrefix().length() == 0) {
-                    prefix = findUniquePrefix();
-                    writeNs = true;
-                } else {
-                    prefix = qname.getPrefix();
-                    prefixes.add(prefix);
-                }
-                prefixes.add(prefix);
-            }
-            super.writeStartElement(prefix, name.getLocalPart(), name.getNamespaceURI());
-            if (writeNs) {
-                this.writeNamespace(prefix, name.getNamespaceURI());
-            }
-        }
-        
-        private String findUniquePrefix() {
-            
-            int i = 0;
-            while (true) {
-                if (!prefixes.contains("ps" + ++i)) {
-                    return "ps" + i;
-                }
-            }
-        }
-        
-        private boolean matchesDropped() {
-            int size = droppingIndexes.size();
-            if (size > 0 && droppingIndexes.get(size - 1) == currentDepth - 1) {
-                return true;
-            }
-            return false;
-        }
-        
-        private boolean indexRemoved(List<Integer> indexes) {
-            int size = indexes.size();
-            if (size > 0 && indexes.get(size - 1) == currentDepth) {
-                indexes.remove(size - 1);
-                return true;
-            }
-            return false;
-        }
-        
-        @Override
-        public NamespaceContext getNamespaceContext() {
-            return new DelegatingNamespaceContext(super.getNamespaceContext(), nsMap);
-        }
-        
-        @Override
-        public void writeAttribute(String uri, String local, String value) throws XMLStreamException {
-            if (!attributesToElements) {
-                super.writeAttribute(uri, local, value);
-            } else {
-                writeAttributeAsElement(uri, local, value);
-            }
-        }
-
-        @Override
-        public void writeAttribute(String local, String value) throws XMLStreamException {
-            if (!attributesToElements) {
-                super.writeAttribute(local, value);
-            } else {
-                writeAttributeAsElement("", local, value);
-            }
-        }
-        
-        private void writeAttributeAsElement(String uri, String local, String value)
-            throws XMLStreamException {
-            this.writeStartElement(uri, local);
-            this.writeCharacters(value);
-            this.writeEndElement();
-        }
-    }
-    
-    private static class QNamesMap {
-        private QName[] keys;
-        private QName[] values;
-        private int index;
-        
-        public QNamesMap(int size) {
-            keys = new QName[size];
-            values = new QName[size];
-        }
-        
-        public void put(QName key, QName value) {
-            keys[index] = key;
-            values[index] = value;
-            index++;
-        }
-        
-        public QName get(QName key) {
-            for (int i = 0; i < keys.length; i++) {
-                if (keys[i].getNamespaceURI().equals(key.getNamespaceURI())) {
-                    if (keys[i].getLocalPart().equals(key.getLocalPart())) {
-                        return values[i];
-                    } else if ("*".equals(keys[i].getLocalPart())) {
-                        // assume it is something like {somens}* : *
-                        return "*".equals(values[i]) ? new QName(key.getLocalPart()) 
-                            : new QName(values[i].getNamespaceURI(), key.getLocalPart());
-                    }
-                }
-            }
-            return null;    
-        }
+    protected XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer,
+                                                            OutputStream os) {
+        return TransformUtils.createTransformWriterIfNeeded(writer, os, 
+                                                      outElementsMap,
+                                                      outDropElements,
+                                                      outAppendMap,
+                                                      attributesToElements);
     }
     
-    protected static class InTransformReader extends DepthXMLStreamReader {
-        
-        private static final String INTERN_NAMES = "org.codehaus.stax2.internNames";
-        private static final String INTERN_NS = "org.codehaus.stax2.internNsUris";
-        
-        private QNamesMap inElementsMap;
-        private Map<QName, QName> inAppendMap = new HashMap<QName, QName>(5);
-        private Map<String, String> nsMap = new HashMap<String, String>(5);
-        private QName currentQName;
-        private QName previousQName;
-        private int previousDepth = -1;
-        
-        public InTransformReader(XMLStreamReader reader, 
-                                 Map<String, String> inMap,
-                                 Map<String, String> appendMap) {
-            super(reader);
-            inElementsMap = new QNamesMap(inMap == null ? 0 : inMap.size());
-            convertToQNamesMap(inMap, inElementsMap, nsMap);
-            convertToMapOfQNames(appendMap, inAppendMap);
-        }
-        
-        public int next() throws XMLStreamException {
-            if (currentQName != null) {
-                return XMLStreamConstants.START_ELEMENT;
-            } else if (previousDepth != -1 && previousDepth == getDepth() + 1) {
-                previousDepth = -1;
-                return XMLStreamConstants.END_ELEMENT;
-            } else {
-                return super.next();
-            }
-        }
-        
-        public Object getProperty(String name) throws IllegalArgumentException {
-
-            if (INTERN_NAMES.equals(name) || INTERN_NS.equals(name)) {
-                return Boolean.FALSE;
-            }
-            return super.getProperty(name);
-        }
-
-        public String getLocalName() {
-            QName cQName = getCurrentName();
-            if (cQName != null) {
-                String name = cQName.getLocalPart();
-                resetCurrentQName();
-                return name;
-            }
-            return super.getLocalName();
-        }
-
-        private QName getCurrentName() {
-            return currentQName != null ? currentQName 
-                : previousQName != null ? previousQName : null;
-        }
-        
-        private void resetCurrentQName() {
-            currentQName = previousQName;
-            previousQName = null;
-        }
-        
-        public NamespaceContext getNamespaceContext() {
-            return new DelegatingNamespaceContext(super.getNamespaceContext(), nsMap);
-        }
-
-        public String getNamespaceURI() {
-         
-            QName theName = readCurrentElement();
-            QName appendQName = inAppendMap.remove(theName);
-            if (appendQName != null) {
-                previousDepth = getDepth();
-                previousQName = theName;
-                currentQName = appendQName;
-                return currentQName.getNamespaceURI();
-            }
-            QName expected = inElementsMap.get(theName);
-            if (expected == null) {
-                return theName.getNamespaceURI();
-            }
-            currentQName = expected;
-            return currentQName.getNamespaceURI();
-        }
-        
-        private QName readCurrentElement() {
-            if (currentQName != null) {
-                return currentQName;
-            }
-            String ns = super.getNamespaceURI();
-            String name = super.getLocalName();
-            return new QName(ns, name);
-        }
-    }
-
-    private static class DelegatingNamespaceContext implements NamespaceContext {
-
-        private NamespaceContext nc;
-        private Map<String, String> nsMap;
-        
-        public DelegatingNamespaceContext(NamespaceContext nc, Map<String, String> nsMap) {
-            this.nc = nc;
-            this.nsMap = nsMap;
-        }
-        
-        public String getNamespaceURI(String prefix) {
-            return nc.getNamespaceURI(prefix);
-        }
-
-        public String getPrefix(String ns) {
-            String value = nsMap.get(ns);
-            if (value != null && value.length() == 0) {
-                return null;
-            }
-            return value != null ? nc.getPrefix(value) : nc.getPrefix(ns);
-        }
-
-        public Iterator getPrefixes(String ns) {
-            return nc.getPrefixes(ns);
-        }
-        
+    protected XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader, InputStream is) {
+        return TransformUtils.createTransformReaderIfNeeded(reader, is,
+                                                            inDropElements,
+                                                            inElementsMap,
+                                                            inAppendMap);
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Tue Feb 15 17:07:08 2011
@@ -62,6 +62,7 @@ import org.apache.cxf.message.Attachment
 import org.apache.cxf.message.Message;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.transform.TransformUtils;
 
 @Produces({"application/xml", "application/*+xml", "text/xml" })
 @Consumes({"application/xml", "application/*+xml", "text/xml" })
@@ -207,7 +208,7 @@ public class JAXBElementProvider extends
         
         reader = createTransformReaderIfNeeded(reader, is);
         if (InjectionUtils.isSupportedCollectionOrArray(type)) {
-            return new JAXBCollectionWrapperReader(createNewReaderIfNeeded(reader, is));
+            return new JAXBCollectionWrapperReader(TransformUtils.createNewReaderIfNeeded(reader, is));
         } else {
             return reader;
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java Tue Feb 15 17:07:08 2011
@@ -41,6 +41,7 @@ import org.apache.cxf.common.WSDLConstan
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
+import org.apache.cxf.staxutils.transform.IgnoreNamespacesWriter;
 import org.codehaus.jettison.AbstractXMLStreamWriter;
 import org.codehaus.jettison.badgerfish.BadgerFishXMLInputFactory;
 import org.codehaus.jettison.badgerfish.BadgerFishXMLOutputFactory;
@@ -118,7 +119,7 @@ public final class JSONUtils {
     
     public static XMLStreamWriter createIgnoreNsWriterIfNeeded(XMLStreamWriter writer, 
                                                                boolean ignoreNamespaces) {
-        return ignoreNamespaces ? new IgnoreNsWriter(writer) : writer; 
+        return ignoreNamespaces ? new IgnoreNamespacesWriter(writer) : writer; 
     }
     
     private static String getKey(MappedNamespaceConvention convention, QName qname) throws Exception {
@@ -286,26 +287,5 @@ public final class JSONUtils {
         
     }
     
-    private static class IgnoreNsWriter extends DelegatingXMLStreamWriter {
-        
-        public IgnoreNsWriter(XMLStreamWriter writer) {
-            super(writer);
-        }
-
-        public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
-            super.writeStartElement(local);
-        }
-        
-        public void writeStartElement(String uri, String local) throws XMLStreamException {
-            super.writeStartElement(local);
-        }
-        
-        public void setPrefix(String pfx, String uri) throws XMLStreamException {
-            // completed
-        }
-        
-        public void setDefaultNamespace(String uri) throws XMLStreamException {
-            // completed
-        }
-    }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue Feb 15 17:07:08 2011
@@ -70,6 +70,7 @@ import org.apache.cxf.common.i18n.Bundle
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.MessageContextImpl;
 import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
@@ -1215,21 +1216,7 @@ public final class JAXRSUtils {
     }
 
     public static QName convertStringToQName(String name) {
-        return convertStringToQName(name, "");
+        return XMLUtils.convertStringToQName(name, "");
     }
     
-    public static QName convertStringToQName(String name, String prefix) {
-        int ind1 = name.indexOf('{');
-        if (ind1 != 0) {
-            return new QName(name);
-        }
-        
-        int ind2 = name.indexOf('}');
-        if (ind2 <= ind1 + 1 || ind2 >= name.length() - 1) {
-            return null;
-        }
-        String ns = name.substring(ind1 + 1, ind2);
-        String localName = name.substring(ind2 + 1);
-        return new QName(ns, localName, prefix);
-    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Tue Feb 15 17:07:08 2011
@@ -45,13 +45,17 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.FIStaxInInterceptor;
 import org.apache.cxf.interceptor.FIStaxOutInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorProvider;
+import org.apache.cxf.interceptor.transform.TransformInInterceptor;
+import org.apache.cxf.interceptor.transform.TransformOutInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.client.ClientConfiguration;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
@@ -151,6 +155,45 @@ public class JAXRSSoapBookTest extends A
     }
     
     @Test
+    public void testGetBookTransform() throws Exception {
+        
+        String address = "http://localhost:" + PORT 
+                         + "/test/services/rest-transform/bookstore/books/123";
+        WebClient client = WebClient.create(address);
+        Response r = client.get();
+        String str = getStringFromInputStream((InputStream)r.getEntity());
+        assertTrue(str.contains("TheBook"));
+    }
+    
+    @Test
+    public void testPostBookTransform() throws Exception {
+           
+        String address = "http://localhost:" + PORT 
+                         + "/test/services/rest-transform/bookstore/books";
+        
+        TransformOutInterceptor out =  new TransformOutInterceptor();
+        out.setOutTransformElements(
+            Collections.singletonMap("{http://www.example.org/books}*", 
+                                     "{http://www.example.org/super-books}*"));
+        
+        TransformInInterceptor in =  new TransformInInterceptor();
+        Map<String, String> map = new HashMap<String, String>();
+
+        // If Book2 didn't have {http://www.example.org/books}Book
+        // then we'd just do '"*" : "{http://www.example.org/books}*'
+        // but given that we have TheBook being returned, we need
+        map.put("TheBook", "{http://www.example.org/books}Book");
+        map.put("id", "{http://www.example.org/books}id");
+        in.setInTransformElements(map);
+        
+        WebClient client = WebClient.create(address);
+        WebClient.getConfig(client).getInInterceptors().add(in);
+        WebClient.getConfig(client).getOutInterceptors().add(out);
+        Book2 book = client.accept("text/xml").post(new Book2(), Book2.class);
+        assertEquals(124L, book.getId());
+    }
+    
+    @Test
     public void testGetBookFastinfoset() throws Exception {
         
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
@@ -630,6 +673,35 @@ public class JAXRSSoapBookTest extends A
     }
     
     @Test
+    public void testGetUnqualifiedBookSoap() throws Exception {
+        String wsdlAddress =
+            "http://localhost:" + PORT + "/test/services/soap-transform/bookservice?wsdl"; 
+        URL wsdlUrl = new URL(wsdlAddress);
+        BookSoapService service = 
+            new BookSoapService(wsdlUrl,
+                                new QName("http://books.com", "BookService"));
+        BookStoreJaxrsJaxws store = service.getBookPort();
+        
+        TransformInInterceptor in =  new TransformInInterceptor();
+        Map<String, String> mapIn = new HashMap<String, String>();
+        mapIn.put("*", "{http://jaxws.jaxrs.systest.cxf.apache.org/}*");
+        in.setInTransformElements(mapIn);
+        
+        TransformOutInterceptor out =  new TransformOutInterceptor();
+        Map<String, String> mapOut = new HashMap<String, String>();
+        mapOut.put("{http://jaxws.jaxrs.systest.cxf.apache.org/}*", "getBookRequest");
+        out.setOutTransformElements(mapOut);
+        
+        
+        Client cl = ClientProxy.getClient(store);
+        cl.getInInterceptors().add(in);
+        cl.getOutInterceptors().add(out);
+        
+        Book book = store.getBook(new Long(123));
+        assertEquals("id is wrong", book.getId(), 123);
+    }
+    
+    @Test
     public void testServiceListingsAndWadl() throws Exception {
         String listings = 
             getStringFromInputStream(getHttpInputStream("http://localhost:" + PORT + "/test/services"));

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java?rev=1070973&r1=1070972&r2=1070973&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java Tue Feb 15 17:07:08 2011
@@ -46,7 +46,7 @@ import org.apache.cxf.systest.jaxrs.Book
 public class BookStoreSoapRestImpl implements BookStoreJaxrsJaxws {
 
     private Map<Long, Book> books = new HashMap<Long, Book>();
-    
+    private boolean ignoreJaxrsClient;
     @Resource
     private WebServiceContext jaxwsContext;
     @Resource
@@ -60,12 +60,18 @@ public class BookStoreSoapRestImpl imple
         init();
     }
     
+    public void setIgnoreJaxrsClient(boolean ignore) {
+        this.ignoreJaxrsClient = ignore;
+    }
+    
     @PostConstruct
     public void verifyWebClient() {
-        if (webClient == null) {
-            throw new RuntimeException();
+        if (!ignoreJaxrsClient) {
+            if (webClient == null) {
+                throw new RuntimeException();
+            }
+            WebClient.client(webClient).accept("application/xml");
         }
-        WebClient.client(webClient).accept("application/xml");
     }
     
     public Book getBook(Long id) throws BookNotFoundFault {
@@ -100,14 +106,17 @@ public class BookStoreSoapRestImpl imple
             }
             throw new WebApplicationException(builder.build());
         }
-        
-        if (!invocationInProcess) {
-            invocationInProcess = true;
-            return webClient.getBook(id);
+     
+        if (!ignoreJaxrsClient) {
+            if (!invocationInProcess) {
+                invocationInProcess = true;
+                return webClient.getBook(id);
+            }
+            invocationInProcess = false;
+            System.out.println(getContentType());
         }
-        invocationInProcess = false;
         
-        System.out.println(getContentType());
+        
         return books.get(id);
     }
     



Mime
View raw message