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 30842E78B for ; Sun, 23 Dec 2012 22:20:27 +0000 (UTC) Received: (qmail 2532 invoked by uid 500); 23 Dec 2012 22:20:27 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 2476 invoked by uid 500); 23 Dec 2012 22:20:27 -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 2463 invoked by uid 99); 23 Dec 2012 22:20:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Dec 2012 22:20:27 +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; Sun, 23 Dec 2012 22:20:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 21755238896F; Sun, 23 Dec 2012 22:19:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1425539 - 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/ Date: Sun, 23 Dec 2012 22:19:57 -0000 To: commits@cxf.apache.org From: ay@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121223221958.21755238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ay Date: Sun Dec 23 22:19:57 2012 New Revision: 1425539 URL: http://svn.apache.org/viewvc?rev=1425539&view=rev Log: Merged revisions 1425530 via svn merge from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes ........ r1425530 | ay | 2012-12-23 22:32:58 +0100 (Sun, 23 Dec 2012) | 9 lines Merged revisions 1425528 via svn merge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1425528 | ay | 2012-12-23 22:23:27 +0100 (Sun, 23 Dec 2012) | 1 line [CXF-4723] stax outTransform may generate duplicate ns declarations for global attributes ........ ........ Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml (with props) cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml (with props) cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java 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/ ------------------------------------------------------------------------------ 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=1425539&r1=1425538&r2=1425539&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 Sun Dec 23 22:19:57 2012 @@ -24,61 +24,72 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; class DelegatingNamespaceContext implements NamespaceContext { - private List> prefixes; private NamespaceContext nc; private Map nsMap; - + private List> namespaces; + private List> prefixes; + public DelegatingNamespaceContext(NamespaceContext nc, Map nsMap) { this.nc = nc; this.nsMap = nsMap; - this.prefixes = new LinkedList>(); - this.prefixes.add(new HashMap()); + namespaces = new LinkedList>(); + prefixes = new LinkedList>(); } public void down() { - Map pm = new HashMap(); - if (prefixes.size() > 0) { - pm.putAll(prefixes.get(0)); - } - prefixes.add(0, pm); + ((LinkedList>)namespaces).addFirst(new HashMap(8)); + ((LinkedList>)prefixes).addFirst(new HashMap(8)); } - + public void up() { - prefixes.remove(0); + ((LinkedList>)namespaces).removeFirst(); + ((LinkedList>)prefixes).removeFirst(); } - public void addPrefix(String prefix, String namespace) { - prefixes.get(0).put(namespace, prefix); + public void addPrefix(String prefix, String ns) { + ((LinkedList>)namespaces).getFirst().put(prefix, ns); + ((LinkedList>)prefixes).getFirst().put(ns, prefix); } - public String findUniquePrefix(String namespace) { - if (namespace.length() == 0) { + public String findUniquePrefix(String ns) { + if (ns.length() == 0) { return null; } - String existingPrefix = prefixes.get(0).get(namespace); + String existingPrefix = getPrefix(ns); if (existingPrefix != null) { return existingPrefix; } int i = 0; while (true) { - if (!prefixes.get(0).containsValue("ps" + ++i)) { - String prefix = "ps" + i; - addPrefix(prefix, namespace); + String prefix = "ps" + ++i; + if (getNamespaceURI(prefix) == null) { + addPrefix(prefix, ns); return prefix; } } } public String getNamespaceURI(String prefix) { - for (Map.Entry entry : prefixes.get(0).entrySet()) { - if (entry.getValue().equals(prefix)) { - return entry.getKey(); + if (!namespaces.isEmpty()) { + Map cache = ((LinkedList>)namespaces).getFirst(); + for (Map nss : namespaces) { + String ns = nss.get(prefix); + if (ns != null) { + cache.put(prefix, ns); + return ns; + } } } + if (XMLConstants.XML_NS_PREFIX.equals(prefix)) { + return XMLConstants.XML_NS_URI; + } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) { + return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + } String ns = nc.getNamespaceURI(prefix); if (ns != null && ns.length() > 0) { addPrefix(prefix, ns); @@ -94,20 +105,42 @@ class DelegatingNamespaceContext impleme if (value != null && value.length() == 0) { return null; } + if (value != null) { + ns = value; + } - String actualNs = value == null ? ns : value; - if (prefixes.get(0).containsKey(actualNs)) { - return prefixes.get(0).get(actualNs); + if (!prefixes.isEmpty()) { + Map cache = ((LinkedList>)prefixes).getFirst(); + for (Map pfs : prefixes) { + String prefix = pfs.get(ns); + if (prefix != null && ns.equals(getNamespaceURI(prefix))) { + cache.put(ns, prefix); + return prefix; + } + } + } + if (XMLConstants.XML_NS_URI.equals(ns)) { + return XMLConstants.XML_NS_PREFIX; + } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(ns)) { + return XMLConstants.XMLNS_ATTRIBUTE; } - String prefix = nc.getPrefix(actualNs); + + String prefix = nc.getPrefix(ns); if (prefix != null) { - addPrefix(prefix, actualNs); + addPrefix(prefix, ns); } return prefix; } - public Iterator getPrefixes(String ns) { - return nc.getPrefixes(ns); + public Iterator getPrefixes(String ns) { + List pl = new LinkedList(); + for (Map pfs : prefixes) { + String pf = pfs.get(ns); + if (pf != null && ns.equals(getNamespaceURI(pf))) { + pl.add(pf); + } + } + return pl.iterator(); } } 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=1425539&r1=1425538&r2=1425539&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 Sun Dec 23 22:19:57 2012 @@ -21,10 +21,10 @@ package org.apache.cxf.staxutils.transfo import java.util.ArrayList; 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 java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; @@ -49,8 +49,8 @@ public class InTransformReader extends D private Map inAppendMap = new HashMap(5); private Set inDropSet = new HashSet(5); private Map nsMap = new HashMap(5); - private Stack pushedBackEvents = new Stack(); - private Stack> pushedAheadEvents = new Stack>(); + private List pushedBackEvents = new LinkedList(); + private List> pushedAheadEvents = new LinkedList>(); private String replaceText; private ParsingEvent currentEvent; private List attributesIndexes = new ArrayList(); @@ -95,9 +95,9 @@ public class InTransformReader extends D public int next() throws XMLStreamException { final boolean doDebug = LOG.isLoggable(Level.FINE); - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { // consume events from the pushed back stack - currentEvent = pushedBackEvents.pop(); + currentEvent = pushedBackEvents.remove(0); if (doDebug) { LOG.fine("pushed event available: " + currentEvent); } @@ -146,7 +146,7 @@ public class InTransformReader extends D LOG.fine("replacing content with " + replaceText); } currentEvent = TransformUtils.createStartElementEvent(expected); - pushedAheadEvents.push(null); + pushedAheadEvents.add(0, null); } else if (dropped) { if (doDebug) { LOG.fine("shallow-dropping start " + expected); @@ -172,13 +172,13 @@ public class InTransformReader extends D namespaceContext.up(); final boolean dropped = inDropSet.contains(theName); if (!dropped) { - List pe = pushedAheadEvents.pop(); + List pe = pushedAheadEvents.remove(0); if (null != pe) { if (doDebug) { LOG.fine("pushed event found"); } - pushedBackEvents.addAll(pe); - currentEvent = pushedBackEvents.pop(); + pushedBackEvents.addAll(0, pe); + currentEvent = pushedBackEvents.remove(0); event = currentEvent.getEvent(); } else { if (doDebug) { @@ -207,45 +207,45 @@ public class InTransformReader extends D // ap-post-* if (null == appendProp.getText()) { // ap-post-wrap - pushedBackEvents.push(TransformUtils.createStartElementEvent(appendProp.getName())); + pushedBackEvents.add(0, TransformUtils.createStartElementEvent(appendProp.getName())); currentEvent = TransformUtils.createStartElementEvent(expected); List pe = new ArrayList(2); - pe.add(TransformUtils.createEndElementEvent(expected)); pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); - pushedAheadEvents.push(pe); + pe.add(TransformUtils.createEndElementEvent(expected)); + pushedAheadEvents.add(0, pe); } else { // ap-post-incl currentEvent = TransformUtils.createStartElementEvent(expected); - List pe = new ArrayList(); - pe.add(TransformUtils.createEndElementEvent(expected)); - pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); - pe.add(TransformUtils.createCharactersEvent(appendProp.getText())); + List pe = new ArrayList(4); pe.add(TransformUtils.createStartElementEvent(appendProp.getName())); - pushedAheadEvents.push(pe); + pe.add(TransformUtils.createCharactersEvent(appendProp.getText())); + pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); + pe.add(TransformUtils.createEndElementEvent(expected)); + pushedAheadEvents.add(0, pe); } } else { // ap-pre-* if (null == appendProp.getText()) { // ap-pre-wrap - pushedBackEvents.push(TransformUtils.createStartElementEvent(expected)); + pushedBackEvents.add(0, TransformUtils.createStartElementEvent(expected)); currentEvent = TransformUtils.createStartElementEvent(appendProp.getName()); - List pe = new ArrayList(); - pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); + List pe = new ArrayList(2); pe.add(TransformUtils.createEndElementEvent(expected)); - pushedAheadEvents.push(pe); + pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); + pushedAheadEvents.add(0, pe); } else { // ap-pre-incl - pushedBackEvents.push(TransformUtils.createStartElementEvent(expected)); - pushedBackEvents.push(TransformUtils.createEndElementEvent(appendProp.getName())); - pushedBackEvents.push(TransformUtils.createCharactersEvent(appendProp.getText())); + pushedBackEvents.add(0, TransformUtils.createStartElementEvent(expected)); + pushedBackEvents.add(0, TransformUtils.createEndElementEvent(appendProp.getName())); + pushedBackEvents.add(0, TransformUtils.createCharactersEvent(appendProp.getText())); currentEvent = TransformUtils.createStartElementEvent(appendProp.getName()); if (doDebug) { LOG.fine("ap-pre-incl " + appendProp.getName() + "=" + appendProp.getText()); } - pushedAheadEvents.push(null); + pushedAheadEvents.add(0, null); } } } @@ -255,9 +255,9 @@ public class InTransformReader extends D if (!name.equals(expected)) { List pe = new ArrayList(1); pe.add(TransformUtils.createEndElementEvent(expected)); - pushedAheadEvents.push(pe); + pushedAheadEvents.add(0, pe); } else { - pushedAheadEvents.push(null); + pushedAheadEvents.add(0, null); } } @@ -293,7 +293,7 @@ public class InTransformReader extends D QName name = readCurrentElement(); String prefix = name.getPrefix(); if (prefix.length() == 0 && getNamespaceURI().length() > 0) { - prefix = getNamespaceContext().getPrefix(getNamespaceURI()); + prefix = namespaceContext.getPrefix(getNamespaceURI()); if (prefix == null) { prefix = ""; } @@ -352,7 +352,7 @@ public class InTransformReader extends D } public int getAttributeCount() { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { return 0; } checkAttributeIndexRange(-1); @@ -360,7 +360,7 @@ public class InTransformReader extends D } public String getAttributeLocalName(int arg0) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { throwIndexException(arg0, 0); } checkAttributeIndexRange(arg0); @@ -369,7 +369,7 @@ public class InTransformReader extends D } public QName getAttributeName(int arg0) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { throwIndexException(arg0, 0); } checkAttributeIndexRange(arg0); @@ -380,7 +380,7 @@ public class InTransformReader extends D } public String getAttributeNamespace(int arg0) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { throwIndexException(arg0, 0); } checkAttributeIndexRange(arg0); @@ -389,7 +389,7 @@ public class InTransformReader extends D } public String getAttributePrefix(int arg0) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { throwIndexException(arg0, 0); } checkAttributeIndexRange(arg0); @@ -408,7 +408,7 @@ public class InTransformReader extends D } public String getAttributeType(int arg0) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { throwIndexException(arg0, 0); } checkAttributeIndexRange(arg0); @@ -416,7 +416,7 @@ public class InTransformReader extends D } public String getAttributeValue(int arg0) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { throwIndexException(arg0, 0); } checkAttributeIndexRange(arg0); @@ -424,7 +424,7 @@ public class InTransformReader extends D } public String getAttributeValue(String namespace, String localName) { - if (!pushedBackEvents.empty()) { + if (!pushedBackEvents.isEmpty()) { return null; } checkAttributeIndexRange(-1); 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=1425539&r1=1425538&r2=1425539&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 Sun Dec 23 22:19:57 2012 @@ -25,7 +25,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Stack; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; @@ -47,8 +46,8 @@ public class OutTransformWriter extends private List> writtenUris = new LinkedList>(); private Set dropElements; - private Stack> pushedAheadEvents = new Stack>(); - private Stack elementsStack = new Stack(); + private List> pushedAheadEvents = new LinkedList>(); + private List elementsStack = new LinkedList(); private String replaceNamespace; private String replaceText; private int currentDepth; @@ -104,7 +103,7 @@ public class OutTransformWriter extends uri = value != null ? value : uri; if (writtenUris.get(0).contains(uri) - && (prefix.length() == 0 || prefix.equals(getPrefix(uri)))) { + && (prefix.length() == 0 || prefix.equals(namespaceContext.getPrefix(uri)))) { return; } @@ -136,7 +135,7 @@ public class OutTransformWriter extends uri = value != null ? value : uri; - if (writtenUris.get(0).contains(uri) && "".equals(getPrefix(uri))) { + if (writtenUris.get(0).contains(uri) && "".equals(namespaceContext.getPrefix(uri))) { return; } super.writeDefaultNamespace(uri); @@ -189,7 +188,7 @@ public class OutTransformWriter extends // if the element is promoted to a qualified element, use the prefix bound // to that namespace. If the namespace is unbound, generate a new prefix and // write its declaration later. - prefix = getPrefix(expected.getNamespaceURI()); + prefix = namespaceContext.getPrefix(expected.getNamespaceURI()); if (prefix == null) { prefix = namespaceContext.findUniquePrefix(expected.getNamespaceURI()); } @@ -208,7 +207,7 @@ public class OutTransformWriter extends boolean nsadded = false; if (theprefix == null) { nsadded = true; - theprefix = getPrefix(appendQName.getNamespaceURI()); + theprefix = namespaceContext.getPrefix(appendQName.getNamespaceURI()); if (theprefix == null && (appendQName.getNamespaceURI().equals(expected.getNamespaceURI()) && expected.getPrefix().length() > 0)) { @@ -230,8 +229,8 @@ public class OutTransformWriter extends pe = new ArrayList(); pe.add(TransformUtils.createEndElementEvent(expected)); pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); - pushedAheadEvents.push(null); - elementsStack.push(appendQName); + pushedAheadEvents.add(0, null); + elementsStack.add(0, appendQName); } else { // ap-pre-incl super.writeCharacters(appendProp.getText()); @@ -243,11 +242,11 @@ public class OutTransformWriter extends replaceText = appendProp.getText(); } else if (dropped) { // unwrap the current element (shallow drop) - elementsStack.push(theName); + elementsStack.add(0, theName); return; } else if (TransformUtils.isEmptyQName(expected)) { // skip the current element (deep drop)); - dropDepth = currentDepth - 1; + dropDepth = currentDepth; return; } write(expected, false); @@ -255,38 +254,38 @@ public class OutTransformWriter extends // the element is promoted to a qualified element, thus write its declaration writeNamespace(expected.getPrefix(), expected.getNamespaceURI()); } - pushedAheadEvents.push(pe); - elementsStack.push(expected); + pushedAheadEvents.add(0, pe); + elementsStack.add(0, expected); replaceNamespace = expected.getNamespaceURI().equals(theName.getNamespaceURI()) ? null : theName.getNamespaceURI(); if (appendProp != null && !replaceContent && appendProp.isChild()) { // ap-post-* QName appendQName = appendProp.getName(); - String theprefix = getPrefix(appendQName.getNamespaceURI()); + String theprefix = namespaceContext.getPrefix(appendQName.getNamespaceURI()); if (appendProp.getText() == null) { // ap-post-wrap write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(), theprefix == null ? "" : theprefix), false); - if (getNamespaceContext().getPrefix(appendQName.getNamespaceURI()) == null) { + if (namespaceContext.getPrefix(appendQName.getNamespaceURI()) == null) { this.writeNamespace(theprefix, uri); } currentDepth++; pe = new ArrayList(); pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); pe.add(TransformUtils.createEndElementEvent(expected)); - pushedAheadEvents.push(pe); - elementsStack.push(appendQName); + pushedAheadEvents.add(0, pe); + elementsStack.add(0, appendQName); } else { // ap-post-incl - pushedAheadEvents.pop(); + pushedAheadEvents.remove(0); pe = new ArrayList(); pe.add(TransformUtils.createStartElementEvent(appendProp.getName())); pe.add(TransformUtils.createCharactersEvent(appendProp.getText())); pe.add(TransformUtils.createEndElementEvent(appendProp.getName())); pe.add(TransformUtils.createEndElementEvent(expected)); - pushedAheadEvents.push(pe); + pushedAheadEvents.add(0, pe); } } } @@ -294,9 +293,12 @@ public class OutTransformWriter extends @Override public void writeStartElement(String uri, String local) throws XMLStreamException { + /* pushedAheadEvents.push(null); elementsStack.push(new QName(uri, local)); super.writeStartElement(uri, local); + */ + writeStartElement("", local, uri); } @Override @@ -306,20 +308,22 @@ public class OutTransformWriter extends @Override public void writeEndElement() throws XMLStreamException { + final boolean indrop = matchesDropped(false); namespaceContext.up(); --currentDepth; - if (matchesDropped(false)) { + if (indrop) { + if (dropDepth > currentDepth) { + dropDepth = 0; + } return; - } else if (dropDepth > 0) { - dropDepth = 0; } if (!writtenUris.isEmpty()) { writtenUris.remove(0); } - QName theName = elementsStack.pop(); + QName theName = elementsStack.remove(0); final boolean dropped = dropElements.contains(theName); if (!dropped) { - List pes = pushedAheadEvents.pop(); + List pes = pushedAheadEvents.remove(0); if (null != pes) { for (ParsingEvent pe : pes) { switch (pe.getEvent()) { @@ -360,7 +364,7 @@ public class OutTransformWriter extends if ((replacePrefix || isDefaultNamespaceRedefined()) && qname.getPrefix().length() == 0) { // if the default namespace is configured to be replaced, a non-empty prefix must be assigned - prefix = getPrefix(qname.getNamespaceURI()); + prefix = namespaceContext.getPrefix(qname.getNamespaceURI()); if (prefix == null) { prefix = namespaceContext.findUniquePrefix(qname.getNamespaceURI()); writeNs = true; @@ -391,7 +395,7 @@ public class OutTransformWriter extends private boolean matchesDropped(boolean shallow) { if ((dropDepth > 0 && dropDepth <= currentDepth) - || (shallow && (elementsStack.size() > 0 && dropElements.contains(elementsStack.peek())))) { + || (shallow && (elementsStack.size() > 0 && dropElements.contains(elementsStack.get(0))))) { return true; } return false; Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml?rev=1425539&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml (added) +++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml Sun Dec 23 22:19:57 2012 @@ -0,0 +1,32 @@ + + + + + http://apache.org/hello_world_soap_http/Greeter/greetMeRequest + urn:uuid:f40b7881-170e-455c-a78b-77d246fa7ac1 + http://localhost:9002/SoapContext/SoapPort + Key#123456789 + + + + implicit1 + + + Propchange: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml?rev=1425539&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml (added) +++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml Sun Dec 23 22:19:57 2012 @@ -0,0 +1,35 @@ + + + + + http://apache.org/hello_world_soap_http/Greeter/greetMeRequest + urn:uuid:f40b7881-170e-455c-a78b-77d246fa7ac1 + http://localhost:9002/SoapContext/SoapPort + +
http://localhost:9001/decoupled_endpoint
+
+ Key#123456789 +
+ + + implicit1 + + +
Propchange: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java?rev=1425539&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java (added) +++ cxf/branches/2.5.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java Sun Dec 23 22:19:57 2012 @@ -0,0 +1,127 @@ +/** + * 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.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import javax.xml.namespace.NamespaceContext; + +import org.junit.Assert; +import org.junit.Test; + +public class DelegatingNamespaceContextTest extends Assert { + + @Test + public void testSomeAddsAndGets() throws Exception { + DelegatingNamespaceContext dnc = getTestDelegatingNamespaceContext(); + + dnc.down(); //1 + dnc.addPrefix("p1", "urn:foo1"); + dnc.addPrefix("p2", "urn:foo2"); + assertEquals("urn:foo0", dnc.getNamespaceURI("p0")); + assertEquals("urn:foo1", dnc.getNamespaceURI("p1")); + assertEquals("urn:foo2", dnc.getNamespaceURI("p2")); + assertEquals("p0", dnc.getPrefix("urn:foo0")); + assertEquals("p1", dnc.getPrefix("urn:foo1")); + assertEquals("p2", dnc.getPrefix("urn:foo2")); + verifyPrefixes(dnc.getPrefixes("urn:foo1"), new String[]{"p1"}); + verifyPrefixes(dnc.getPrefixes("urn:foo2"), new String[]{"p2"}); + + dnc.down(); //2 + dnc.addPrefix("p11", "urn:foo1"); + dnc.addPrefix("p2", "urn:foo22"); + dnc.addPrefix("p3", "urn:foo3"); + assertEquals("urn:foo1", dnc.getNamespaceURI("p1")); + assertEquals("urn:foo1", dnc.getNamespaceURI("p11")); + assertEquals("urn:foo22", dnc.getNamespaceURI("p2")); + assertEquals("urn:foo3", dnc.getNamespaceURI("p3")); + String p = dnc.getPrefix("urn:foo1"); + assertTrue("p1".equals(p) || "p11".equals(p)); + assertNull(dnc.getPrefix("urn:foo2")); + assertEquals("p2", dnc.getPrefix("urn:foo22")); + assertEquals("p3", dnc.getPrefix("urn:foo3")); + p = dnc.findUniquePrefix("urn:foo4"); + assertNotNull(p); + assertEquals(p, dnc.getPrefix("urn:foo4")); + assertEquals("urn:foo4", dnc.getNamespaceURI(p)); + verifyPrefixes(dnc.getPrefixes("urn:foo1"), new String[]{"p1", "p11"}); + verifyPrefixes(dnc.getPrefixes("urn:foo2"), new String[]{}); + verifyPrefixes(dnc.getPrefixes("urn:foo22"), new String[]{"p2"}); + verifyPrefixes(dnc.getPrefixes("urn:foo3"), new String[]{"p3"}); + + dnc.up(); //1 + assertEquals("urn:foo1", dnc.getNamespaceURI("p1")); + assertNull(dnc.getNamespaceURI("p11")); + assertEquals("urn:foo2", dnc.getNamespaceURI("p2")); + assertNull(dnc.getNamespaceURI("p3")); + assertEquals("p1", dnc.getPrefix("urn:foo1")); + assertNull(dnc.getPrefix("urn:foo11")); + assertEquals("p2", dnc.getPrefix("urn:foo2")); + assertNull(dnc.getPrefix("urn:foo22")); + assertNull(dnc.getPrefix("urn:foo3")); + verifyPrefixes(dnc.getPrefixes("urn:foo1"), new String[]{"p1"}); + verifyPrefixes(dnc.getPrefixes("urn:foo2"), new String[]{"p2"}); + verifyPrefixes(dnc.getPrefixes("urn:foo3"), new String[]{}); + + dnc.up(); //0 + + try { + dnc.up(); //-1 + fail("not allowed to go up"); + } catch (Exception e) { + // ignore + } + } + + private DelegatingNamespaceContext getTestDelegatingNamespaceContext() { + return new DelegatingNamespaceContext( + new NamespaceContext() { + public String getNamespaceURI(String prefix) { + return "p0".equals(prefix) ? "urn:foo0" : null; + } + public String getPrefix(String ns) { + return "urn:foo0".equals(ns) ? "p0" : null; + } + public Iterator getPrefixes(String ns) { + return null; + } + }, + Collections.singletonMap("urn:foo5", "urn:foo55")); + } + + private void verifyPrefixes(Iterator prefixes, String[] values) { + Set tmp = new HashSet(); + while (prefixes.hasNext()) { + tmp.add(prefixes.next()); + } + for (String v : values) { + if (tmp.contains(v)) { + tmp.remove(v); + } else { + fail("not expected: " + v); + } + } + assertTrue(tmp.isEmpty()); + } + + +} 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=1425539&r1=1425538&r2=1425539&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 Sun Dec 23 22:19:57 2012 @@ -115,9 +115,9 @@ public class OutTransformWriterTest exte String xmlPI = ""; String start = ""; + + " xmlns:ps2=\"http://testbeans.com/v3\">"; String expected2 = xmlPI + start - + ">"; + + ">"; String out = os.toString(); assertTrue("Output \"" + out + "\" does not match expected values", expected1.equals(out) || expected2.equals(out)); @@ -533,4 +533,13 @@ public class OutTransformWriterTest exte assertEquals("1", value); } + @Test + public void testNamespacedAttributeDropElement() throws Exception { + Map transformElements = new HashMap(); + transformElements.put("{http://www.w3.org/2005/08/addressing}ReplyTo", ""); + TransformTestUtils.transformOutStreamAndCompare("../resources/greetMeWSAReqIn.xml", + "../resources/greetMeWSAReq.xml", + transformElements, null, null, null, null); + } + }