mkwan 2003/04/01 12:26:41
Modified: java/src/org/apache/xalan/transformer
ClonerToResultTree.java QueuedEvents.java
SerializerSwitcher.java TransformSnapshot.java
TransformSnapshotImpl.java TransformState.java
TransformerHandlerImpl.java
TransformerIdentityImpl.java TransformerImpl.java
TreeWalker2Result.java
Added: java/src/org/apache/xalan/transformer
XalanTransformState.java
Removed: java/src/org/apache/xalan/transformer ResultTreeHandler.java
Log:
Merging XSLTC_DTM and common serializer to the head
Changes in org.apache.xalan.transformer for the new serializer.
Revision Changes Path
1.16 +11 -26
xml-xalan/java/src/org/apache/xalan/transformer/ClonerToResultTree.java
Index: ClonerToResultTree.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ClonerToResultTree.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ClonerToResultTree.java 30 Jan 2003 18:45:54 -0000 1.15
+++ ClonerToResultTree.java 1 Apr 2003 20:26:39 -0000 1.16
@@ -58,7 +58,9 @@
import javax.xml.transform.TransformerException;
+import org.apache.xalan.serialize.SerializerUtils;
import org.apache.xml.dtm.DTM;
+import org.apache.xml.serializer.SerializationHandler;
import org.apache.xml.utils.XMLString;
/**
@@ -69,26 +71,6 @@
public class ClonerToResultTree
{
- /** Result tree handler for the cloned tree */
- private ResultTreeHandler m_rth;
-
- /** Transformer instance to use for cloning */
- private TransformerImpl m_transformer;
-
- /**
- * Constructor ClonerToResultTree
- *
- *
- * @param transformer non-null transformer instance to use for the cloning
- * @param rth non-null result tree handler for the cloned tree
- */
- public ClonerToResultTree(TransformerImpl transformer,
- ResultTreeHandler rth)
- {
- m_rth = rth;
- m_transformer = transformer;
- }
-
// /**
// * Clone an element with or without children.
// * TODO: Fix or figure out node clone failure!
@@ -184,7 +166,7 @@
* @throws TransformerException
*/
public static void cloneToResultTree(int node, int nodeType, DTM dtm,
- ResultTreeHandler rth,
+ SerializationHandler rth,
boolean shouldCloneAttributes)
throws TransformerException
{
@@ -208,15 +190,18 @@
String ns = dtm.getNamespaceURI(node);
if (ns==null) ns="";
String localName = dtm.getLocalName(node);
- rth.startElement(ns, localName, dtm.getNodeNameX(node), null);
+ // rth.startElement(ns, localName, dtm.getNodeNameX(node), null);
+ // don't call a real SAX startElement (as commented out above),
+ // call a SAX-like startElement, to be able to add attributes after
this call
+ rth.startElement(ns, localName, dtm.getNodeNameX(node));
// If outputting attrs as separate events, they must
// _follow_ the startElement event. (Think of the
// xsl:attribute directive.)
if (shouldCloneAttributes)
{
- rth.addAttributes(node);
- rth.processNSDecls(node, nodeType, dtm);
+ SerializerUtils.addAttributes(rth, node);
+ SerializerUtils.processNSDecls(rth, node, nodeType, dtm);
}
}
break;
@@ -226,14 +211,14 @@
rth.endCDATA();
break;
case DTM.ATTRIBUTE_NODE :
- rth.addAttribute(node);
+ SerializerUtils.addAttribute(rth, node);
break;
case DTM.NAMESPACE_NODE:
// %REVIEW% Normally, these should have been
handled with element.
// It's possible that someone may write a
stylesheet that tries to
// clone them explicitly. If so, we need the
equivalent of
// rth.addAttribute().
- rth.processNSDecls(node,DTM.NAMESPACE_NODE,dtm);
+
SerializerUtils.processNSDecls(rth,node,DTM.NAMESPACE_NODE,dtm);
break;
case DTM.COMMENT_NODE :
XMLString xstr = dtm.getStringValue (node);
1.13 +3 -3
xml-xalan/java/src/org/apache/xalan/transformer/QueuedEvents.java
Index: QueuedEvents.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/QueuedEvents.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- QueuedEvents.java 30 Jan 2003 18:45:55 -0000 1.12
+++ QueuedEvents.java 1 Apr 2003 20:26:39 -0000 1.13
@@ -178,7 +178,7 @@
}
/** Instance of a serializer */
- private org.apache.xalan.serialize.Serializer m_serializer;
+ private org.apache.xml.serializer.Serializer m_serializer;
/**
* This is only for use of object pooling, so that
@@ -186,7 +186,7 @@
*
* @param s non-null instance of a serializer
*/
- void setSerializer(org.apache.xalan.serialize.Serializer s)
+ void setSerializer(org.apache.xml.serializer.Serializer s)
{
m_serializer = s;
}
@@ -197,7 +197,7 @@
*
* @return The serializer
*/
- org.apache.xalan.serialize.Serializer getSerializer()
+ org.apache.xml.serializer.Serializer getSerializer()
{
return m_serializer;
}
1.12 +6 -5
xml-xalan/java/src/org/apache/xalan/transformer/SerializerSwitcher.java
Index: SerializerSwitcher.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/SerializerSwitcher.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SerializerSwitcher.java 30 Jan 2003 18:45:55 -0000 1.11
+++ SerializerSwitcher.java 1 Apr 2003 20:26:39 -0000 1.12
@@ -63,9 +63,9 @@
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerException;
-import org.apache.xalan.serialize.Method;
-import org.apache.xalan.serialize.Serializer;
-import org.apache.xalan.serialize.SerializerFactory;
+import org.apache.xml.serializer.Serializer;
+import org.apache.xml.serializer.SerializerFactory;
+import org.apache.xml.serialize.Method;
import org.apache.xalan.templates.OutputProperties;
import org.xml.sax.ContentHandler;
@@ -118,7 +118,8 @@
try
{
- Serializer oldSerializer = transformer.getSerializer();
+// Serializer oldSerializer = transformer.getSerializer();
+ Serializer oldSerializer = null;
if (null != oldSerializer)
{
@@ -137,7 +138,7 @@
serializer.setOutputStream(os);
}
- transformer.setSerializer(serializer);
+// transformer.setSerializer(serializer);
ContentHandler ch = serializer.asContentHandler();
1.3 +3 -0
xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshot.java
Index: TransformSnapshot.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshot.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransformSnapshot.java 27 Jan 2003 18:44:32 -0000 1.2
+++ TransformSnapshot.java 1 Apr 2003 20:26:39 -0000 1.3
@@ -59,6 +59,9 @@
/**
* This is an opaque interface that allows the transformer to return a
* "snapshot" of it's current state, which can later be restored.
+ *
+ * @deprecated It doesn't look like this code, which is for tooling, has
+ * functioned propery for a while, so it doesn't look like it is being used.
*/
public interface TransformSnapshot
{
1.10 +25 -39
xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshotImpl.java
Index: TransformSnapshotImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshotImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TransformSnapshotImpl.java 30 Jan 2003 18:45:55 -0000 1.9
+++ TransformSnapshotImpl.java 1 Apr 2003 20:26:39 -0000 1.10
@@ -49,9 +49,9 @@
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
- * originally based on software copyright (c) 1999, Lotus
- * Development Corporation., http://www.lotus.com. For more
- * information on the Apache Software Foundation, please see
+ * originally based on software copyright (c) 1999-2003, Lotus Development
+ * Corporation., http://www.lotus.com. For more information on the Apache
+ * Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.transformer;
@@ -70,12 +70,17 @@
import org.xml.sax.helpers.NamespaceSupport;
+import org.apache.xml.serializer.NamespaceMappings;
+import org.apache.xml.serializer.SerializationHandler;
/**
* This class holds a "snapshot" of it's current transformer state,
* which can later be restored.
*
* This only saves state which can change over the course of the
side-effect-free
* (i.e. no extensions that call setURIResolver, etc.).
+ *
+ * @deprecated It doesn't look like this code, which is for tooling, has
+ * functioned propery for a while, so it doesn't look like it is being used.
*/
class TransformSnapshotImpl implements TransformSnapshot
{
@@ -160,16 +165,18 @@
/**
* Use the SAX2 helper class to track result namespaces.
*/
- private NamespaceSupport m_nsSupport;
+ private NamespaceMappings m_nsSupport;
/** The number of events queued */
- int m_eventCount;
+// int m_eventCount;
/**
* Constructor TransformSnapshotImpl
* Take a snapshot of the currently executing context.
*
* @param transformer Non null transformer instance
+ * @deprecated It doesn't look like this code, which is for tooling, has
+ * functioned propery for a while, so it doesn't look like it is being
used.
*/
TransformSnapshotImpl(TransformerImpl transformer)
{
@@ -178,25 +185,15 @@
{
// Are all these clones deep enough?
- ResultTreeHandler rtf = transformer.getResultTreeHandler();
+ SerializationHandler rtf = transformer.getResultTreeHandler();
- m_eventCount = rtf.m_eventCount;
-
- // yuck. No clone. Hope this is good enough.
- m_nsSupport = new NamespaceSupport2();
-
- Enumeration prefixes = rtf.m_nsSupport.getPrefixes();
-
- while (prefixes.hasMoreElements())
{
- String prefix = (String) prefixes.nextElement();
- String uri = rtf.m_nsSupport.getURI(prefix);
-
- m_nsSupport.declarePrefix(prefix, uri);
+ // save serializer fields
+ m_nsSupport = (NamespaceMappings)rtf.getNamespaceMappings().clone();
+
+ // Do other fields need to be saved/restored?
}
-
- m_nsContextPushed = rtf.m_nsContextPushed;
-
+
XPathContext xpc = transformer.getXPathContext();
m_variableStacks = (VariableStack) xpc.getVarStack().clone();
@@ -235,6 +232,9 @@
* based on some previously taken snapshot where we can then start
execution
*
* @param transformer Non null transformer instance
+ *
+ * @deprecated It doesn't look like this code, which is for tooling, has
+ * functioned propery for a while, so it doesn't look like it is being
used.
*/
void apply(TransformerImpl transformer)
{
@@ -243,26 +243,12 @@
{
// Are all these clones deep enough?
- ResultTreeHandler rtf = transformer.getResultTreeHandler();
+ SerializationHandler rtf = transformer.getResultTreeHandler();
if (rtf != null)
{
- rtf.m_eventCount = 1; //1 for start document event! m_eventCount;
-
- // yuck. No clone. Hope this is good enough.
- rtf.m_nsSupport = new NamespaceSupport();
-
- Enumeration prefixes = m_nsSupport.getPrefixes();
-
- while (prefixes.hasMoreElements())
- {
- String prefix = (String) prefixes.nextElement();
- String uri = m_nsSupport.getURI(prefix);
-
- rtf.m_nsSupport.declarePrefix(prefix, uri);
- }
-
- rtf.m_nsContextPushed = m_nsContextPushed;
+ // restore serializer fields
+ rtf.setNamespaceMappings((NamespaceMappings)m_nsSupport.clone());
}
XPathContext xpc = transformer.getXPathContext();
@@ -296,4 +282,4 @@
throw new org.apache.xml.utils.WrappedRuntimeException(cnse);
}
}
-}
+}
\ No newline at end of file
1.8 +10 -1
xml-xalan/java/src/org/apache/xalan/transformer/TransformState.java
Index: TransformState.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformState.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TransformState.java 30 Jan 2003 18:45:55 -0000 1.7
+++ TransformState.java 1 Apr 2003 20:26:39 -0000 1.8
@@ -60,6 +60,7 @@
import org.apache.xalan.templates.ElemTemplate;
import org.apache.xalan.templates.ElemTemplateElement;
+import org.apache.xml.serializer.TransformStateSetter;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.NodeIterator;
@@ -78,8 +79,13 @@
* <p>Note that the current stylesheet and root stylesheet can
* be retrieved from the ElemTemplateElement obtained from
* either getCurrentElement() or getCurrentTemplate().</p>
+ *
+ * This interface contains only getter methods, any setters are in the
interface
+ * TransformStateSetter which this interface extends.
+ *
+ * @see org.apache.xml.serializer.TransformStateSetter
*/
-public interface TransformState
+public interface TransformState extends TransformStateSetter
{
/**
@@ -152,4 +158,7 @@
* @return the TrAX Transformer object in effect.
*/
Transformer getTransformer();
+
+
+
}
1.18 +7 -4
xml-xalan/java/src/org/apache/xalan/transformer/TransformerHandlerImpl.java
Index: TransformerHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerHandlerImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TransformerHandlerImpl.java 30 Jan 2003 18:45:56 -0000 1.17
+++ TransformerHandlerImpl.java 1 Apr 2003 20:26:39 -0000 1.18
@@ -81,6 +81,7 @@
import org.xml.sax.SAXParseException;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
+import org.apache.xml.serializer.SerializationHandler;
/**
@@ -197,10 +198,12 @@
try
{
- ContentHandler handler =
- m_transformer.createResultContentHandler(result);
-
- m_transformer.setContentHandler(handler);
+// ContentHandler handler =
+// m_transformer.createResultContentHandler(result);
+// m_transformer.setContentHandler(handler);
+ SerializationHandler xoh =
+ m_transformer.createSerializationHandler(result);
+ m_transformer.setSerializationHandler(xoh);
}
catch (javax.xml.transform.TransformerException te)
{
1.24 +14 -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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- TransformerIdentityImpl.java 3 Feb 2003 20:48:13 -0000 1.23
+++ TransformerIdentityImpl.java 1 Apr 2003 20:26:39 -0000 1.24
@@ -76,12 +76,12 @@
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
+import org.apache.xml.serializer.Serializer;
+import org.apache.xml.serializer.SerializerFactory;
+import org.apache.xml.serializer.Method;
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.res.XSLTErrorResources;
-import org.apache.xalan.serialize.Method;
-import org.apache.xalan.serialize.Serializer;
-import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.templates.OutputProperties;
import org.apache.xml.utils.DOMBuilder;
import org.apache.xml.utils.TreeWalker;
@@ -896,6 +896,17 @@
{
if(!m_flushedStartDoc)
{
+ if (m_resultContentHandler == null)
+ {
+ try
+ {
+ createResultContentHandler(m_result);
+ }
+ catch(TransformerException te)
+ {
+ throw new SAXException(te);
+ }
+ }
m_resultContentHandler.startDocument();
m_flushedStartDoc = true;
}
1.144 +379 -259
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.143
retrieving revision 1.144
diff -u -r1.143 -r1.144
--- TransformerImpl.java 30 Jan 2003 18:45:56 -0000 1.143
+++ TransformerImpl.java 1 Apr 2003 20:26:39 -0000 1.144
@@ -70,6 +70,7 @@
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import javax.xml.transform.SourceLocator;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
@@ -80,9 +81,9 @@
import org.apache.xalan.extensions.ExtensionsTable;
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.res.XSLTErrorResources;
-import org.apache.xalan.serialize.Method;
-import org.apache.xalan.serialize.Serializer;
-import org.apache.xalan.serialize.SerializerFactory;
+import org.apache.xml.serializer.Method;
+import org.apache.xml.serializer.Serializer;
+import org.apache.xml.serializer.SerializerFactory;
import org.apache.xalan.templates.AVT;
import org.apache.xalan.templates.Constants;
import org.apache.xalan.templates.ElemAttributeSet;
@@ -102,6 +103,12 @@
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.DTMManager;
import org.apache.xml.dtm.DTMWSFilter;
+import org.apache.xml.serializer.ToHTMLSAXHandler;
+import org.apache.xml.serializer.ToSAXHandler;
+import org.apache.xml.serializer.ToTextSAXHandler;
+import org.apache.xml.serializer.ToTextStream;
+import org.apache.xml.serializer.ToXMLSAXHandler;
+import org.apache.xml.serializer.SerializationHandler;
import org.apache.xml.utils.BoolStack;
import org.apache.xml.utils.DOMBuilder;
import org.apache.xml.utils.DOMHelper;
@@ -117,7 +124,7 @@
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FuncExtFunction;
import org.apache.xpath.objects.XObject;
-
+import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -125,6 +132,7 @@
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
+import org.apache.xalan.trace.GenerateEvent;
/**
* <meta name="usage" content="advanced"/>
* This class implements the
@@ -132,7 +140,7 @@
* representation of the transformation execution.</p>
*/
public class TransformerImpl extends Transformer
- implements Runnable, DTMWSFilter, ExtensionsProvider
+ implements Runnable, DTMWSFilter, ExtensionsProvider,
org.apache.xml.serializer.SerializerTrace
{
// Synch object to gaurd against setting values from the TrAX interface
@@ -166,8 +174,6 @@
*/
private OutputProperties m_outputFormat;
- /** The output serializer */
- private Serializer m_serializer;
/**
* The content handler for the source input tree.
@@ -194,7 +200,7 @@
* Please note that each of these also holds onto a Text Serializer.
*/
private ObjectPool m_textResultHandlerObjectPool =
- new ObjectPool("org.apache.xalan.transformer.ResultTreeHandler");
+ new ObjectPool("org.apache.xml.serializer.ToTextStream");
/**
* Related to m_textResultHandlerObjectPool, this is a pool of
@@ -208,7 +214,7 @@
* A static text format object, which can be used over and
* over to create the text serializers.
*/
- private OutputProperties m_textformat = new OutputProperties(Method.Text);
+ private OutputProperties m_textformat = new OutputProperties(Method.TEXT);
// Commenteded out in response to problem reported by
// Nicola Brown <[EMAIL PROTECTED]>
@@ -281,7 +287,7 @@
/**
* Output handler to bottleneck SAX events.
*/
- private ResultTreeHandler m_resultTreeHandler;
+ private SerializationHandler m_serializationHandler;
/** The key manager, which manages xsl:keys. */
private KeyManager m_keyManager = new KeyManager();
@@ -498,7 +504,7 @@
m_currentMatchTemplates.removeAllElements();
m_currentMatchedNodes.removeAllElements();
- m_resultTreeHandler = null;
+ m_serializationHandler = null;
m_outputTarget = null;
m_keyManager = new KeyManager();
m_attrSetStack = null;
@@ -693,9 +699,9 @@
throw new javax.xml.transform.TransformerException(e);
}
}
- else if (null != m_resultTreeHandler)
+ else if (null != m_serializationHandler)
{
- m_resultTreeHandler.endDocument();
+ m_serializationHandler.endDocument();
}
}
catch (org.apache.xml.utils.WrappedRuntimeException wre)
@@ -954,142 +960,189 @@
return (Properties) getOutputFormat().getProperties().clone();
}
- /**
- * Create a result ContentHandler from a Result object, based
- * on the current OutputProperties.
- *
- * @param outputTarget Where the transform result should go,
- * should not be null.
- *
- * @return A valid ContentHandler that will create the
- * result tree when it is fed SAX events.
- *
- * @throws TransformerException
- */
- public ContentHandler createResultContentHandler(Result outputTarget)
- throws TransformerException
- {
- return createResultContentHandler(outputTarget, getOutputFormat());
- }
-
- /**
- * Create a ContentHandler from a Result object and an OutputProperties.
- *
- * @param outputTarget Where the transform result should go,
- * should not be null.
- * @param format The OutputProperties object that will contain
- * instructions on how to serialize the output.
- *
- * @return A valid ContentHandler that will create the
- * result tree when it is fed SAX events.
- *
- * @throws TransformerException
- */
- public ContentHandler createResultContentHandler(
- Result outputTarget, OutputProperties format)
+ /**
+ * Create a result ContentHandler from a Result object, based
+ * on the current OutputProperties.
+ *
+ * @param outputTarget Where the transform result should go,
+ * should not be null.
+ *
+ * @return A valid ContentHandler that will create the
+ * result tree when it is fed SAX events.
+ *
+ * @throws TransformerException
+ */
+ public SerializationHandler createSerializationHandler(Result
outputTarget)
throws TransformerException
- {
-
- ContentHandler handler = null;
-
- // If the Result object contains a Node, then create
- // a ContentHandler that will add nodes to the input node.
- org.w3c.dom.Node outputNode = null;
-
- if (outputTarget instanceof DOMResult)
{
- outputNode = ((DOMResult) outputTarget).getNode();
+ SerializationHandler xoh =
+ createSerializationHandler(outputTarget, getOutputFormat());
+ return xoh;
+ }
+
+ /**
+ * Create a ContentHandler from a Result object and an OutputProperties.
+ *
+ * @param outputTarget Where the transform result should go,
+ * should not be null.
+ * @param format The OutputProperties object that will contain
+ * instructions on how to serialize the output.
+ *
+ * @return A valid ContentHandler that will create the
+ * result tree when it is fed SAX events.
+ *
+ * @throws TransformerException
+ */
+ public SerializationHandler createSerializationHandler(
+ Result outputTarget, OutputProperties format)
+ throws TransformerException
+ {
+
+ SerializationHandler xoh;
+
+ // If the Result object contains a Node, then create
+ // a ContentHandler that will add nodes to the input node.
+ org.w3c.dom.Node outputNode = null;
+
+ if (outputTarget instanceof DOMResult)
+ {
+ outputNode = ((DOMResult) outputTarget).getNode();
+
+ org.w3c.dom.Document doc;
+ short type;
+
+ if (null != outputNode)
+ {
+ type = outputNode.getNodeType();
+ doc = (org.w3c.dom.Node.DOCUMENT_NODE == type)
+ ? (org.w3c.dom.Document) outputNode
+ : outputNode.getOwnerDocument();
+ }
+ else
+ {
+ doc = org.apache.xml.utils.DOMHelper.createDocument();
+ outputNode = doc;
+ type = outputNode.getNodeType();
- org.w3c.dom.Document doc;
- short type;
+ ((DOMResult) outputTarget).setNode(outputNode);
+ }
- if (null != outputNode)
- {
- type = outputNode.getNodeType();
- doc = (org.w3c.dom.Node.DOCUMENT_NODE == type)
- ? (org.w3c.dom.Document) outputNode
- : outputNode.getOwnerDocument();
+ ContentHandler handler =
+ (org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE == type)
+ ? new DOMBuilder(doc, (org.w3c.dom.DocumentFragment) outputNode)
+ : new DOMBuilder(doc, outputNode);
+ String encoding = format.getProperty(OutputKeys.ENCODING);
+ xoh = new ToXMLSAXHandler(handler, (LexicalHandler)handler,
encoding);
}
- else
+ else if (outputTarget instanceof SAXResult)
{
- doc = DOMHelper.createDocument();
- outputNode = doc;
- type = outputNode.getNodeType();
+ ContentHandler handler = ((SAXResult) outputTarget).getHandler();
+
+ if (null == handler)
+ throw new IllegalArgumentException(
+ "handler can not be null for a SAXResult");
+
+ LexicalHandler lexHandler;
+ if (handler instanceof LexicalHandler)
+ lexHandler = (LexicalHandler) handler;
+ else
+ lexHandler = null;
+
+ String encoding = format.getProperty(OutputKeys.ENCODING);
+ String method = format.getProperty(OutputKeys.METHOD);
+ if (org.apache.xml.serializer.Method.HTML.equals(method))
+ {
+ xoh = new ToHTMLSAXHandler(handler, lexHandler, encoding);
+ }
+ else if (org.apache.xml.serializer.Method.TEXT.equals(method))
+ {
+ xoh = new ToTextSAXHandler(handler, lexHandler, encoding);
+ }
+ else
+ {
+ xoh = new ToXMLSAXHandler(handler, lexHandler, encoding);
+ }
+
+ if (handler instanceof TransformerClient) {
+ XalanTransformState state = new XalanTransformState();
+ ((TransformerClient)handler).setTransformState(state);
+ ((ToSAXHandler)xoh).setTransformState(state);
+ }
- ((DOMResult) outputTarget).setNode(outputNode);
+
}
- handler =
- (org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE == type)
- ? new DOMBuilder(doc, (org.w3c.dom.DocumentFragment) outputNode)
- : new DOMBuilder(doc, outputNode);
- }
- else if (outputTarget instanceof SAXResult)
- {
- handler = ((SAXResult) outputTarget).getHandler();
-
- if (null == handler)
- throw new IllegalArgumentException(
- "handler can not be null for a SAXResult");
- }
-
- // Otherwise, create a ContentHandler that will serialize the
- // result tree to either a stream or a writer.
- else if (outputTarget instanceof StreamResult)
- {
- StreamResult sresult = (StreamResult) outputTarget;
- String method = format.getProperty(OutputKeys.METHOD);
-
- try
+ // Otherwise, create a ContentHandler that will serialize the
+ // result tree to either a stream or a writer.
+ else if (outputTarget instanceof StreamResult)
{
- Serializer serializer =
- SerializerFactory.getSerializer(format.getProperties());
+ StreamResult sresult = (StreamResult) outputTarget;
+ String method = format.getProperty(OutputKeys.METHOD);
- if (null != sresult.getWriter())
- serializer.setWriter(sresult.getWriter());
- else if (null != sresult.getOutputStream())
- serializer.setOutputStream(sresult.getOutputStream());
- else if (null != sresult.getSystemId())
+ try
{
- String fileURL = sresult.getSystemId();
+ SerializationHandler serializer =
+ (SerializationHandler)
SerializerFactory.getSerializer(format.getProperties());
- if (fileURL.startsWith("file:///"))
+ if (null != sresult.getWriter())
+ serializer.setWriter(sresult.getWriter());
+ else if (null != sresult.getOutputStream())
+ serializer.setOutputStream(sresult.getOutputStream());
+ else if (null != sresult.getSystemId())
{
- if (fileURL.substring(8).indexOf(":") >0)
- fileURL = fileURL.substring(8);
- else
- fileURL = fileURL.substring(7);
- }
+ String fileURL = sresult.getSystemId();
- m_outputStream = new java.io.FileOutputStream(fileURL);
+ if (fileURL.startsWith("file:///"))
+ {
+ if (fileURL.substring(8).indexOf(":") >0)
+ fileURL = fileURL.substring(8);
+ else
+ fileURL = fileURL.substring(7);
+ }
- serializer.setOutputStream(m_outputStream);
- }
- else
- throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_OUTPUT_SPECIFIED,
null)); //"No output specified!");
+ m_outputStream = new java.io.FileOutputStream(fileURL);
- handler = serializer.asContentHandler();
+ serializer.setOutputStream(m_outputStream);
+
+ xoh = serializer;
+ }
+ else
+ throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_OUTPUT_SPECIFIED,
null)); //"No output specified!");
- this.setSerializer(serializer);
- }
- catch (UnsupportedEncodingException uee)
- {
- throw new TransformerException(uee);
+ // handler = serializer.asContentHandler();
+
+ // this.setSerializer(serializer);
+
+ xoh = serializer;
+ }
+// catch (UnsupportedEncodingException uee)
+// {
+// throw new TransformerException(uee);
+// }
+ catch (IOException ioe)
+ {
+ throw new TransformerException(ioe);
+ }
}
- catch (IOException ioe)
+ else
{
- throw new TransformerException(ioe);
+ throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_TRANSFORM_TO_RESULT_TYPE,
new Object[]{outputTarget.getClass().getName()})); //"Can't transform to a
Result of type "
+ //+ outputTarget.getClass().getName()
+ //+ "!");
}
- }
- else
- {
- throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_TRANSFORM_TO_RESULT_TYPE,
new Object[]{outputTarget.getClass().getName()})); //"Can't transform to a
Result of type "
- //+ outputTarget.getClass().getName()
- //+ "!");
- }
+
+ // before we forget, lets make the created handler hold a reference
+ // to the current TransformImpl object
+ xoh.setTransformer(this);
- return handler;
- }
+ SourceLocator srcLocator = getStylesheet();
+ xoh.setSourceLocator(srcLocator);
+
+
+ return xoh;
+
+
+ }
/**
* Process the source tree to the output result.
@@ -1118,11 +1171,11 @@
synchronized (m_reentryGuard)
{
- ContentHandler handler = createResultContentHandler(outputTarget);
+ SerializationHandler xoh = createSerializationHandler(outputTarget);
+ this.setSerializationHandler(xoh);
m_outputTarget = outputTarget;
- this.setContentHandler(handler);
transform(xmlSource, shouldRelease);
}
}
@@ -1142,11 +1195,11 @@
{
- ContentHandler handler = createResultContentHandler(outputTarget);
+ SerializationHandler xoh = createSerializationHandler(outputTarget);
+ this.setSerializationHandler(xoh);
m_outputTarget = outputTarget;
- this.setContentHandler(handler);
transformNode(node);
}
@@ -1165,7 +1218,7 @@
//dml
setExtensionsTable(getStylesheet());
// Make sure we're not writing to the same output content handler.
- synchronized (m_outputContentHandler)
+ synchronized (m_serializationHandler)
{
m_hasBeenReset = false;
@@ -1216,9 +1269,9 @@
// m_stylesheetRoot.getStartRule().execute(this);
// System.out.println("Done with applyTemplateToNode -
"+Thread.currentThread().getName());
- if (null != m_resultTreeHandler)
+ if (null != m_serializationHandler)
{
- m_resultTreeHandler.endDocument();
+ m_serializationHandler.endDocument();
}
}
catch (Exception se)
@@ -1238,21 +1291,21 @@
se = e;
}
- if (null != m_resultTreeHandler)
+ if (null != m_serializationHandler)
{
try
{
if(se instanceof org.xml.sax.SAXParseException)
-
m_resultTreeHandler.fatalError((org.xml.sax.SAXParseException)se);
+
m_serializationHandler.fatalError((org.xml.sax.SAXParseException)se);
else if(se instanceof TransformerException)
{
TransformerException te = ((TransformerException)se);
SAXSourceLocator sl = new SAXSourceLocator( te.getLocator() );
- m_resultTreeHandler.fatalError(new
org.xml.sax.SAXParseException(te.getMessage(), sl, te));
+ m_serializationHandler.fatalError(new
org.xml.sax.SAXParseException(te.getMessage(), sl, te));
}
else
{
- m_resultTreeHandler.fatalError(new
org.xml.sax.SAXParseException(se.getMessage(), new SAXSourceLocator(), se));
+ m_serializationHandler.fatalError(new
org.xml.sax.SAXParseException(se.getMessage(), new SAXSourceLocator(), se));
}
}
catch (Exception e){}
@@ -1380,30 +1433,6 @@
}
/**
- * <meta name="usage" content="internal"/>
- * Get the current serializer in use, which may well not
- * be the main serializer (for instance, this may well be
- * a text serializer for string creation from templates).
- *
- * @return The current serializer, or null if there is none.
- */
- public Serializer getSerializer()
- {
- return m_serializer;
- }
-
- /**
- * <meta name="usage" content="internal"/>
- * Set the current serializer.
- *
- * @param s The current serializer, or null.
- */
- public void setSerializer(Serializer s)
- {
- m_serializer = s;
- }
-
- /**
* Set a parameter for the templates.
*
* @param name The name of the parameter.
@@ -1750,10 +1779,16 @@
{
m_outputContentHandler = handler;
- if (null == m_resultTreeHandler)
- m_resultTreeHandler = new ResultTreeHandler(this, handler);
+ if (null == m_serializationHandler)
+ {
+ ToXMLSAXHandler h = new ToXMLSAXHandler();
+ h.setContentHandler(handler);
+ h.setTransformer(this);
+
+ m_serializationHandler = h;
+ }
else
- m_resultTreeHandler.setContentHandler(handler);
+ m_serializationHandler.setContentHandler(handler);
}
}
@@ -1835,12 +1870,19 @@
int resultFragment; // not yet reliably = dtmFrag.getDocument();
// Save the current result tree handler.
- ResultTreeHandler savedRTreeHandler = this.m_resultTreeHandler;
+ SerializationHandler savedRTreeHandler = this.m_serializationHandler;
+
// And make a new handler for the RTF.
- m_resultTreeHandler = new ResultTreeHandler(this, rtfHandler);
-
- ResultTreeHandler rth = m_resultTreeHandler;
+ ToSAXHandler h = new ToXMLSAXHandler();
+ h.setContentHandler(rtfHandler);
+ h.setTransformer(this);
+
+ // Replace the old handler (which was already saved)
+ m_serializationHandler = h;
+
+ // use local variable for the current handler
+ SerializationHandler rth = m_serializationHandler;
try
{
@@ -1879,7 +1921,7 @@
{
// Restore the previous result tree handler.
- this.m_resultTreeHandler = savedRTreeHandler;
+ this.m_serializationHandler = savedRTreeHandler;
}
return resultFragment;
@@ -1924,55 +1966,41 @@
}
// Save the current result tree handler.
- ResultTreeHandler savedRTreeHandler = this.m_resultTreeHandler;
+ SerializationHandler savedRTreeHandler = this.m_serializationHandler;
// Create a Serializer object that will handle the SAX events
// and build the ResultTreeFrag nodes.
StringWriter sw = (StringWriter) m_stringWriterObjectPool.getInstance();
- m_resultTreeHandler =
- (ResultTreeHandler) m_textResultHandlerObjectPool.getInstance();
-
- Serializer serializer = m_resultTreeHandler.getSerializer();
-
- try
- {
- if (null == serializer)
- {
- serializer =
- SerializerFactory.getSerializer(m_textformat.getProperties());
-
- m_resultTreeHandler.setSerializer(serializer);
- serializer.setWriter(sw);
+ m_serializationHandler =
+ (ToTextStream) m_textResultHandlerObjectPool.getInstance();
- ContentHandler shandler = serializer.asContentHandler();
-
- m_resultTreeHandler.init(this, shandler);
- }
- else
+ if (null == m_serializationHandler)
{
+ // if we didn't get one from the pool, go make a new one
- // Leave Commented. -sb
- // serializer.setWriter(sw);
- // serializer.setOutputFormat(m_textformat);
- // ContentHandler shandler = serializer.asContentHandler();
- // m_resultTreeHandler.setContentHandler(shandler);
- }
- }
- catch (IOException ioe)
- {
- throw new TransformerException(ioe);
- }
+
+ Serializer serializer =
org.apache.xml.serializer.SerializerFactory.getSerializer(
+ m_textformat.getProperties());
+ m_serializationHandler = (SerializationHandler) serializer;
+ }
+ m_serializationHandler.setTransformer(this);
+ m_serializationHandler.setWriter(sw);
+
+
String result;
try
{
- this.m_resultTreeHandler.startDocument();
+ /* Don't call startDocument, the SerializationHandler will
+ * generate its own internal startDocument call anyways
+ */
+ // this.m_serializationHandler.startDocument();
// Do the transformation of the child elements.
executeChildTemplates(elem, true);
- this.m_resultTreeHandler.endDocument();
+ this.m_serializationHandler.endDocument();
result = sw.toString();
}
@@ -1991,11 +2019,11 @@
catch (Exception ioe){}
m_stringWriterObjectPool.freeInstance(sw);
- m_textResultHandlerObjectPool.freeInstance(m_resultTreeHandler);
- m_resultTreeHandler.reset();
+ m_serializationHandler.reset();
+ m_textResultHandlerObjectPool.freeInstance(m_serializationHandler);
// Restore the previous result tree handler.
- m_resultTreeHandler = savedRTreeHandler;
+ m_serializationHandler = savedRTreeHandler;
}
return result;
@@ -2223,52 +2251,6 @@
* <meta name="usage" content="advanced"/>
* Execute each of the children of a template element.
*
- * @param elem The ElemTemplateElement that contains the children
- * that should execute.
- * @param handler The ContentHandler to where the result events
- * should be fed.
- *
- * @throws TransformerException
- */
- public void executeChildTemplates(
- ElemTemplateElement elem, ContentHandler handler)
- throws TransformerException
- {
-
- ResultTreeHandler rth = this.getResultTreeHandler();
-
- // These may well not be the same! In this case when calling
- // the Redirect extension, it has already set the ContentHandler
- // in the Transformer.
- ContentHandler savedRTHHandler = rth.getContentHandler();
- ContentHandler savedHandler = this.getContentHandler();
-
- try
- {
- getResultTreeHandler().flushPending();
- this.setContentHandler(handler);
-
- // %REVIEW% Make sure current node is being pushed.
- executeChildTemplates(elem, true);
- }
- catch (org.xml.sax.SAXException se)
- {
- throw new TransformerException(se);
- }
- finally
- {
- this.setContentHandler(savedHandler);
-
- // This fixes a bug where the ResultTreeHandler's ContentHandler
- // was being reset to the wrong ContentHandler.
- rth.setContentHandler(savedRTHHandler);
- }
- }
-
- /**
- * <meta name="usage" content="advanced"/>
- * Execute each of the children of a template element.
- *
* @param transformer The XSLT transformer instance.
*
* @param elem The ElemTemplateElement that contains the children
@@ -2297,7 +2279,7 @@
{
// Have to push stuff on for tooling...
this.pushElemTemplateElement(t);
- m_resultTreeHandler.characters(chars, 0, chars.length);
+ m_serializationHandler.characters(chars, 0, chars.length);
}
catch(SAXException se)
{
@@ -2352,6 +2334,50 @@
// if (check)
// getStackGuard().pop();
}
+ /**
+ * <meta name="usage" content="advanced"/>
+ * Execute each of the children of a template element.
+ *
+ * @param elem The ElemTemplateElement that contains the children
+ * that should execute.
+ * @param handler The ContentHandler to where the result events
+ * should be fed.
+ *
+ * @throws TransformerException
+ */
+ public void executeChildTemplates(
+ ElemTemplateElement elem, ContentHandler handler)
+ throws TransformerException
+ {
+
+ SerializationHandler xoh = this.getSerializationHandler();
+
+ // These may well not be the same! In this case when calling
+ // the Redirect extension, it has already set the ContentHandler
+ // in the Transformer.
+ SerializationHandler savedHandler = xoh;
+
+ try
+ {
+ xoh.flushPending();
+
+ // %REVIEW% Make sure current node is being pushed.
+ LexicalHandler lex = null;
+ if (handler instanceof LexicalHandler) {
+ lex = (LexicalHandler) lex;
+ }
+ m_serializationHandler = new ToXMLSAXHandler(handler, lex,
savedHandler.getEncoding());
+ executeChildTemplates(elem, true);
+ }
+ catch (TransformerException e)
+ {
+ throw e;
+ }
+ finally
+ {
+ m_serializationHandler = savedHandler;
+ }
+ }
/**
* <meta name="usage" content="advanced"/>
@@ -2810,17 +2836,28 @@
}
/**
- * Get the ResultTreeHandler object.
+ * Get the SerializationHandler object.
*
- * @return The current ResultTreeHandler, which may not
+ * @return The current SerializationHandler, which may not
* be the main result tree manager.
*/
- public ResultTreeHandler getResultTreeHandler()
+ public SerializationHandler getResultTreeHandler()
{
- return m_resultTreeHandler;
+ return m_serializationHandler;
}
/**
+ * Get the SerializationHandler object.
+ *
+ * @return The current SerializationHandler, which may not
+ * be the main result tree manager.
+ */
+ public SerializationHandler getSerializationHandler()
+ {
+ return m_serializationHandler;
+ }
+
+ /**
* Get the KeyManager object.
*
* @return A reference to the KeyManager object, which should
@@ -3234,7 +3271,7 @@
//
// sth.setExceptionThrown(e);
// }
- ContentHandler ch = getContentHandler();
+ // ContentHandler ch = getContentHandler();
// if(ch instanceof SourceTreeHandler)
// {
@@ -3333,7 +3370,8 @@
* This will get a snapshot of the current executing context
*
*
- * @return TransformerSnapshot object, snapshot of executing context
+ * @return TransformSnapshot object, snapshot of executing context
+ * @deprecated This is an internal tooling API that nobody seems to be
using
*/
public TransformSnapshot getSnapshot()
{
@@ -3348,6 +3386,7 @@
* @param ts The snapshot of where to start execution
*
* @throws TransformerException
+ * @deprecated This is an internal tooling API that nobody seems to be
using
*/
public void executeFromSnapshot(TransformSnapshot ts)
throws TransformerException
@@ -3366,6 +3405,7 @@
* from the snapshot point.
*
* @param ts The snapshot of where to start execution
+ * @deprecated This is an internal tooling API that nobody seems to be
using
*/
public void resetToStylesheet(TransformSnapshot ts)
{
@@ -3413,5 +3453,85 @@
return DTMWSFilter.INHERIT;
}
}
+ /**
+ * Initializer method.
+ *
+ * @param transformer non-null transformer instance
+ * @param realHandler Content Handler instance
+ */
+ public void init(ToXMLSAXHandler h,Transformer transformer,
ContentHandler realHandler)
+ {
+ h.setTransformer(transformer);
+ h.setContentHandler(realHandler);
+ }
+
+ public void setSerializationHandler(SerializationHandler xoh)
+ {
+ m_serializationHandler = xoh;
+ }
+
+
+
+ /**
+ * Fire off characters, cdate events.
+ * @see org.apache.xml.utils.SerializerTrace#fireGenerateEvent(int,
char[], int, int)
+ */
+ public void fireGenerateEvent(
+ int eventType,
+ char[] ch,
+ int start,
+ int length) {
+
+ GenerateEvent ge = new GenerateEvent(this, eventType, ch,
start, length);
+ m_traceManager.fireGenerateEvent(ge);
+ }
+
+ /**
+ * Fire off startElement, endElement events.
+ * @see org.apache.xml.utils.SerializerTrace#fireGenerateEvent(int,
String, Attributes)
+ */
+ public void fireGenerateEvent(
+ int eventType,
+ String name,
+ Attributes atts) {
+
+ GenerateEvent ge = new GenerateEvent(this, eventType, name,
atts);
+ m_traceManager.fireGenerateEvent(ge);
+ }
+
+ /**
+ * Fire off processingInstruction events.
+ * @see org.apache.xml.utils.SerializerTrace#fireGenerateEvent(int,
String, String)
+ */
+ public void fireGenerateEvent(int eventType, String name, String data) {
+ GenerateEvent ge = new GenerateEvent(this, eventType,
name,data);
+ m_traceManager.fireGenerateEvent(ge);
+ }
+
+ /**
+ * Fire off comment and entity ref events.
+ * @see org.apache.xml.utils.SerializerTrace#fireGenerateEvent(int,
String)
+ */
+ public void fireGenerateEvent(int eventType, String data) {
+ GenerateEvent ge = new GenerateEvent(this, eventType, data);
+ m_traceManager.fireGenerateEvent(ge);
+ }
+
+ /**
+ * Fire off startDocument, endDocument events.
+ * @see org.apache.xml.utils.SerializerTrace#fireGenerateEvent(int)
+ */
+ public void fireGenerateEvent(int eventType) {
+ GenerateEvent ge = new GenerateEvent(this, eventType);
+ m_traceManager.fireGenerateEvent(ge);
+ }
+
+ /**
+ * @see org.apache.xml.utils.SerializerTrace#hasTraceListeners()
+ */
+ public boolean hasTraceListeners() {
+ return m_traceManager.hasTraceListeners();
+ }
+
} // end TransformerImpl class
1.16 +8 -12
xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java
Index: TreeWalker2Result.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TreeWalker2Result.java 30 Jan 2003 18:45:56 -0000 1.15
+++ TreeWalker2Result.java 1 Apr 2003 20:26:40 -0000 1.16
@@ -56,8 +56,10 @@
*/
package org.apache.xalan.transformer;
+import org.apache.xalan.serialize.SerializerUtils;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.ref.DTMTreeWalker;
+import org.apache.xml.serializer.SerializationHandler;
import org.apache.xpath.XPathContext;
/**
@@ -72,7 +74,7 @@
TransformerImpl m_transformer;
/** The result tree handler */
- ResultTreeHandler m_handler;
+ SerializationHandler m_handler;
/** Node where to start the tree walk */
int m_startNode;
@@ -84,7 +86,7 @@
* @param handler The Result tree handler to use
*/
public TreeWalker2Result(TransformerImpl transformer,
- ResultTreeHandler handler)
+ SerializationHandler handler)
{
super(handler, null);
@@ -155,27 +157,21 @@
String namespace = m_dtm.getNamespaceURI(node);
//xcntxt.pushCurrentNode(node);
- m_handler.startElement(namespace, localName, elemName, null);
-
+ // SAX-like call to allow adding attributes afterwards
+ m_handler.startElement(namespace, localName, elemName);
boolean hasNSDecls = false;
DTM dtm = m_dtm;
for (int ns = dtm.getFirstNamespaceNode(node, true);
DTM.NULL != ns; ns = dtm.getNextNamespaceNode(node, ns, true))
{
- m_handler.ensureNamespaceDeclDeclared(dtm, ns);
+ SerializerUtils.ensureNamespaceDeclDeclared(m_handler,dtm, ns);
}
- // %REVIEW% This flag is apparently never set true. Is that
- // a bug, or should this code be phased out?
- if(hasNSDecls)
- {
- m_handler.addNSDeclsToAttrs();
- }
for (int attr = dtm.getFirstAttribute(node);
DTM.NULL != attr; attr = dtm.getNextAttribute(attr))
{
- m_handler.addAttribute(attr);
+ SerializerUtils.addAttribute(m_handler, attr);
}
}
1.1
xml-xalan/java/src/org/apache/xalan/transformer/XalanTransformState.java
Index: XalanTransformState.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2003, International Business
* Machines, Inc., http://www.ibm.com. For more information on the Apache
* Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.transformer;
import javax.xml.transform.Transformer;
import org.apache.xalan.templates.ElemTemplate;
import org.apache.xalan.templates.ElemTemplateElement;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.NodeIterator;
/**
* Before the serializer merge, the TransformState interface was
* implemented by ResultTreeHandler.
*/
public class XalanTransformState
implements TransformState {
Node m_node = null;
ElemTemplateElement m_currentElement = null;
ElemTemplate m_currentTemplate = null;
ElemTemplate m_matchedTemplate = null;
int m_currentNodeHandle = DTM.NULL;
Node m_currentNode = null;
int m_matchedNode = DTM.NULL;
DTMIterator m_contextNodeList = null;
boolean m_elemPending = false;
TransformerImpl m_transformer = null;
/**
* @see
org.apache.xml.serializer.SerializerTransformState#setCurrentNode(Node)
*/
public void setCurrentNode(Node n) {
m_node = n;
}
/**
* @see
org.apache.xml.serializer.SerializerTransformState#resetState(Transformer)
*/
public void resetState(Transformer transformer) {
if ((transformer != null) && (transformer instanceof
TransformerImpl)) {
m_transformer = (TransformerImpl)transformer;
m_currentElement = m_transformer.getCurrentElement();
m_currentTemplate = m_transformer.getCurrentTemplate();
m_matchedTemplate = m_transformer.getMatchedTemplate();
int currentNodeHandle = m_transformer.getCurrentNode();
DTM dtm =
m_transformer.getXPathContext().getDTM(currentNodeHandle);
m_currentNode = dtm.getNode(currentNodeHandle);
m_matchedNode = m_transformer.getMatchedNode();
m_contextNodeList = m_transformer.getContextNodeList();
}
}
/**
* @see org.apache.xalan.transformer.TransformState#getCurrentElement()
*/
public ElemTemplateElement getCurrentElement() {
if (m_elemPending)
return m_currentElement;
else
return m_transformer.getCurrentElement();
}
/**
* @see org.apache.xalan.transformer.TransformState#getCurrentNode()
*/
public Node getCurrentNode() {
if (m_currentNode != null) {
return m_currentNode;
} else {
DTM dtm =
m_transformer.getXPathContext().getDTM(m_transformer.getCurrentNode());
return dtm.getNode(m_transformer.getCurrentNode());
}
}
/**
* @see org.apache.xalan.transformer.TransformState#getCurrentTemplate()
*/
public ElemTemplate getCurrentTemplate() {
if (m_elemPending)
return m_currentTemplate;
else
return m_transformer.getCurrentTemplate();
}
/**
* @see org.apache.xalan.transformer.TransformState#getMatchedTemplate()
*/
public ElemTemplate getMatchedTemplate() {
if (m_elemPending)
return m_matchedTemplate;
else
return m_transformer.getMatchedTemplate();
}
/**
* @see org.apache.xalan.transformer.TransformState#getMatchedNode()
*/
public Node getMatchedNode() {
if (m_elemPending) {
DTM dtm = m_transformer.getXPathContext().getDTM(m_matchedNode);
return dtm.getNode(m_matchedNode);
} else {
DTM dtm =
m_transformer.getXPathContext().getDTM(m_transformer.getMatchedNode());
return dtm.getNode(m_transformer.getMatchedNode());
}
}
/**
* @see org.apache.xalan.transformer.TransformState#getContextNodeList()
*/
public NodeIterator getContextNodeList() {
if (m_elemPending) {
return new
org.apache.xml.dtm.ref.DTMNodeIterator(m_contextNodeList);
} else {
return new
org.apache.xml.dtm.ref.DTMNodeIterator(m_transformer.getContextNodeList());
}
}
/**
* @see org.apache.xalan.transformer.TransformState#getTransformer()
*/
public Transformer getTransformer() {
return m_transformer;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]