If namespaces are part of the Attributes, make sure they are written out first 
and then NOT duplicated as part of writing out the namespace mappings


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/dc45c525
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/dc45c525
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/dc45c525

Branch: refs/heads/2.7.x-fixes
Commit: dc45c5256866c1c5e853dff422778fce30802b42
Parents: df01f6c
Author: Daniel Kulp <[email protected]>
Authored: Fri Mar 28 13:14:53 2014 -0400
Committer: Daniel Kulp <[email protected]>
Committed: Wed Apr 2 02:16:34 2014 -0400

----------------------------------------------------------------------
 .../staxutils/StreamWriterContentHandler.java   | 36 +++++++++++++++-----
 1 file changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/dc45c525/api/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java 
b/api/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
index 6ef3bce..22266b3 100644
--- a/api/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
+++ b/api/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
@@ -215,6 +215,24 @@ public class StreamWriterContentHandler implements 
ContentHandler, LexicalHandle
             } else {
                 writer.writeStartElement(prefix, localName, namespaceURI);
             }
+            if (!mapping.isEmpty() && atts != null) {
+                int attCount = atts.getLength();
+                for (int i = 0; i < attCount; i++) {
+                    if (!StringUtils.isEmpty(atts.getURI(i))
+                        && atts.getQName(i).startsWith("xmlns")) {
+                        String pfx = atts.getQName(i);
+                        int idx = pfx.indexOf(':');
+                        if (idx == -1) {
+                            mapping.remove("");
+                            writer.writeDefaultNamespace(atts.getValue(i));
+                        } else {
+                            pfx = pfx.substring(idx + 1);
+                            mapping.remove(pfx);
+                            writer.writeNamespace(pfx, atts.getValue(i));
+                        }
+                    }
+                }
+            }
             for (Map.Entry<String, String> e : mapping.entrySet()) {
                 if ("".equals(e.getKey())) {
                     writer.writeDefaultNamespace(e.getValue());
@@ -235,16 +253,18 @@ public class StreamWriterContentHandler implements 
ContentHandler, LexicalHandle
                                               atts.getValue(i));
                     } else {
                         String pfx = atts.getQName(i);
-                        if (pfx.indexOf(':') != -1) {
-                            pfx = pfx.substring(0, pfx.indexOf(':'));
-                            writer.writeAttribute(pfx,
-                                                  atts.getURI(i),
+                        if (!pfx.startsWith("xmlns")) {
+                            if (pfx.indexOf(':') != -1) {
+                                pfx = pfx.substring(0, pfx.indexOf(':'));
+                                writer.writeAttribute(pfx,
+                                                      atts.getURI(i),
+                                                      atts.getLocalName(i),
+                                                      atts.getValue(i));
+                            } else {
+                                writer.writeAttribute(atts.getURI(i),
                                                   atts.getLocalName(i),
                                                   atts.getValue(i));
-                        } else {
-                            writer.writeAttribute(atts.getURI(i),
-                                              atts.getLocalName(i),
-                                              atts.getValue(i));
+                            }
                         }
                     }
                 }

Reply via email to