cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1425528 - in /cxf/trunk/api/src: main/java/org/apache/cxf/staxutils/transform/ test/java/org/apache/cxf/staxutils/resources/ test/java/org/apache/cxf/staxutils/transform/
Date Sun, 23 Dec 2012 21:23:28 GMT
Author: ay
Date: Sun Dec 23 21:23:27 2012
New Revision: 1425528

URL: http://svn.apache.org/viewvc?rev=1425528&view=rev
Log:
[CXF-4723] stax outTransform may generate duplicate ns declarations for global attributes

Added:
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml   (with
props)
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml   (with
props)
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1425528&r1=1425527&r2=1425528&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
Sun Dec 23 21:23:27 2012
@@ -18,69 +18,79 @@
  */
 package org.apache.cxf.staxutils.transform;
 
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 
-import org.apache.cxf.helpers.CastUtils;
-
 class DelegatingNamespaceContext implements NamespaceContext {
-    private List<Map<String, String>> prefixes;
     private NamespaceContext nc;
     private Map<String, String> nsMap;
-    
+    private Deque<Map<String, String>> namespaces;
+    private Deque<Map<String, String>> prefixes;
+
     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>());
+        namespaces = new LinkedList<Map<String, String>>();
+        prefixes = new LinkedList<Map<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);
+        namespaces.addFirst(new HashMap<String, String>(8));
+        prefixes.addFirst(new HashMap<String, String>(8));
     }
-    
+
     public void up() {
-        prefixes.remove(0);
+        namespaces.removeFirst();
+        prefixes.removeFirst();
     }
     
