You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/06/03 05:11:52 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/transformer QueuedEvents.java ResultTreeHandler.java
sboag 01/06/02 20:11:52
Modified: java/src/org/apache/xalan/transformer Tag: DTM_EXP
QueuedEvents.java ResultTreeHandler.java
Log:
Folded in functionality from queued sax events directly into the
class, for performance reasons.
Revision Changes Path
No revision
No revision
1.7.2.1 +85 -50 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.7
retrieving revision 1.7.2.1
diff -u -r1.7 -r1.7.2.1
--- QueuedEvents.java 2001/03/11 21:58:47 1.7
+++ QueuedEvents.java 2001/06/03 03:11:52 1.7.2.1
@@ -57,11 +57,17 @@
package org.apache.xalan.transformer;
import java.util.Stack;
+import java.util.Vector;
import org.apache.xml.utils.ObjectPool;
import org.xml.sax.Attributes;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.utils.MutableAttrListImpl;
+import org.apache.xalan.templates.ElemTemplateElement;
+import org.apache.xalan.templates.ElemTemplate;
+
/**
* This class acts as a base for ResultTreeHandler, and keeps
* queud stack events. In truth, we don't need a stack,
@@ -71,50 +77,93 @@
{
/** The number of events queued */
- int m_eventCount = 0;
+ protected int m_eventCount = 0;
/** Queued start document */
- QueuedStartDocument m_startDoc = new QueuedStartDocument();
+ // QueuedStartDocument m_startDoc = new QueuedStartDocument();
/** Queued start element */
- QueuedStartElement m_startElement = new QueuedStartElement();
+ // QueuedStartElement m_startElement = new QueuedStartElement();
+
+ protected boolean m_docPending = false;
+ protected boolean m_docEnded = false;
+
+ /** Flag indicating that an event is pending */
+ public boolean m_elemIsPending = false;
+ /** Flag indicating that an event is ended */
+ public boolean m_elemIsEnded = false;
+
/**
- * Get the queued document event.
- *
- * @return the queued document event or null if none.
+ * The pending attributes. We have to delay the call to
+ * m_flistener.startElement(name, atts) because of the
+ * xsl:attribute and xsl:copy calls. In other words,
+ * the attributes have to be fully collected before you
+ * can call startElement.
*/
- QueuedStartDocument getQueuedDoc()
- {
- return (m_eventCount == 1) ? m_startDoc : null;
- }
+ protected MutableAttrListImpl m_attributes = new MutableAttrListImpl();
/**
- * Get the queued document event.
- *
- * @return the queued document event.
+ * Flag to try and get the xmlns decls to the attribute list
+ * before other attributes are added.
*/
- QueuedStartDocument getQueuedDocAtBottom()
- {
- return m_startDoc;
- }
+ protected boolean m_nsDeclsHaveBeenAdded = false;
/**
- * Get the queued element.
- *
- * @return the queued element.
+ * The pending element, namespace, and local name.
*/
- QueuedStartElement getQueuedElem()
- {
- return (m_eventCount > 1) ? m_startElement : null;
- }
+ protected String m_name;
+
+ /** Namespace URL of the element */
+ protected String m_url;
+ /** Local part of qualified name of the element */
+ protected String m_localName;
+
+ /**
+ * The stylesheet element that produced the SAX event.
+ */
+ protected ElemTemplateElement m_currentElement;
+
+ /**
+ * The current context node in the source tree.
+ */
+ protected int m_currentNode;
+
+ /**
+ * The xsl:template that is in effect, which may be a matched template
+ * or a named template.
+ */
+ protected ElemTemplate m_currentTemplate;
+
+ /**
+ * The xsl:template that was matched.
+ */
+ protected ElemTemplate m_matchedTemplate;
+
+ /**
+ * The node in the source tree that matched
+ * the template obtained via getMatchedTemplate().
+ */
+ protected int m_matchedNode;
+
+ /**
+ * The current context node list.
+ */
+ protected DTMIterator m_contextNodeList;
+
+ /** Vector of namespaces for this element */
+ protected Vector m_namespaces = null;
+
// /**
-// * This is for the derived class to init new events.
+// * Get the queued element.
// *
-// * @param qse Queud Sax event
+// * @return the queued element.
// */
-// protected abstract void initQSE(QueuedSAXEvent qse);
+// QueuedStartElement getQueuedElem()
+// {
+// return (m_eventCount > 1) ? m_startElement : null;
+// }
/**
* To re-initialize the document and element events
@@ -122,8 +171,6 @@
*/
protected void reInitEvents()
{
- // initQSE(m_startDoc);
- // initQSE(m_startElement);
}
/**
@@ -142,27 +189,9 @@
void pushDocumentEvent()
{
- m_startDoc.setPending(true);
+ // m_startDoc.setPending(true);
// initQSE(m_startDoc);
-
- m_eventCount++;
- }
-
- /**
- * Push the element event
- *
- *
- * @param ns Namespace URI of the element
- * @param localName Local part of the qualified name of the element
- * @param name Name of the element
- * @param atts Attribute children of the element
- */
- void pushElementEvent(String ns, String localName, String name,
- Attributes atts)
- {
-
- m_startElement.setPending(ns, localName, name, atts);
- // initQSE(m_startElement);
+ m_docPending = true;
m_eventCount++;
}
@@ -173,8 +202,14 @@
*/
void popEvent()
{
+ m_elemIsPending = false;
+ m_attributes.clear();
- m_startElement.reset();
+ m_nsDeclsHaveBeenAdded = false;
+ m_name = null;
+ m_url = null;
+ m_localName = null;
+ m_namespaces = null;
m_eventCount--;
}
1.37.2.9 +334 -312 xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java
Index: ResultTreeHandler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java,v
retrieving revision 1.37.2.8
retrieving revision 1.37.2.9
diff -u -r1.37.2.8 -r1.37.2.9
--- ResultTreeHandler.java 2001/05/27 03:05:14 1.37.2.8
+++ ResultTreeHandler.java 2001/06/03 03:11:52 1.37.2.9
@@ -71,7 +71,6 @@
import org.apache.xml.utils.XMLCharacterRecognizer;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.XPathContext;
-
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.DTMFilter;
@@ -99,7 +98,7 @@
implements ContentHandler, LexicalHandler, TransformState
{
- /** Indicate whether running in Debug mode */
+ /** Indicate whether running in Debug mode */
private static final boolean DEBUG = false;
/**
@@ -130,30 +129,26 @@
{
m_transformer = transformer;
- m_startElement.setTransformer(m_transformer);
- m_startDoc.setTransformer(m_transformer);
+ // m_startDoc.setTransformer(m_transformer);
TraceManager tracer = transformer.getTraceManager();
if ((null != tracer) && tracer.hasTraceListeners())
m_tracer = tracer;
else
m_tracer = null;
-
- m_startElement.setTraceManager(m_tracer);
- m_startDoc.setTraceManager(m_tracer);
+ // m_startDoc.setTraceManager(m_tracer);
m_contentHandler = realHandler;
- m_startElement.setContentHandler(m_contentHandler);
- m_startDoc.setContentHandler(m_contentHandler);
+ // m_startDoc.setContentHandler(m_contentHandler);
if (m_contentHandler instanceof LexicalHandler)
m_lexicalHandler = (LexicalHandler) m_contentHandler;
else
m_lexicalHandler = null;
-
- m_startElement.setIsTransformClient(m_contentHandler instanceof TransformerClient);
-
+
+ m_isTransformClient = (m_contentHandler instanceof TransformerClient);
+
m_cloner = new ClonerToResultTree(transformer, this);
// The stylesheet is set at a rather late stage, so I do
@@ -180,11 +175,10 @@
*/
public void endDocument() throws org.xml.sax.SAXException
{
- flushPending(EVT_ENDDOCUMENT);
- QueuedStartDocument qsd = getQueuedDocAtBottom();
+ flushPending(true);
- if (!qsd.isEnded)
+ if (!m_docEnded)
{
m_contentHandler.endDocument();
@@ -197,10 +191,11 @@
m_tracer.fireGenerateEvent(ge);
}
- qsd.setPending(false);
+ m_docEnded = true;
+ m_docPending = false;
}
}
-
+
/**
* Bottleneck the startElement event. This is used to "pend" an
* element, so that attributes can still be added to it before
@@ -218,36 +213,60 @@
throws org.xml.sax.SAXException
{
- QueuedStartElement qse = getQueuedElem();
-
if (DEBUG)
{
- if (null != qse && qse.isPending)
- System.out.println("(ResultTreeHandler#startElement - pended: " + qse.getURL() + "#"
- + qse.getLocalName());
-
- System.out.println("ResultTreeHandler#startElement: " + ns + "#" + localName);
-// if(null == ns)
-// {
-// (new RuntimeException(localName+" has a null namespace!")).printStackTrace();
-// }
+ if (m_elemIsPending)
+ System.out.println("(ResultTreeHandler#startElement - pended: "
+ + m_url + "#" + m_localName);
+
+ System.out.println("ResultTreeHandler#startElement: " + ns + "#"
+ + localName);
+
+ // if(null == ns)
+ // {
+ // (new RuntimeException(localName+" has a null namespace!")).printStackTrace();
+ // }
}
- checkForSerializerSwitch(ns, localName);
- flushPending(EVT_STARTELEMENT);
+ if(m_docPending)
+ checkForSerializerSwitch(ns, localName);
+
+ flushPending(true);
if (!m_nsContextPushed)
{
- if (DEBUG)
- System.out.println("ResultTreeHandler#startElement - push(startElement)");
+ if (DEBUG)
+ System.out.println(
+ "ResultTreeHandler#startElement - push(startElement)");
m_nsSupport.pushContext();
}
+
+ if (ns != null)
+ ensurePrefixIsDeclared(ns, name);
+
+ m_name = name;
+ m_url = ns;
+ m_localName = localName;
+
+ if (null != atts)
+ m_attributes.addAttributes(atts);
- ensurePrefixIsDeclared(ns, name);
+ m_elemIsPending = true;
+ m_elemIsEnded = false;
+
+ if(m_isTransformClient && (null != m_transformer))
+ {
+ m_currentElement = m_transformer.getCurrentElement();
+ m_currentTemplate = m_transformer.getCurrentTemplate();
+ m_matchedTemplate = m_transformer.getMatchedTemplate();
+ m_currentNode = m_transformer.getCurrentNode();
+ m_matchedNode = m_transformer.getMatchedNode();
+ m_contextNodeList = m_transformer.getContextNodeList(); // TODO: Need to clone
+ }
+ // initQSE(m_startElement);
- // getQueuedElem().setPending(ns, localName, name, atts);
- this.pushElementEvent(ns, localName, name, atts);
+ m_eventCount++;
}
/**
@@ -262,17 +281,18 @@
public void endElement(String ns, String localName, String name)
throws org.xml.sax.SAXException
{
+
if (DEBUG)
{
- QueuedStartElement qse = getQueuedElem();
- if (null != qse && qse.isPending)
- System.out.println("(ResultTreeHandler#endElement - pended: " + qse.getURL() + "#"
- + qse.getLocalName());
+ if (m_elemIsPending)
+ System.out.println("(ResultTreeHandler#endElement - pended: "
+ + m_url + "#" + m_localName);
- System.out.println("ResultTreeHandler#endElement: " + ns + "#" + localName);
+ System.out.println("ResultTreeHandler#endElement: " + ns + "#"
+ + localName);
}
-
- flushPending(EVT_ENDELEMENT);
+
+ flushPending(true);
m_contentHandler.endElement(ns, localName, name);
if (null != m_tracer)
@@ -293,7 +313,7 @@
m_nsSupport.popContext();
}
- /** Indicate whether a namespace context was pushed */
+ /** Indicate whether a namespace context was pushed */
boolean m_nsContextPushed = false;
/**
@@ -339,22 +359,25 @@
* @param prefix The Namespace prefix being declared.
* @param uri The Namespace URI the prefix is mapped to.
* @param shouldFlush Indicate whether pending events needs
- * to be flushed first
+ * to be flushed first
*
* @throws org.xml.sax.SAXException The client may throw
* an exception during processing.
*/
public void startPrefixMapping(
- String prefix, String uri, boolean shouldFlush) throws org.xml.sax.SAXException
+ String prefix, String uri, boolean shouldFlush)
+ throws org.xml.sax.SAXException
{
if (shouldFlush)
- flushPending(EVT_STARTPREFIXMAPPING);
+ flushPending(false);
if (!m_nsContextPushed)
{
if (DEBUG)
- System.out.println("ResultTreeHandler#startPrefixMapping push(startPrefixMapping: " + prefix + ")");
+ System.out.println(
+ "ResultTreeHandler#startPrefixMapping push(startPrefixMapping: "
+ + prefix + ")");
m_nsSupport.pushContext();
@@ -365,21 +388,23 @@
prefix = ""; // bit-o-hack, that that's OK
String existingURI = m_nsSupport.getURI(prefix);
-
- if(null == existingURI)
+
+ if (null == existingURI)
existingURI = "";
-
- if(null == uri)
+
+ if (null == uri)
uri = "";
if (!existingURI.equals(uri))
{
if (DEBUG)
{
- System.out.println("ResultTreeHandler#startPrefixMapping Prefix: " + prefix);
- System.out.println("ResultTreeHandler#startPrefixMapping uri: " + uri);
+ System.out.println("ResultTreeHandler#startPrefixMapping Prefix: "
+ + prefix);
+ System.out.println("ResultTreeHandler#startPrefixMapping uri: "
+ + uri);
}
-
+
m_nsSupport.declarePrefix(prefix, uri);
}
}
@@ -398,7 +423,8 @@
* @see #startPrefixMapping
* @see #endElement
*/
- public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException{}
+ public void endPrefixMapping(String prefix)
+ throws org.xml.sax.SAXException{}
/**
* Bottleneck the characters event.
@@ -409,32 +435,36 @@
*
* @throws org.xml.sax.SAXException
*/
- public void characters(char ch[], int start, int length) throws org.xml.sax.SAXException
+ public void characters(char ch[], int start, int length)
+ throws org.xml.sax.SAXException
{
// It would be nice to suppress all whitespace before the
// first element, but this is going to cause potential problems with
// text serialization and with text entities (right term?).
// So this really needs to be done at the serializer level.
+
/*if (m_startDoc.isPending
&& XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
return;*/
-
- if(DEBUG)
+ if (DEBUG)
{
System.out.print("ResultTreeHandler#characters: ");
- int n = start+length;
- for (int i = start; i < n; i++)
+
+ int n = start + length;
+
+ for (int i = start; i < n; i++)
{
- if(Character.isWhitespace(ch[i]))
- System.out.print("\\"+((int)ch[i]));
+ if (Character.isWhitespace(ch[i]))
+ System.out.print("\\" + ((int) ch[i]));
else
System.out.print(ch[i]);
- }
- System.out.println("");
+ }
+
+ System.out.println("");
}
- flushPending(EVT_CHARACTERS);
+ flushPending(true);
m_contentHandler.characters(ch, start, length);
if (null != m_tracer)
@@ -459,14 +489,12 @@
public void ignorableWhitespace(char ch[], int start, int length)
throws org.xml.sax.SAXException
{
-
- QueuedStartDocument qsd = getQueuedDoc();
- if ((null != qsd) && qsd.isPending
+ if (m_docPending
&& XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
return;
- flushPending(EVT_IGNORABLEWHITESPACE);
+ flushPending(true);
m_contentHandler.ignorableWhitespace(ch, start, length);
if (null != m_tracer)
@@ -491,7 +519,8 @@
public void processingInstruction(String target, String data)
throws org.xml.sax.SAXException
{
- flushPending(EVT_PROCESSINGINSTRUCTION);
+
+ flushPending(true);
m_contentHandler.processingInstruction(target, data);
if (null != m_tracer)
@@ -514,7 +543,7 @@
public void comment(String data) throws org.xml.sax.SAXException
{
- flushPending(EVT_COMMENT);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -540,10 +569,11 @@
*
* @throws org.xml.sax.SAXException
*/
- public void comment(char ch[], int start, int length) throws org.xml.sax.SAXException
+ public void comment(char ch[], int start, int length)
+ throws org.xml.sax.SAXException
{
- flushPending(EVT_COMMENT);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -570,7 +600,7 @@
public void entityReference(String name) throws org.xml.sax.SAXException
{
- flushPending(EVT_ENTITYREF);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -598,7 +628,7 @@
public void startEntity(String name) throws org.xml.sax.SAXException
{
- flushPending(EVT_STARTENTITY);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -616,7 +646,7 @@
public void endEntity(String name) throws org.xml.sax.SAXException
{
- flushPending(EVT_ENDENTITY);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -644,10 +674,11 @@
*
* @throws org.xml.sax.SAXException
*/
- public void startDTD(String s1, String s2, String s3) throws org.xml.sax.SAXException
+ public void startDTD(String s1, String s2, String s3)
+ throws org.xml.sax.SAXException
{
- flushPending(EVT_STARTDTD);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -663,7 +694,7 @@
public void endDTD() throws org.xml.sax.SAXException
{
- flushPending(EVT_ENDDTD);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -679,7 +710,7 @@
public void startCDATA() throws org.xml.sax.SAXException
{
- flushPending(EVT_STARTCDATA);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -695,7 +726,7 @@
public void endCDATA() throws org.xml.sax.SAXException
{
- flushPending(EVT_ENDCDATA);
+ flushPending(true);
if (null != m_lexicalHandler)
{
@@ -721,32 +752,99 @@
* wrapping another exception.
*/
public void skippedEntity(String name) throws org.xml.sax.SAXException{}
-
+
/**
- * Set whether Namespace declarations have been added to
+ * Set whether Namespace declarations have been added to
* this element
*
*
- * @param b Flag indicating whether Namespace declarations
+ * @param b Flag indicating whether Namespace declarations
* have been added to this element
*/
public void setNSDeclsHaveBeenAdded(boolean b)
+ {
+
+ m_nsDeclsHaveBeenAdded = b;
+ }
+
+ /**
+ * Flush the event.
+ *
+ * @throws TransformerException
+ *
+ * @throws org.xml.sax.SAXException
+ */
+ void flushDocEvent() throws org.xml.sax.SAXException
{
- QueuedStartElement qe = getQueuedElem();
- if (null != qe)
+
+ if (m_docPending)
{
- qe.setNSDeclsHaveBeenAdded(b);
+ m_contentHandler.startDocument();
+
+ if (null != m_tracer)
+ {
+ GenerateEvent ge =
+ new GenerateEvent(m_transformer,
+ GenerateEvent.EVENTTYPE_STARTDOCUMENT);
+
+ m_tracer.fireGenerateEvent(ge);
+ }
+
+ if (m_contentHandler instanceof TransformerClient)
+ {
+ ((TransformerClient) m_contentHandler).setTransformState(this);
+ }
+
+ m_docPending = false;
}
}
+
+ /**
+ * Flush the event.
+ *
+ * @throws SAXException
+ */
+ void flushElem() throws org.xml.sax.SAXException
+ {
+ if (m_elemIsPending)
+ {
+ if (null != m_name)
+ {
+ m_contentHandler.startElement(m_url, m_localName, m_name,
+ m_attributes);
+ if(null != m_tracer)
+ {
+ GenerateEvent ge =
+ new GenerateEvent(m_transformer,
+ GenerateEvent.EVENTTYPE_STARTELEMENT);
+
+ m_tracer.fireGenerateEvent(ge);
+ }
+ }
+
+ m_elemIsPending = false;
+ m_attributes.clear();
+
+ m_nsDeclsHaveBeenAdded = false;
+ m_name = null;
+ m_url = null;
+ m_localName = null;
+ m_namespaces = null;
+
+ // super.flush();
+ }
+ }
+
+
/**
* Flush the pending element.
*
* @throws org.xml.sax.SAXException
*/
- public void flushPending() throws org.xml.sax.SAXException
+ public final void flushPending() throws org.xml.sax.SAXException
{
- flushPending(EVT_NODE);
+ flushPending(true);
}
/**
@@ -754,40 +852,41 @@
*
* @param type Event type
*
+ * NEEDSDOC @param flushPrefixes
+ *
* @throws org.xml.sax.SAXException
*/
- public void flushPending(int type) throws org.xml.sax.SAXException
+ public final void flushPending(boolean flushPrefixes)
+ throws org.xml.sax.SAXException
{
-
- QueuedStartElement qe = getQueuedElem();
- QueuedStartDocument qdab = getQueuedDocAtBottom();
- if ((type != EVT_STARTPREFIXMAPPING) && qdab.isPending)
+ if (flushPrefixes && m_docPending)
{
- qdab.flush(this);
+ flushDocEvent();
}
- if ((null != qe) && qe.isPending)
+ if (m_elemIsPending)
{
- if (!qe.nsDeclsHaveBeenAdded())
+ if (!m_nsDeclsHaveBeenAdded)
addNSDeclsToAttrs();
sendStartPrefixMappings();
-
- if(DEBUG)
+
+ if (DEBUG)
{
System.out.println("ResultTreeHandler#flushPending - start flush: "
- +qe.getName());
+ + m_name);
}
- qe.flush();
-
- if(DEBUG)
+ flushElem();
+
+ if (DEBUG)
{
- System.out.println("ResultTreeHandler#flushPending - after flush, isPending: "
- +qe.isPending);
+ System.out.println(
+ "ResultTreeHandler#flushPending - after flush, isPending: "
+ + m_elemIsPending);
}
-
+
m_nsContextPushed = false;
}
}
@@ -804,34 +903,15 @@
public void outputResultTreeFragment(XObject obj, XPathContext support)
throws org.xml.sax.SAXException
{
+
int doc = obj.rtree();
DTM dtm = support.getDTM(doc);
-
- for (int n = dtm.getFirstChild(doc); DTM.NULL != n; n = dtm.getNextSibling(n))
- {
- flushPending(EVT_NODE); // I think.
- dtm.dispatchToEvents(n, this);
- }
- }
- /**
- * Clone an element with or without children.
- *
- * @param node Element to clone
- * @param shouldCloneAttributes Whether or not to clone with children
- *
- * @throws org.xml.sax.SAXException
- */
- public void cloneToResultTree(int node, boolean shouldCloneAttributes)
- throws org.xml.sax.SAXException
- {
- try
- {
- m_cloner.cloneToResultTree(node, shouldCloneAttributes);
- }
- catch(TransformerException te)
+ for (int n = dtm.getFirstChild(doc); DTM.NULL != n;
+ n = dtm.getNextSibling(n))
{
- throw new org.xml.sax.SAXException(te);
+ flushPending(true); // I think.
+ dtm.dispatchToEvents(n, this);
}
}
@@ -849,12 +929,13 @@
* If it's not, it still needs to be declared at this point.
* TODO: This needs to be done at an earlier stage in the game... -sb
*
- * @param ns Namespace URI of the element
+ * @param ns Namespace URI of the element
* @param rawName Raw name of element (with prefix)
*
* @throws org.xml.sax.SAXException
*/
- public void ensurePrefixIsDeclared(String ns, String rawName) throws org.xml.sax.SAXException
+ public void ensurePrefixIsDeclared(String ns, String rawName)
+ throws org.xml.sax.SAXException
{
if (ns != null && ns.length() > 0)
@@ -867,28 +948,32 @@
{
String foundURI = m_nsSupport.getURI(prefix);
- if ((null == foundURI) || !foundURI.equals(ns))
+ if ((null == foundURI) ||!foundURI.equals(ns))
{
-
startPrefixMapping(prefix, ns, false);
}
}
}
}
-
+
/**
* This function checks to make sure a given prefix is really
* declared. It might not be, because it may be an excluded prefix.
* If it's not, it still needs to be declared at this point.
* TODO: This needs to be done at an earlier stage in the game... -sb
*
- * @param ns Namespace URI of the element
+ * @param ns Namespace URI of the element
* @param rawName Raw name of element (with prefix)
*
+ * NEEDSDOC @param dtm
+ * NEEDSDOC @param namespace
+ *
* @throws org.xml.sax.SAXException
*/
- public void ensureNamespaceDeclDeclared(DTM dtm, int namespace) throws org.xml.sax.SAXException
+ public void ensureNamespaceDeclDeclared(DTM dtm, int namespace)
+ throws org.xml.sax.SAXException
{
+
String uri = dtm.getNodeValue(namespace);
String prefix = dtm.getNodeNameX(namespace);
@@ -896,9 +981,8 @@
{
String foundURI = m_nsSupport.getURI(prefix);
- if ((null == foundURI) || !foundURI.equals(uri))
+ if ((null == foundURI) ||!foundURI.equals(uri))
{
-
startPrefixMapping(prefix, uri, false);
}
}
@@ -949,7 +1033,7 @@
* first output element being an HTML element.
*
* @param ns Namespace URI of the element
- * @param localName Local part of name of the element
+ * @param localName Local part of name of the element
*
* @throws org.xml.sax.SAXException
*/
@@ -959,14 +1043,13 @@
try
{
- QueuedStartDocument qdab = getQueuedDocAtBottom();
-
- if (qdab.isPending)
+ if (m_docPending)
{
- SerializerSwitcher.switchSerializerIfHTML(m_transformer, ns, localName);
+ SerializerSwitcher.switchSerializerIfHTML(m_transformer, ns,
+ localName);
}
}
- catch(TransformerException te)
+ catch (TransformerException te)
{
throw new org.xml.sax.SAXException(te);
}
@@ -980,7 +1063,6 @@
{
Enumeration prefixes = m_nsSupport.getDeclaredPrefixes();
- QueuedStartElement qe = getQueuedElem();
while (prefixes.hasMoreElements())
{
@@ -998,49 +1080,39 @@
name = "xmlns:" + prefix;
String uri = m_nsSupport.getURI(prefix);
-
- if(null == uri)
+
+ if (null == uri)
uri = "";
- qe.addAttribute("http://www.w3.org/2000/xmlns/", prefix, name, "CDATA",
- uri);
+ m_attributes.addAttribute("http://www.w3.org/2000/xmlns/",
+ prefix, name, "CDATA", uri);
}
- qe.setNSDeclsHaveBeenAdded(true);
+ m_nsDeclsHaveBeenAdded = true;
}
/**
* Copy <KBD>xmlns:</KBD> attributes in if not already in scope.
*
* @param src Source Node
+ * NEEDSDOC @param type
+ * NEEDSDOC @param dtm
*
* @throws TransformerException
*/
- public void processNSDecls(int src) throws TransformerException
+ public void processNSDecls(int src, int type, DTM dtm)
+ throws TransformerException
{
try
{
- int type;
- DTM dtm = m_transformer.getXPathContext().getDTM(src);
-
- // Vector nameValues = null;
- // Vector alreadyProcessedPrefixes = null;
- int parent;
-
- if (((type = dtm.getNodeType(src)) == DTM.ELEMENT_NODE ||
- (type == DTM.ENTITY_REFERENCE_NODE))
- && (parent = dtm.getParent(src)) != DTM.NULL)
- {
- processNSDecls(parent);
- }
-
if (type == DTM.ELEMENT_NODE)
{
-
for (int namespace = dtm.getFirstNamespaceNode(src, true);
- DTM.NULL != namespace; namespace = dtm.getNextNamespaceNode(src, namespace, true))
+ DTM.NULL != namespace;
+ namespace = dtm.getNextNamespaceNode(src, namespace, true))
{
+
// String prefix = dtm.getPrefix(namespace);
String prefix = dtm.getNodeNameX(namespace);
String desturi = getURI(prefix);
@@ -1053,7 +1125,7 @@
}
}
}
- catch(org.xml.sax.SAXException se)
+ catch (org.xml.sax.SAXException se)
{
throw new TransformerException(se);
}
@@ -1076,7 +1148,7 @@
*
* @param namespace Given namespace URI
*
- * @return Prefix name associated with namespace URI
+ * @return Prefix name associated with namespace URI
*/
public String getPrefix(String namespace)
{
@@ -1105,18 +1177,18 @@
return m_nsSupport;
}
-// /**
-// * Override QueuedEvents#initQSE.
-// *
-// * @param qse Give queued Sax event
-// */
-// protected void initQSE(QueuedSAXEvent qse)
-// {
-//
-// // qse.setContentHandler(m_contentHandler);
-// // qse.setTransformer(m_transformer);
-// // qse.setTraceManager(m_tracer);
-// }
+ // /**
+ // * Override QueuedEvents#initQSE.
+ // *
+ // * @param qse Give queued Sax event
+ // */
+ // protected void initQSE(QueuedSAXEvent qse)
+ // {
+ //
+ // // qse.setContentHandler(m_contentHandler);
+ // // qse.setTransformer(m_transformer);
+ // // qse.setTraceManager(m_tracer);
+ // }
/**
* Return the current content handler.
@@ -1143,11 +1215,10 @@
{
m_contentHandler = ch;
- m_startElement.setIsTransformClient(m_contentHandler instanceof TransformerClient);
- m_startElement.setContentHandler(m_contentHandler);
- m_startDoc.setContentHandler(m_contentHandler);
-
- if (m_contentHandler instanceof LexicalHandler)
+
+ m_isTransformClient = (m_contentHandler instanceof TransformerClient);
+
+ if (m_contentHandler instanceof LexicalHandler)
m_lexicalHandler = (LexicalHandler) m_contentHandler;
else
m_lexicalHandler = null;
@@ -1158,7 +1229,7 @@
/**
* Get a unique namespace value.
*
- * @return a unique namespace value to be used with a
+ * @return a unique namespace value to be used with a
* fabricated prefix
*/
public int getUniqueNSValue()
@@ -1183,11 +1254,11 @@
* the attributes have to be fully collected before you
* can call startElement.
*
- * @return the pending attributes.
+ * @return the pending attributes.
*/
public MutableAttrListImpl getPendingAttributes()
{
- return getQueuedElem().getAttrs();
+ return m_attributes;
}
/**
@@ -1215,30 +1286,29 @@
String uri, String localName, String rawName, String type, String value)
throws TransformerException
{
-
- QueuedStartElement qe = getQueuedElem();
- if (!qe.nsDeclsHaveBeenAdded())
+ if (!m_nsDeclsHaveBeenAdded)
addNSDeclsToAttrs();
-
- if(null == uri) // defensive, should not really need this.
+
+ if (null == uri) // defensive, should not really need this.
uri = "";
try
{
- if(!rawName.equals("xmlns")) // don't handle xmlns default namespace.
+ if (!rawName.equals("xmlns")) // don't handle xmlns default namespace.
ensurePrefixIsDeclared(uri, rawName);
}
- catch(org.xml.sax.SAXException se)
+ catch (org.xml.sax.SAXException se)
{
throw new TransformerException(se);
}
if (DEBUG)
- System.out.println("ResultTreeHandler#addAttribute Adding attr: " + localName + ", " + uri);
+ System.out.println("ResultTreeHandler#addAttribute Adding attr: "
+ + localName + ", " + uri);
- if(!isDefinedNSDecl(rawName, value))
- qe.addAttribute(uri, localName, rawName, type, value);
+ if (!isDefinedNSDecl(rawName, value))
+ m_attributes.addAttribute(uri, localName, rawName, type, value);
}
/**
@@ -1248,8 +1318,8 @@
* @param rawName Raw name of namespace element
* @param value URI of given namespace
*
- * @return True if the namespace is already defined in list of
- * namespaces
+ * @return True if the namespace is already defined in list of
+ * namespaces
*/
public boolean isDefinedNSDecl(String rawName, String value)
{
@@ -1278,48 +1348,53 @@
}
/**
- * Returns whether a namespace is defined
+ * Returns whether a namespace is defined
*
*
* @param attr Namespace attribute node
*
- * @return True if the namespace is already defined in
+ * @return True if the namespace is already defined in
* list of namespaces
*/
public boolean isDefinedNSDecl(int attr)
{
+
DTM dtm = m_transformer.getXPathContext().getDTM(attr);
- if(DTM.NAMESPACE_NODE == dtm.getNodeType(attr))
+
+ if (DTM.NAMESPACE_NODE == dtm.getNodeType(attr))
{
+
// String prefix = dtm.getPrefix(attr);
String prefix = dtm.getNodeNameX(attr);
String uri = getURI(prefix);
-
+
if ((null != uri) && uri.equals(dtm.getStringValue(attr)))
return true;
}
return false;
}
-
+
/**
- * Returns whether a namespace is defined
+ * Returns whether a namespace is defined
*
*
* @param attr Namespace attribute node
* @param dtm The DTM that owns attr.
*
- * @return True if the namespace is already defined in
+ * @return True if the namespace is already defined in
* list of namespaces
*/
public boolean isDefinedNSDecl(int attr, DTM dtm)
{
- if(DTM.NAMESPACE_NODE == dtm.getNodeType(attr))
+
+ if (DTM.NAMESPACE_NODE == dtm.getNodeType(attr))
{
+
// String prefix = dtm.getPrefix(attr);
String prefix = dtm.getNodeNameX(attr);
String uri = getURI(prefix);
-
+
if ((null != uri) && uri.equals(dtm.getStringValue(attr)))
return true;
}
@@ -1327,7 +1402,6 @@
return false;
}
-
/**
* Copy an DOM attribute to the created output element, executing
* attribute templates as need be, and processing the xsl:use
@@ -1339,19 +1413,20 @@
*/
public void addAttribute(int attr) throws TransformerException
{
+
DTM dtm = m_transformer.getXPathContext().getDTM(attr);
if (isDefinedNSDecl(attr, dtm))
return;
-
+
String ns = dtm.getNamespaceURI(attr);
- if(ns == null)
+
+ if (ns == null)
ns = "";
// %OPT% ...can I just store the node handle?
- addAttribute(ns,
- dtm.getLocalName(attr), dtm.getNodeName(attr),
- "CDATA", dtm.getNodeValue(attr));
+ addAttribute(ns, dtm.getLocalName(attr), dtm.getNodeName(attr), "CDATA",
+ dtm.getNodeValue(attr));
} // end copyAttributeToTarget method
/**
@@ -1363,10 +1438,11 @@
*/
public void addAttributes(int src) throws TransformerException
{
+
DTM dtm = m_transformer.getXPathContext().getDTM(src);
- for (int node = dtm.getFirstAttribute(src); DTM.NULL != node;
- node = dtm.getNextAttribute(node))
+ for (int node = dtm.getFirstAttribute(src); DTM.NULL != node;
+ node = dtm.getNextAttribute(node))
{
addAttribute(node);
}
@@ -1377,14 +1453,12 @@
*
* @return True if an element is pending
*/
- public boolean isElementPending()
+ public final boolean isElementPending()
{
-
- QueuedStartElement qse = getQueuedElem();
-
- return (null != qse) ? qse.isPending : false;
+
+ return m_elemIsPending;
}
-
+
/**
* Retrieves the stylesheet element that produced
* the SAX event.
@@ -1397,9 +1471,9 @@
*/
public ElemTemplateElement getCurrentElement()
{
- QueuedStartElement qe = getQueuedElem();
- if(null != qe && qe.isPending)
- return qe.getCurrentElement();
+
+ if (m_elemIsPending)
+ return m_currentElement;
else
return m_transformer.getCurrentElement();
}
@@ -1412,13 +1486,15 @@
*/
public org.w3c.dom.Node getCurrentNode()
{
+
// %DTBD% Need DTM2DOM stuff
return null;
-// QueuedStartElement qe = getQueuedElem();
-// if(null != qe && qe.isPending)
-// return qe.getCurrentNode();
-// else
-// return m_transformer.getCurrentNode();
+
+ // QueuedStartElement qe = getQueuedElem();
+ // if(null != qe && qe.isPending)
+ // return qe.getCurrentNode();
+ // else
+ // return m_transformer.getCurrentNode();
}
/**
@@ -1434,9 +1510,9 @@
*/
public ElemTemplate getCurrentTemplate()
{
- QueuedStartElement qe = getQueuedElem();
- if(null != qe && qe.isPending)
- return qe.getCurrentTemplate();
+
+ if (m_elemIsPending)
+ return m_currentTemplate;
else
return m_transformer.getCurrentTemplate();
}
@@ -1456,9 +1532,9 @@
*/
public ElemTemplate getMatchedTemplate()
{
- QueuedStartElement qe = getQueuedElem();
- if(null != qe && qe.isPending)
- return qe.getMatchedTemplate();
+
+ if (m_elemIsPending)
+ return m_matchedTemplate;
else
return m_transformer.getMatchedTemplate();
}
@@ -1472,13 +1548,15 @@
*/
public org.w3c.dom.Node getMatchedNode()
{
+
// %DTBD% Need DTM2DOM stuff
return null;
-// QueuedStartElement qe = getQueuedElem();
-// if(null != qe && qe.isPending)
-// return qe.getMatchedNode();
-// else
-// return m_transformer.getMatchedNode();
+
+ // QueuedStartElement qe = getQueuedElem();
+ // if(null != qe && qe.isPending)
+ // return qe.getMatchedNode();
+ // else
+ // return m_transformer.getMatchedNode();
}
/**
@@ -1488,13 +1566,15 @@
*/
public org.w3c.dom.traversal.NodeIterator getContextNodeList()
{
+
// %DTBD% Need DTM2DOM stuff
return null;
-// QueuedStartElement qe = getQueuedElem();
-// if(null != qe && qe.isPending)
-// return qe.getContextNodeList();
-// else
-// return m_transformer.getContextNodeList();
+
+ // QueuedStartElement qe = getQueuedElem();
+ // if(null != qe && qe.isPending)
+ // return qe.getContextNodeList();
+ // else
+ // return m_transformer.getContextNodeList();
}
/**
@@ -1506,6 +1586,8 @@
{
return m_transformer;
}
+
+ boolean m_isTransformClient = false;
/**
* Use the SAX2 helper class to track result namespaces.
@@ -1524,7 +1606,7 @@
*/
private ContentHandler m_contentHandler;
- /** The LexicalHandler */
+ /** The LexicalHandler */
private LexicalHandler m_lexicalHandler;
/**
@@ -1537,9 +1619,9 @@
*/
private int m_uniqueNSValue = 0;
- /** Prefix used to create unique prefix names */
+ /** Prefix used to create unique prefix names */
private static final String S_NAMESPACEPREFIX = "ns";
-
+
/**
* This class clones nodes to the result tree.
*/
@@ -1552,64 +1634,4 @@
// These are passed to flushPending, to help it decide if it
// should really flush.
-
- /** SETDOCUMENTLOCATOR event type */
- private static final int EVT_SETDOCUMENTLOCATOR = 1;
-
- /** STARTDOCUMENT event type */
- private static final int EVT_STARTDOCUMENT = 2;
-
- /** ENDDOCUMENT event type */
- private static final int EVT_ENDDOCUMENT = 3;
-
- /** STARTPREFIXMAPPING event type */
- private static final int EVT_STARTPREFIXMAPPING = 4;
-
- /** ENDPREFIXMAPPING event type */
- private static final int EVT_ENDPREFIXMAPPING = 5;
-
- /** STARTELEMENT event type */
- private static final int EVT_STARTELEMENT = 6;
-
- /** ENDELEMENT event type */
- private static final int EVT_ENDELEMENT = 7;
-
- /** CHARACTERS event type */
- private static final int EVT_CHARACTERS = 8;
-
- /** IGNORABLEWHITESPACE event type */
- private static final int EVT_IGNORABLEWHITESPACE = 9;
-
- /** PROCESSINGINSTRUCTION event type */
- private static final int EVT_PROCESSINGINSTRUCTION = 10;
-
- /** SKIPPEDENTITY event type */
- private static final int EVT_SKIPPEDENTITY = 11;
-
- /** COMMENT event type */
- private static final int EVT_COMMENT = 12;
-
- /** ENTITYREF event type */
- private static final int EVT_ENTITYREF = 13;
-
- /** STARTENTITY event type */
- private static final int EVT_STARTENTITY = 14;
-
- /** ENDENTITY event type */
- private static final int EVT_ENDENTITY = 15;
-
- /** STARTDTD event type */
- private static final int EVT_STARTDTD = 16;
-
- /** ENDDTD event type */
- private static final int EVT_ENDDTD = 17;
-
- /** STARTCDATA event type */
- private static final int EVT_STARTCDATA = 22;
-
- /** ENDCDATA event type */
- private static final int EVT_ENDCDATA = 23;
-
- /** NODE event type */
- private static final int EVT_NODE = 24;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org