You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/10/03 19:21:01 UTC
svn commit: r1178466 - in /cxf/branches/2.4.x-fixes: ./
common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
Author: sergeyb
Date: Mon Oct 3 17:21:00 2011
New Revision: 1178466
URL: http://svn.apache.org/viewvc?rev=1178466&view=rev
Log:
Merged revisions 1178464 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1178464 | sergeyb | 2011-10-03 18:19:23 +0100 (Mon, 03 Oct 2011) | 1 line
[CXF-3843] Updating InTransformReader to optionally replace a text content
........
Modified:
cxf/branches/2.4.x-fixes/ (props changed)
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
cxf/branches/2.4.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:1178464
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1178466&r1=1178465&r2=1178466&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java (original)
+++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java Mon Oct 3 17:21:00 2011
@@ -49,6 +49,7 @@ public class InTransformReader extends D
private QName currentQName;
private QName pushBackQName;
private QName pushAheadQName;
+ private String replaceText;
private String currentText;
private String pushAheadText;
private List<Integer> attributesIndexes = new ArrayList<Integer>();
@@ -110,8 +111,11 @@ public class InTransformReader extends D
attributesIndexed = false;
final QName theName = super.getName();
final ElementProperty appendProp = inAppendMap.remove(theName);
+ final boolean replaced = appendProp != null && theName.equals(appendProp.getName());
+
final boolean dropped = inDropSet.contains(theName);
- if (appendProp != null) {
+ if (appendProp != null && !replaced) {
+
if (appendProp.isChild()) {
// append-post-*
pushAheadQName = appendProp.getName();
@@ -149,12 +153,16 @@ public class InTransformReader extends D
if (appendProp != null && appendProp.isChild()) {
// append-post-*
currentQName = expected;
- } else if (appendProp != null && !appendProp.isChild()) {
+ } else if (appendProp != null && !appendProp.isChild()
+ && !replaced) {
// append-pre-*
pushBackQName = expected;
} else {
// no append
currentQName = expected;
+ if (replaced) {
+ replaceText = appendProp.getText();
+ }
pushElement();
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
@@ -363,14 +371,24 @@ public class InTransformReader extends D
if (currentText != null) {
return currentText;
}
- return super.getText();
+ String superText = super.getText();
+ if (replaceText != null) {
+ superText = replaceText;
+ replaceText = null;
+ }
+ return superText;
}
public char[] getTextCharacters() {
if (currentText != null) {
return currentText.toCharArray();
}
- return super.getTextCharacters();
+ char[] superChars = super.getTextCharacters();
+ if (replaceText != null) {
+ superChars = replaceText.toCharArray();
+ replaceText = null;
+ }
+ return superChars;
}
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
Modified: cxf/branches/2.4.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java?rev=1178466&r1=1178465&r2=1178466&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java (original)
+++ cxf/branches/2.4.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java Mon Oct 3 17:21:00 2011
@@ -55,6 +55,41 @@ public class InTransformReaderTest exten
}
@Test
+ public void testReplaceSimpleElement() throws Exception {
+ InputStream is = new ByteArrayInputStream(
+ "<ns:test xmlns:ns=\"http://bar\"><ns:a>1</ns:a></ns:test>".getBytes());
+ XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+ reader = new InTransformReader(reader,
+ null,
+ Collections.singletonMap("{http://bar}a", "{http://bar}a:1 2 3"),
+ null,
+ null, false);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ StaxUtils.copy(reader, bos);
+ String value = bos.toString();
+ assertEquals("<ns:test xmlns:ns=\"http://bar\"><ns:a>1 2 3</ns:a></ns:test>", value);
+ }
+
+ @Test
+ public void testTransformAndReplaceSimpleElement() throws Exception {
+ InputStream is = new ByteArrayInputStream(
+ "<ns:test xmlns:ns=\"http://bar\"><ns:a>1</ns:a></ns:test>".getBytes());
+ XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+ reader = new InTransformReader(reader,
+ Collections.singletonMap("{http://bar}*", "{http://foo}*"),
+ Collections.singletonMap("{http://bar}a", "{http://bar}a:1 2 3"),
+ null,
+ null, false);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ StaxUtils.copy(reader, bos);
+ String value = bos.toString();
+ assertEquals(
+ "<ps1:test xmlns:ps1=\"http://foo\"><ps1:a>1 2 3</ps1:a></ps1:test>", value);
+ }
+
+ @Test
public void testReadWithParentDefaultNamespace() throws Exception {
InputStream is = new ByteArrayInputStream(
"<test xmlns=\"http://bar\"><ns:subtest xmlns:ns=\"http://bar1\"/></test>".getBytes());
@@ -211,7 +246,7 @@ public class InTransformReaderTest exten
@Test
- public void testReadWithRepaceAppend() throws Exception {
+ public void testReadWithReplaceAppend() throws Exception {
Map<String, String> transformElements = new HashMap<String, String>();
transformElements.put("requestValue",
"{http://cxf.apache.org/hello_world_soap_http/types}requestType");