You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/04/02 08:26:10 UTC

[14/21] git commit: 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

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 <dk...@apache.org>
Authored: Fri Mar 28 13:14:53 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
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));
+                            }
                         }
                     }
                 }