cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [3/7] 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
Date Fri, 04 Apr 2014 16:13:55 GMT
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/7a942960
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/7a942960
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/7a942960

Branch: refs/heads/2.6.x-fixes
Commit: 7a942960f5b87507f0ce343858c203b904c4ec5c
Parents: 31999f8
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Mar 28 13:14:53 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Apr 4 12:03:21 2014 -0400

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/7a942960/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));
+                            }
                         }
                     }
                 }


Mime
View raw message