Skip to content
Permalink
Browse files
[CXF-5381] Fix problems detecting overlays when elements of same name…
… are stuck in an overlay element.

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1541220 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dkulp committed Nov 12, 2013
1 parent bfa2514 commit a284f9ea503493173461de348ffd9593684d8c8a
Showing 1 changed file with 65 additions and 8 deletions.
@@ -51,9 +51,33 @@ public OverlayW3CDOMStreamWriter(Element 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 void writeStartElement(String local) throws XMLStreamException {
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 void writeStartElement(String namespace, String local) throws XMLStreamEx
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 void writeStartElement(String prefix, String local, String namespace) thr
} else {
isOverlaidStack.add(0, isOverlaid);
if (isOverlaid) {

Element nd = getCurrentNode();
Node nd2 = null;
if (nd == null) {
@@ -126,18 +171,30 @@ public void writeStartElement(String prefix, String local, String namespace) thr
}

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;
}
}

0 comments on commit a284f9e

Please sign in to comment.