Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 88FEB9E2B for ; Mon, 3 Oct 2011 17:21:25 +0000 (UTC) Received: (qmail 45633 invoked by uid 500); 3 Oct 2011 17:21:25 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 45568 invoked by uid 500); 3 Oct 2011 17:21:25 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 45551 invoked by uid 99); 3 Oct 2011 17:21:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2011 17:21:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2011 17:21:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 35C7D23889DA for ; Mon, 3 Oct 2011 17:21:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Mon, 03 Oct 2011 17:21:01 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111003172101.35C7D23889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 attributesIndexes = new ArrayList(); @@ -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( + "1".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("1 2 3", value); + } + + @Test + public void testTransformAndReplaceSimpleElement() throws Exception { + InputStream is = new ByteArrayInputStream( + "1".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( + "1 2 3", value); + } + + @Test public void testReadWithParentDefaultNamespace() throws Exception { InputStream is = new ByteArrayInputStream( "".getBytes()); @@ -211,7 +246,7 @@ public class InTransformReaderTest exten @Test - public void testReadWithRepaceAppend() throws Exception { + public void testReadWithReplaceAppend() throws Exception { Map transformElements = new HashMap(); transformElements.put("requestValue", "{http://cxf.apache.org/hello_world_soap_http/types}requestType");