cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1541246 - /cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
Date Tue, 12 Nov 2013 21:31:53 GMT
Author: dkulp
Date: Tue Nov 12 21:31:53 2013
New Revision: 1541246

URL: http://svn.apache.org/r1541246
Log:
Merged revisions 1541222 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

........
  r1541222 | dkulp | 2013-11-12 15:38:20 -0500 (Tue, 12 Nov 2013) | 10 lines

  Merged revisions 1541220 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1541220 | dkulp | 2013-11-12 15:36:20 -0500 (Tue, 12 Nov 2013) | 2 lines

    [CXF-5381] Fix problems detecting overlays when elements of same name are stuck in an
overlay element.

  ........

........

Modified:
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java?rev=1541246&r1=1541245&r2=1541246&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
Tue Nov 12 21:31:53 2013
@@ -51,9 +51,33 @@ public class OverlayW3CDOMStreamWriter e
     public OverlayW3CDOMStreamWriter(Document doc, Element e) {
         super(doc, e);
     }
-    
+
+    @Override
+    protected void createAndAddElement(String prefix, String local, String namespace) {
+        super.createAndAddElement(prefix, local, namespace);
+        if (isOverlaid) {
+            try {
+                //mark this as new so we don't consider this for overlaying
+                getCurrentNode().setUserData("new", "new", null);
+            } catch (Throwable t) {
+                //ignore
+            }
+        }
+    }
+
     @Override
     public void writeEndElement() throws XMLStreamException {
+        if (isOverlaid) {
+            Node nd = getCurrentNode().getFirstChild();
+            while (nd != null) {
+                try {
+                    getCurrentNode().setUserData("new", null, null);
+                } catch (Throwable t) {
+                    //ignore
+                }
+                nd = nd.getNextSibling();
+            }
+        }
         isOverlaid = isOverlaidStack.remove(0);
         super.writeEndElement();
     }
@@ -68,18 +92,29 @@ public class OverlayW3CDOMStreamWriter e
                 nd2 = nd.getFirstChild();
             }
             while (nd2 != null) {
+                Object userData = null;
+                try {
+                    userData = nd2.getUserData("new");
+                } catch (Throwable t) {
+                    //ignore - non DOM level 3
+                }
                 if (nd2.getNodeType() == Node.ELEMENT_NODE 
                     && local.equals(nd2.getLocalName())
-                    && StringUtils.isEmpty(nd2.getNamespaceURI())) {
+                    && StringUtils.isEmpty(nd2.getNamespaceURI())
+                    && userData != null) {
                     adjustOverlaidNode(nd2, null);
                     setChild((Element)nd2, false);
+                    if (nd2.getFirstChild() == null) {
+                        //optimize a case where we KNOW anything added cannot be an overlay
+                        isOverlaid = false;
+                    }
                     return;
                 }
                 nd2 = nd2.getNextSibling();
             }
         }
-        isOverlaid = false;
         super.writeStartElement(local);
+        isOverlaid = false;
     }
 
     protected void adjustOverlaidNode(Node nd2, String pfx) {
@@ -96,18 +131,29 @@ public class OverlayW3CDOMStreamWriter e
                 nd2 = nd.getFirstChild();
             }
             while (nd2 != null) {
+                Object userData = null;
+                try {
+                    userData = nd2.getUserData("new");
+                } catch (Throwable t) {
+                    //ignore - non DOM level 3
+                }
                 if (nd2.getNodeType() == Node.ELEMENT_NODE 
                     && local.equals(nd2.getLocalName())
-                    && namespace.equals(nd2.getNamespaceURI())) {
+                    && namespace.equals(nd2.getNamespaceURI())
+                    && userData == null) {
                     adjustOverlaidNode(nd2, "");
                     setChild((Element)nd2, false);
+                    if (nd2.getFirstChild() == null) {
+                        //optimize a case where we KNOW anything added cannot be an overlay
+                        isOverlaid = false;
+                    }
                     return;
                 }
                 nd2 = nd2.getNextSibling();
             }
         }
-        isOverlaid = false;
         super.writeStartElement(namespace, local);
+        isOverlaid = false;
     }
 
     public void writeStartElement(String prefix, String local, String namespace) throws XMLStreamException
{
@@ -116,7 +162,6 @@ public class OverlayW3CDOMStreamWriter e
         } else {
             isOverlaidStack.add(0, isOverlaid);
             if (isOverlaid) {
-    
                 Element nd = getCurrentNode();
                 Node nd2 = null;
                 if (nd == null) {
@@ -126,18 +171,30 @@ public class OverlayW3CDOMStreamWriter e
                 }
                 
                 while (nd2 != null) {
+                    Object userData = null;
+                    try {
+                        userData = nd2.getUserData("new");
+                    } catch (Throwable t) {
+                        //ignore - non DOM level 3
+                    }
+
                     if (nd2.getNodeType() == Node.ELEMENT_NODE 
                         && local.equals(nd2.getLocalName())
-                        && namespace.equals(nd2.getNamespaceURI())) {
+                        && namespace.equals(nd2.getNamespaceURI())
+                        && userData == null) {
                         adjustOverlaidNode(nd2, prefix);
                         setChild((Element)nd2, false);
+                        if (nd2.getFirstChild() == null) {
+                            //optimize a case where we KNOW anything added cannot be an overlay
+                            isOverlaid = false;
+                        }
                         return;
                     }
                     nd2 = nd2.getNextSibling();
                 }
             }
-            isOverlaid = false;
             super.writeStartElement(prefix, local, namespace);
+            isOverlaid = false;
         }
     }
     



Mime
View raw message