-    public void addPrefix(String prefix, String namespace) {
-        prefixes.get(0).put(namespace, prefix);
+    public void addPrefix(String prefix, String ns) {
+        namespaces.getFirst().put(prefix, ns);
+        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<String, String> entry : prefixes.get(0).entrySet()) {
-            if (entry.getValue().equals(prefix)) {
-                return entry.getKey();
+        if (!namespaces.isEmpty()) {
+            Map<String, String> cache = namespaces.getFirst();
+            for (Map<String, String> 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);
@@ -96,20 +106,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<String, String> cache = prefixes.getFirst();
+            for (Map<String, String> pfs : prefixes) {
+                String prefix = pfs.get(ns);
+                if (prefix != null && ns.equals(getNamespaceURI(prefix))) {
+                    cache.put(ns, prefix);
+                    return prefix;
+                }
+            }
         }
-        String prefix = nc.getPrefix(actualNs);
+        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(ns);
         if (prefix != null) {
-            addPrefix(prefix, actualNs);
+            addPrefix(prefix, ns);
         }
         return prefix;
     }
 
     public Iterator<String> getPrefixes(String ns) {
-        return CastUtils.cast(nc.getPrefixes(ns));
+        List<String> pl = new LinkedList<String>();
+        for (Map<String, String> pfs : prefixes) {
+            String pf = pfs.get(ns);
+            if (pf != null && ns.equals(getNamespaceURI(pf))) {
+                pl.add(pf);
+            }
+        }
+        return pl.iterator();
     }
     
 }

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1425528&r1=1425527&r2=1425528&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Sun Dec 23 21:23:27 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<QName, ElementProperty> inAppendMap = new HashMap<QName, ElementProperty>(5);
     private Set<QName> inDropSet = new HashSet<QName>(5);
     private Map<String, String> nsMap = new HashMap<String, String>(5);
-    private Stack<ParsingEvent> pushedBackEvents = new Stack<ParsingEvent>();
-    private Stack<List<ParsingEvent>> pushedAheadEvents = new Stack<List<ParsingEvent>>();
+    private List<ParsingEvent> pushedBackEvents = new LinkedList<ParsingEvent>();
+    private List<List<ParsingEvent>> pushedAheadEvents = new LinkedList<List<ParsingEvent>>();
     private String replaceText;
     private ParsingEvent currentEvent;
     private List<Integer> attributesIndexes = new ArrayList<Integer>(); 
@@ -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<ParsingEvent> pe = pushedAheadEvents.pop();
+                List<ParsingEvent> 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<ParsingEvent> pe = new ArrayList<ParsingEvent>(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<ParsingEvent> pe = new ArrayList<ParsingEvent>();
-                pe.add(TransformUtils.createEndElementEvent(expected));
-                pe.add(TransformUtils.createEndElementEvent(appendProp.getName()));
-                pe.add(TransformUtils.createCharactersEvent(appendProp.getText()));
+                List<ParsingEvent> pe = new ArrayList<ParsingEvent>(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<ParsingEvent> pe = new ArrayList<ParsingEvent>();
-                pe.add(TransformUtils.createEndElementEvent(appendProp.getName()));
+                List<ParsingEvent> pe = new ArrayList<ParsingEvent>(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<ParsingEvent> pe = new ArrayList<ParsingEvent>(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/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1425528&r1=1425527&r2=1425528&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
Sun Dec 23 21:23:27 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<Set<String>> writtenUris = new LinkedList<Set<String>>();
     
     private Set<QName> dropElements;
-    private Stack<List<ParsingEvent>> pushedAheadEvents = new Stack<List<ParsingEvent>>();
-    private Stack<QName> elementsStack = new Stack<QName>();
+    private List<List<ParsingEvent>> pushedAheadEvents = new LinkedList<List<ParsingEvent>>();
+    private List<QName> elementsStack = new LinkedList<QName>();
     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<ParsingEvent>();
                     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<ParsingEvent>();
                 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<ParsingEvent>();
                 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<ParsingEvent> pes = pushedAheadEvents.pop();
+            List<ParsingEvent> 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;
@@ -390,7 +394,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/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml?rev=1425528&view=auto
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml (added)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml Sun Dec
23 21:23:27 2012
@@ -0,0 +1,32 @@
+<?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.
+-->
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Header>
+    <Action xmlns="http://www.w3.org/2005/08/addressing">http://apache.org/hello_world_soap_http/Greeter/greetMeRequest</Action>
+    <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:f40b7881-170e-455c-a78b-77d246fa7ac1</MessageID>
+    <To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:9002/SoapContext/SoapPort</To>
+    <customer:CustomerKey xmlns="http://www.w3.org/2005/08/addressing" xmlns:customer="http://example.org/customer"
xmlns:wsa="http://www.w3.org/2005/08/addressing" wsa:IsReferenceParameter="1">Key#123456789</customer:CustomerKey>
+  </soap:Header>
+  <soap:Body>
+    <greetMe xmlns="http://apache.org/hello_world_soap_http/types">
+      <requestType>implicit1</requestType>
+    </greetMe>
+  </soap:Body>
+</soap:Envelope>

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml?rev=1425528&view=auto
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml (added)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml Sun
Dec 23 21:23:27 2012
@@ -0,0 +1,35 @@
+<?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.
+-->
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Header>
+    <Action xmlns="http://www.w3.org/2005/08/addressing">http://apache.org/hello_world_soap_http/Greeter/greetMeRequest</Action>
+    <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:f40b7881-170e-455c-a78b-77d246fa7ac1</MessageID>
+    <To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:9002/SoapContext/SoapPort</To>
+    <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
+      <Address>http://localhost:9001/decoupled_endpoint</Address>
+    </ReplyTo>
+    <customer:CustomerKey xmlns="http://www.w3.org/2005/08/addressing" xmlns:customer="http://example.org/customer"
xmlns:wsa="http://www.w3.org/2005/08/addressing" wsa:IsReferenceParameter="1">Key#123456789</customer:CustomerKey>
+  </soap:Header>
+  <soap:Body>
+    <greetMe xmlns="http://apache.org/hello_world_soap_http/types">
+      <requestType>implicit1</requestType>
+    </greetMe>
+  </soap:Body>
+</soap:Envelope>

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java?rev=1425528&view=auto
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
(added)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
Sun Dec 23 21:23:27 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<String> getPrefixes(String ns) {
+                    return null;
+                }
+            },
+            Collections.singletonMap("urn:foo5", "urn:foo55"));
+    }
+
+    private void verifyPrefixes(Iterator<String> prefixes, String[] values) {
+        Set<String> tmp = new HashSet<String>();
+        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/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java?rev=1425528&r1=1425527&r2=1425528&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Sun Dec 23 21:23:27 2012
@@ -115,9 +115,9 @@ public class OutTransformWriterTest exte
         String xmlPI = "<?xml version='1.0' encoding='UTF-8'?>";
         String start = "<testBean xmlns=\"http://testbeans.com/v2\"";
         String expected1 = xmlPI + start
-            + " xmlns:ps1=\"http://testbeans.com/v3\"><ps1:bean/></testBean>";
+            + " xmlns:ps2=\"http://testbeans.com/v3\"><ps2:bean/></testBean>";
         String expected2 = xmlPI + start
-            + "><ps1:bean xmlns:ps1=\"http://testbeans.com/v3\"/></testBean>";
+            + "><ps2:bean xmlns:ps2=\"http://testbeans.com/v3\"/></testBean>";
         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("<ps1:test xmlns:ps1=\"http://bar\"><ps1:a>1</ps1:a></ps1:test>",
value);        
     }
 
+    @Test
+    public void testNamespacedAttributeDropElement() throws Exception {
+        Map<String, String> transformElements = new HashMap<String, String>();
+        transformElements.put("{http://www.w3.org/2005/08/addressing}ReplyTo", "");
+        TransformTestUtils.transformOutStreamAndCompare("../resources/greetMeWSAReqIn.xml",

+                                                        "../resources/greetMeWSAReq.xml",
+                                  transformElements, null, null, null, null);
+    }
+
 }



Mime
View raw message