You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/09/13 23:49:32 UTC
svn commit: r1384556 - in /cxf/branches/2.5.x-fixes: ./
common/common/src/main/java/org/apache/cxf/staxutils/transform/
common/common/src/test/java/org/apache/cxf/staxutils/resources/
common/common/src/test/java/org/apache/cxf/staxutils/transform/
Author: ay
Date: Thu Sep 13 21:49:32 2012
New Revision: 1384556
URL: http://svn.apache.org/viewvc?rev=1384556&view=rev
Log:
Merged revisions 1384552 via svn merge from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........
r1384552 | ay | 2012-09-13 23:33:42 +0200 (Thu, 13 Sep 2012) | 9 lines
Merged revisions 1384365 via svn merge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1384365 | ay | 2012-09-13 17:17:46 +0200 (Thu, 13 Sep 2012) | 1 line
[CXF-4503] TransformOutInterceptor may lose namespace declarations in some elements
........
........
Added:
cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml (with props)
cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml (with props)
cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml (with props)
cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml (with props)
Modified:
cxf/branches/2.5.x-fixes/ (props changed)
cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Propchange: cxf/branches/2.5.x-fixes/
('svn:mergeinfo' removed)
Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1384556&r1=1384555&r2=1384556&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java (original)
+++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java Thu Sep 13 21:49:32 2012
@@ -20,37 +20,52 @@ package org.apache.cxf.staxutils.transfo
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import javax.xml.namespace.NamespaceContext;
class DelegatingNamespaceContext implements NamespaceContext {
-
- private Map<String, String> prefixes = new HashMap<String, String>();
+ private List<Map<String, String>> prefixes;
private NamespaceContext nc;
private Map<String, String> nsMap;
public DelegatingNamespaceContext(NamespaceContext nc, Map<String, String> nsMap) {
this.nc = nc;
this.nsMap = nsMap;
+ this.prefixes = new LinkedList<Map<String, String>>();
+ this.prefixes.add(new HashMap<String, String>());
+ }
+
+ public void down() {
+ Map<String, String> pm = new HashMap<String, String>();
+ if (prefixes.size() > 0) {
+ pm.putAll(prefixes.get(0));
+ }
+ prefixes.add(0, pm);
+ }
+
+ public void up() {
+ prefixes.remove(0);
}
public void addPrefix(String prefix, String namespace) {
- prefixes.put(namespace, prefix);
+ prefixes.get(0).put(namespace, prefix);
}
public String findUniquePrefix(String namespace) {
if (namespace.length() == 0) {
return null;
}
- String existingPrefix = prefixes.get(namespace);
+ String existingPrefix = prefixes.get(0).get(namespace);
if (existingPrefix != null) {
return existingPrefix;
}
int i = 0;
while (true) {
- if (!prefixes.containsValue("ps" + ++i)) {
+ if (!prefixes.get(0).containsValue("ps" + ++i)) {
String prefix = "ps" + i;
addPrefix(prefix, namespace);
return prefix;
@@ -59,7 +74,7 @@ class DelegatingNamespaceContext impleme
}
public String getNamespaceURI(String prefix) {
- for (Map.Entry<String, String> entry : prefixes.entrySet()) {
+ for (Map.Entry<String, String> entry : prefixes.get(0).entrySet()) {
if (entry.getValue().equals(prefix)) {
return entry.getKey();
}
@@ -79,8 +94,8 @@ class DelegatingNamespaceContext impleme
}
String actualNs = value == null ? ns : value;
- if (prefixes.containsKey(actualNs)) {
- return prefixes.get(actualNs);
+ if (prefixes.get(0).containsKey(actualNs)) {
+ return prefixes.get(0).get(actualNs);
}
String prefix = nc.getPrefix(actualNs);
addPrefix(prefix, actualNs);
Modified: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1384556&r1=1384555&r2=1384556&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java (original)
+++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java Thu Sep 13 21:49:32 2012
@@ -111,6 +111,7 @@ public class InTransformReader extends D
int event = super.next();
if (event == XMLStreamConstants.START_ELEMENT) {
attributesIndexed = false;
+ namespaceContext.down();
final QName theName = super.getName();
final ElementProperty appendProp = inAppendMap.remove(theName);
final boolean replaceContent = appendProp != null && theName.equals(appendProp.getName());
@@ -168,6 +169,7 @@ public class InTransformReader extends D
LOG.fine("read EndElement " + theName + " at " + getDepth());
}
+ namespaceContext.up();
final boolean dropped = inDropSet.contains(theName);
if (!dropped) {
List<ParsingEvent> pe = pushedAheadEvents.pop();
Modified: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1384556&r1=1384555&r2=1384556&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java (original)
+++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java Thu Sep 13 21:49:32 2012
@@ -153,6 +153,7 @@ public class OutTransformWriter extends
@Override
public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
currentDepth++;
+ namespaceContext.down();
if (matchesDropped(false)) {
return;
}
@@ -293,6 +294,7 @@ public class OutTransformWriter extends
@Override
public void writeEndElement() throws XMLStreamException {
+ namespaceContext.up();
--currentDepth;
if (matchesDropped(false)) {
return;
Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml?rev=1384556&view=auto
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml (added)
+++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml Thu Sep 13 21:49:32 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ 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.
+-->
+<ns2:testDoubleBean xmlns:ns2="http://testbeans.com/double/v2">
+ <ns3:bean xmlns:ns3="http://testbeans.com/v3"/>
+ <ns3:beanNext xmlns:ns3="http://testbeans.com/v3"/>
+</ns2:testDoubleBean>
Propchange: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml?rev=1384556&view=auto
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml (added)
+++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml Thu Sep 13 21:49:32 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ 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.
+-->
+<ns2:testDoubleBean xmlns:ns2="http://testbeans.com/double">
+ <ns3:bean xmlns:ns3="http://testbeans.com"/>
+ <ns3:beanNext xmlns:ns3="http://testbeans.com"/>
+</ns2:testDoubleBean>
Propchange: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml?rev=1384556&view=auto
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml (added)
+++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml Thu Sep 13 21:49:32 2012
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ 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.
+-->
+<ns2:testDoubleBean xmlns:ns2="http://testbeans.com/double">
+ <bean xmlns="http://testbeans.com"/>
+ <beanNext xmlns="http://testbeans.com"/>
+</ns2:testDoubleBean>
+
Propchange: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml?rev=1384556&view=auto
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml (added)
+++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml Thu Sep 13 21:49:32 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ 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.
+-->
+<ns2:testDoubleBean xmlns="http://testbeans.com" xmlns:ns2="http://testbeans.com/double">
+ <bean/>
+ <beanNext/>
+</ns2:testDoubleBean>
Propchange: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java?rev=1384556&r1=1384555&r2=1384556&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java (original)
+++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java Thu Sep 13 21:49:32 2012
@@ -218,6 +218,74 @@ public class OutTransformWriterTest exte
}
@Test
+ public void testReadWithComplexTransformationNamespace2() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("{http://testbeans.com/double}*",
+ "{http://testbeans.com/double/v2}*");
+ map.put("{http://testbeans.com}*",
+ "{http://testbeans.com/v3}*");
+
+ // the namespaces are prefixed in the input
+ XMLStreamReader reader =
+ TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn1.xml",
+ map, null, null, null, false, null);
+ XMLStreamReader reader2 =
+ StaxUtils.createXMLStreamReader(
+ InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
+ TransformTestUtils.verifyReaders(reader2, reader, true, false);
+
+ // the child elements with the default namespace that is declared in the elements
+ reader =
+ TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn2.xml",
+ map, null, null, null, false, null);
+ reader2 =
+ StaxUtils.createXMLStreamReader(
+ InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
+ TransformTestUtils.verifyReaders(reader2, reader, true, false);
+
+ // the child elements with the default namespace that is declared in their parent element
+ reader =
+ TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn3.xml",
+ map, null, null, null, false, null);
+ reader2 =
+ StaxUtils.createXMLStreamReader(
+ InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
+ TransformTestUtils.verifyReaders(reader2, reader, true, false);
+
+ // writing each child separately (as the soap header children are serialized)
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ XMLStreamWriter writer =
+ new OutTransformWriter(StaxUtils.createXMLStreamWriter(os, "UTF-8"),
+ map, null,
+ null, null, false, null);
+ boolean nsset = "ns3".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com/double"));
+ writer.writeStartElement("ns3", "testDoubleBean", "http://testbeans.com/double");
+ if (!nsset) {
+ writer.writeNamespace("ns3", "http://testbeans.com/double");
+ }
+ nsset = "".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com"));
+ writer.writeStartElement("", "bean", "http://testbeans.com");
+ if (!nsset) {
+ writer.writeNamespace("", "http://testbeans.com");
+ }
+ writer.writeEndElement();
+ nsset = "".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com"));
+ writer.writeStartElement("", "beanNext", "http://testbeans.com");
+ if (!nsset) {
+ writer.writeNamespace("", "http://testbeans.com");
+ }
+ writer.writeEndElement();
+ writer.writeEndElement();
+ writer.flush();
+
+ reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(os.toByteArray()));
+ reader2 =
+ StaxUtils.createXMLStreamReader(
+ InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
+ TransformTestUtils.verifyReaders(reader2, reader, true, false);
+ }
+
+ @Test
public void testReadWithReplaceAppend() throws Exception {
Map<String, String> transformElements = new HashMap<String, String>();
transformElements.put("requestValue",