You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mk...@apache.org on 2005/05/20 16:25:13 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/utils DOMBuilder.java
mkwan 2005/05/20 07:25:13
Modified: java/src/org/apache/xalan/transformer
TransformerIdentityImpl.java TransformerImpl.java
java/src/org/apache/xml/utils DOMBuilder.java
Log:
Support DOMResult.nextSibling in XalanJ Interpretive. If
nextSibling is not null, then result nodes are inserted
before it.
Revision Changes Path
1.34 +29 -3 xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java
Index: TransformerIdentityImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- TransformerIdentityImpl.java 11 Feb 2005 07:07:54 -0000 1.33
+++ TransformerIdentityImpl.java 20 May 2005 14:25:13 -0000 1.34
@@ -132,6 +132,26 @@
}
/**
+ * Reset the status of the transformer.
+ */
+ public void reset()
+ {
+ m_flushedStartDoc = false;
+ m_foundFirstElement = false;
+ m_outputStream = null;
+ m_params.clear();
+ m_result = null;
+ m_resultContentHandler = null;
+ m_resultDeclHandler = null;
+ m_resultDTDHandler = null;
+ m_resultLexicalHandler = null;
+ m_serializer = null;
+ m_systemID = null;
+ m_URIResolver = null;
+ m_outputFormat = new OutputProperties(Method.XML);
+ }
+
+ /**
* Create a result ContentHandler from a Result object, based
* on the current OutputProperties.
*
@@ -165,6 +185,7 @@
{
DOMResult domResult = (DOMResult) outputTarget;
Node outputNode = domResult.getNode();
+ Node nextSibling = domResult.getNextSibling();
Document doc;
short type;
@@ -197,11 +218,16 @@
((DOMResult) outputTarget).setNode(outputNode);
}
- m_resultContentHandler =
+ DOMBuilder domBuilder =
(Node.DOCUMENT_FRAGMENT_NODE == type)
? new DOMBuilder(doc, (DocumentFragment) outputNode)
: new DOMBuilder(doc, outputNode);
- m_resultLexicalHandler = (LexicalHandler) m_resultContentHandler;
+
+ if (nextSibling != null)
+ domBuilder.setNextSibling(nextSibling);
+
+ m_resultContentHandler = domBuilder;
+ m_resultLexicalHandler = domBuilder;
}
else if (outputTarget instanceof StreamResult)
{
1.164 +7 -2 xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -r1.163 -r1.164
--- TransformerImpl.java 17 May 2005 17:22:14 -0000 1.163
+++ TransformerImpl.java 20 May 2005 14:25:13 -0000 1.164
@@ -1037,6 +1037,7 @@
if (outputTarget instanceof DOMResult)
{
outputNode = ((DOMResult) outputTarget).getNode();
+ org.w3c.dom.Node nextSibling = ((DOMResult)outputTarget).getNextSibling();
org.w3c.dom.Document doc;
short type;
@@ -1057,10 +1058,14 @@
((DOMResult) outputTarget).setNode(outputNode);
}
- ContentHandler handler =
+ DOMBuilder handler =
(org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE == type)
? new DOMBuilder(doc, (org.w3c.dom.DocumentFragment) outputNode)
: new DOMBuilder(doc, outputNode);
+
+ if (nextSibling != null)
+ handler.setNextSibling(nextSibling);
+
String encoding = format.getProperty(OutputKeys.ENCODING);
xoh = new ToXMLSAXHandler(handler, (LexicalHandler)handler, encoding);
}
1.21 +59 -9 xml-xalan/java/src/org/apache/xml/utils/DOMBuilder.java
Index: DOMBuilder.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/DOMBuilder.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DOMBuilder.java 23 Mar 2004 23:04:41 -0000 1.20
+++ DOMBuilder.java 20 May 2005 14:25:13 -0000 1.21
@@ -49,6 +49,12 @@
/** Current node */
protected Node m_currentNode = null;
+
+ /** The root node */
+ protected Node m_root = null;
+
+ /** The next sibling node */
+ protected Node m_nextSibling = null;
/** First node of document fragment or null if not a DocumentFragment */
public DocumentFragment m_docFrag = null;
@@ -66,7 +72,10 @@
public DOMBuilder(Document doc, Node node)
{
m_doc = doc;
- m_currentNode = node;
+ m_currentNode = m_root = node;
+
+ if (node instanceof Element)
+ m_elemStack.push(node);
}
/**
@@ -94,16 +103,23 @@
}
/**
- * Get the root node of the DOM being created. This
- * is either a Document or a DocumentFragment.
+ * Get the root document or DocumentFragment of the DOM being created.
*
* @return The root document or document fragment if not null
*/
- public Node getRootNode()
+ public Node getRootDocument()
{
return (null != m_docFrag) ? (Node) m_docFrag : (Node) m_doc;
}
-
+
+ /**
+ * Get the root node of the DOM tree.
+ */
+ public Node getRootNode()
+ {
+ return m_root;
+ }
+
/**
* Get the node currently being processed.
*
@@ -113,6 +129,27 @@
{
return m_currentNode;
}
+
+ /**
+ * Set the next sibling node, which is where the result nodes
+ * should be inserted before.
+ *
+ * @param nextSibling the next sibling node.
+ */
+ public void setNextSibling(Node nextSibling)
+ {
+ m_nextSibling = nextSibling;
+ }
+
+ /**
+ * Return the next sibling node.
+ *
+ * @return the next sibling node.
+ */
+ public Node getNextSibling()
+ {
+ return m_nextSibling;
+ }
/**
* Return null since there is no Writer for this class.
@@ -136,13 +173,19 @@
if (null != currentNode)
{
- currentNode.appendChild(newNode);
+ if (currentNode == m_root && m_nextSibling != null)
+ currentNode.insertBefore(newNode, m_nextSibling);
+ else
+ currentNode.appendChild(newNode);
// System.out.println(newNode.getNodeName());
}
else if (null != m_docFrag)
{
- m_docFrag.appendChild(newNode);
+ if (m_nextSibling != null)
+ m_docFrag.insertBefore(newNode, m_nextSibling);
+ else
+ m_docFrag.appendChild(newNode);
}
else
{
@@ -166,6 +209,8 @@
{
if (m_doc.getDocumentElement() != null)
{
+ ok = false;
+
throw new org.xml.sax.SAXException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_CANT_HAVE_MORE_THAN_ONE_ROOT, null)); //"Can't have more than one root on a DOM!");
@@ -173,7 +218,12 @@
}
if (ok)
- m_doc.appendChild(newNode);
+ {
+ if (m_nextSibling != null)
+ m_doc.insertBefore(newNode, m_nextSibling);
+ else
+ m_doc.appendChild(newNode);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org