cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r774827 - in /cxf/branches/2.1.x-fixes: common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
Date Thu, 14 May 2009 15:36:50 GMT
Author: dkulp
Date: Thu May 14 15:36:49 2009
New Revision: 774827

URL: http://svn.apache.org/viewvc?rev=774827&view=rev
Log:
Fix compile failures

Modified:
    cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
    cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java

Modified: cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java?rev=774827&r1=774826&r2=774827&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
(original)
+++ cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
Thu May 14 15:36:49 2009
@@ -30,17 +30,20 @@
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.apache.cxf.helpers.MapNamespaceContext;
 import org.apache.cxf.helpers.XMLUtils;
 
 public class W3CDOMStreamWriter implements XMLStreamWriter {
     static final String XML_NS = "http://www.w3.org/2000/xmlns/";
-    private Stack<Element> stack = new Stack<Element>();
+    private Stack<Node> stack = new Stack<Node>();
     private Document document;
-    private Element currentNode;
+    private Node currentNode;
     private NamespaceContext context = new W3CNamespaceContext();
+    private boolean nsRepairing;
     private Map properties = Collections.EMPTY_MAP;
 
     public W3CDOMStreamWriter() throws ParserConfigurationException {
@@ -54,6 +57,10 @@
     public W3CDOMStreamWriter(Document document) {
         this.document = document;
     }
+    public W3CDOMStreamWriter(DocumentFragment frag) {
+        this.document = frag.getOwnerDocument();
+        currentNode = frag;
+    }
 
     public W3CDOMStreamWriter(Element e) {
         this.document = e.getOwnerDocument();
@@ -61,7 +68,26 @@
         currentNode = e;
         ((W3CNamespaceContext)context).setElement(e);
     }
-
+    
+    public Element getCurrentNode() {
+        if (currentNode instanceof Element) {
+            return (Element)currentNode;
+        }
+        return null;
+    }
+    public DocumentFragment getCurrentFragment() {
+        if (currentNode instanceof DocumentFragment) {
+            return (DocumentFragment)currentNode;
+        }
+        return null;
+    }
+    
+    public void setNsRepairing(boolean b) {
+        nsRepairing = b;
+    }
+    public boolean isNsRepairing() {
+        return nsRepairing;
+    }
     public void setProperties(Map properties) {
         this.properties = properties;
     }
@@ -74,12 +100,19 @@
         newChild(document.createElement(local));
     }
 
-    private void newChild(Element element) {
+    protected void newChild(Element element) {
+        setChild(element, true);
+    }
+    protected void setChild(Element element, boolean append) {
         if (currentNode != null) {
             stack.push(currentNode);
-            currentNode.appendChild(element);
+            if (append) {
+                currentNode.appendChild(element);
+            }
         } else {
-            document.appendChild(element);
+            if (append) {
+                document.appendChild(element);
+            }
         }
         if (!(context instanceof W3CNamespaceContext)) {
             context = new W3CNamespaceContext();
@@ -97,29 +130,36 @@
             writeStartElement(namespace, local);
         } else {
             newChild(document.createElementNS(namespace, prefix + ":" + local));
+            if (nsRepairing
+                && !prefix.equals(getNamespaceContext().getPrefix(namespace))) {
+                writeNamespace(prefix, namespace);
+            }
         }
     }
 
     public void writeEmptyElement(String namespace, String local) throws XMLStreamException
{
         writeStartElement(namespace, local);
+        writeEndElement();
     }
 
     public void writeEmptyElement(String prefix, String namespace, String local) throws XMLStreamException
{
         writeStartElement(prefix, namespace, local);
+        writeEndElement();
     }
 
     public void writeEmptyElement(String local) throws XMLStreamException {
         writeStartElement(local);
+        writeEndElement();
     }
 
     public void writeEndElement() throws XMLStreamException {
         if (stack.size() > 0) {
-            currentNode = (Element)stack.pop();
+            currentNode = stack.pop();
         } else {
             currentNode = null;
         }
-        if (context instanceof W3CNamespaceContext) {
-            ((W3CNamespaceContext)context).setElement(currentNode);
+        if (context instanceof W3CNamespaceContext && currentNode instanceof Element)
{
+            ((W3CNamespaceContext)context).setElement((Element)currentNode);
         } else if (context instanceof MapNamespaceContext) {
             ((MapNamespaceContext) context).setTargetNode(currentNode);
         }
@@ -131,7 +171,7 @@
     public void writeAttribute(String local, String value) throws XMLStreamException {
         Attr a = document.createAttribute(local);
         a.setValue(value);
-        currentNode.setAttributeNode(a);
+        ((Element)currentNode).setAttributeNode(a);
     }
 
     public void writeAttribute(String prefix, String namespace, String local, String value)
@@ -142,13 +182,17 @@
         
         Attr a = document.createAttributeNS(namespace, local);
         a.setValue(value);
-        currentNode.setAttributeNodeNS(a);
+        ((Element)currentNode).setAttributeNodeNS(a);
+        if (nsRepairing
+            && !prefix.equals(getNamespaceContext().getPrefix(namespace))) {
+            writeNamespace(prefix, namespace);
+        }
     }
 
     public void writeAttribute(String namespace, String local, String value) throws XMLStreamException
{
         Attr a = document.createAttributeNS(namespace, local);
         a.setValue(value);
-        currentNode.setAttributeNodeNS(a);
+        ((Element)currentNode).setAttributeNodeNS(a);
     }
 
     public void writeNamespace(String prefix, String namespace) throws XMLStreamException
{
@@ -157,14 +201,14 @@
         } else {
             Attr attr = document.createAttributeNS(XML_NS, "xmlns:" + prefix);
             attr.setValue(namespace);
-            currentNode.setAttributeNodeNS(attr);
+            ((Element)currentNode).setAttributeNodeNS(attr);
         }
     }
 
     public void writeDefaultNamespace(String namespace) throws XMLStreamException {
         Attr attr = document.createAttributeNS(XML_NS, "xmlns");
         attr.setValue(namespace);
-        currentNode.setAttributeNodeNS(attr);
+        ((Element)currentNode).setAttributeNodeNS(attr);
     }
 
     public void writeComment(String value) throws XMLStreamException {

Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java?rev=774827&r1=774826&r2=774827&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
Thu May 14 15:36:49 2009
@@ -30,6 +30,9 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.validation.Schema;
 
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Node;
+
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.databinding.DataWriter;
@@ -37,6 +40,7 @@
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 public class XMLStreamDataWriter implements DataWriter<XMLStreamWriter> {
     private static final Logger LOG = LogUtils.getL7dLogger(XMLStreamDataWriter.class);



Mime
View raw message