cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1425530 - in /cxf/branches/2.6.x-fixes: ./ api/src/main/java/org/apache/cxf/staxutils/transform/ api/src/test/java/org/apache/cxf/staxutils/resources/ api/src/test/java/org/apache/cxf/staxutils/transform/
Date Sun, 23 Dec 2012 21:32:59 GMT
Author: ay
Date: Sun Dec 23 21:32:58 2012
New Revision: 1425530

URL: http://svn.apache.org/viewvc?rev=1425530&view=rev
Log:
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.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml
      - copied unchanged from r1425528, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReq.xml
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml
      - copied unchanged from r1425528, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/greetMeWSAReqIn.xml
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
      - copied unchanged from r1425528, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1425530&r1=1425529&r2=1425530&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
Sun Dec 23 21:32:58 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/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1425530&r1=1425529&r2=1425530&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Sun Dec 23 21:32:58 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/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1425530&r1=1425529&r2=1425530&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
Sun Dec 23 21:32:58 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;

Modified: cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java?rev=1425530&r1=1425529&r2=1425530&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Sun Dec 23 21:32:58 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