/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: TreeWalker.java,v 1.2.4.1 2005/09/15 08:15:59 suresh_emailid Exp $
*/
/**
* This class does a pre-order walk of the DOM tree, calling a ContentHandler
* interface as it goes.
* @xsl.usage advanced
*/
public class TreeWalker
{
/** Local reference to a ContentHandler */
// ARGHH!! JAXP Uses Xerces without setting the namespace processing to ON!
// DOM2Helper m_dh = new DOM2Helper();
/** DomHelper for this TreeWalker */
/** Locator object for this TreeWalker */
/**
* Get the ContentHandler used for the tree walk.
*
* @return the ContentHandler used for the tree walk
*/
{
return m_contentHandler;
}
/**
* Get the ContentHandler used for the tree walk.
*
* @return the ContentHandler used for the tree walk
*/
{
}
/**
* Constructor.
* @param contentHandler The implemention of the
* @param systemId System identifier for the document.
* contentHandler operation (toXMLString, digest, ...)
*/
{
this.m_contentHandler = contentHandler;
else {
try {
// Bug see Bugzilla 26741
m_locator.setSystemId(SecuritySupport.getSystemProperty("user.dir") + File.separator + "dummy.xsl");
}
}
}
}
/**
* Constructor.
* @param contentHandler The implemention of the
* contentHandler operation (toXMLString, digest, ...)
*/
{
this.m_contentHandler = contentHandler;
try {
// Bug see Bugzilla 26741
m_locator.setSystemId(SecuritySupport.getSystemProperty("user.dir") + File.separator + "dummy.xsl");
}
}
}
/**
* Constructor.
* @param contentHandler The implemention of the
* contentHandler operation (toXMLString, digest, ...)
*/
{
this.m_contentHandler = contentHandler;
if (m_contentHandler != null)
try {
// Bug see Bugzilla 26741
m_locator.setSystemId(SecuritySupport.getSystemProperty("user.dir") + File.separator + "dummy.xsl");
}
}
m_dh = new DOM2Helper();
}
/**
* Perform a pre-order traversal non-recursive style.
*
* Note that TreeWalker assumes that the subtree is intended to represent
* a complete (though not necessarily well-formed) document and, during a
* traversal, startDocument and endDocument will always be issued to the
* SAX listener.
*
* @param pos Node in the tree where to start traversal
*
* @throws TransformerException
*/
{
this.m_contentHandler.startDocument();
this.m_contentHandler.endDocument();
}
/**
* Perform a pre-order traversal non-recursive style.
*
* In contrast to the traverse() method this method will not issue
* startDocument() and endDocument() events to the SAX listener.
*
* @param pos Node in the tree where to start traversal
*
* @throws TransformerException
*/
{
{
{
break;
{
{
break;
}
}
}
}
}
/**
* Perform a pre-order traversal non-recursive style.
* Note that TreeWalker assumes that the subtree is intended to represent
* a complete (though not necessarily well-formed) document and, during a
* traversal, startDocument and endDocument will always be issued to the
* SAX listener.
*
* @param pos Node in the tree where to start traversal
* @param top Node in the tree where to end traversal
*
* @throws TransformerException
*/
{
this.m_contentHandler.startDocument();
{
{
break;
{
{
break;
}
}
}
}
this.m_contentHandler.endDocument();
}
/** Flag indicating whether following text to be processed is raw text */
boolean nextIsRaw = false;
/**
* Optimized dispatch of characters.
*/
{
if(m_contentHandler instanceof com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)
{
((com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)m_contentHandler).characters(node);
}
else
{
}
}
/**
* Start processing given node
*
*
* @param node Node to process
*
* @throws org.xml.sax.SAXException
*/
{
if (m_contentHandler instanceof NodeConsumer)
{
}
{
}
else
{
}
switch (node.getNodeType())
{
case Node.COMMENT_NODE :
{
if (m_contentHandler instanceof LexicalHandler)
{
}
}
break;
case Node.DOCUMENT_FRAGMENT_NODE :
// ??;
break;
case Node.DOCUMENT_NODE :
break;
case Node.ELEMENT_NODE :
// System.out.println("TreeWalker#startNode: "+node.getNodeName());
for (int i = 0; i < nAttrs; i++)
{
// System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
{
// System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
int index;
// Use "" instead of null, as Xerces likes "" for the
// name of the default namespace. Fix attributed
// to "Steven Murray" <smurray@ebt.com>.
attr.getNodeValue());
}
}
// System.out.println("m_dh.getNamespaceOfNode(node): "+m_dh.getNamespaceOfNode(node));
// System.out.println("m_dh.getLocalNameOfNode(node): "+m_dh.getLocalNameOfNode(node));
ns = "";
node.getNodeName(),
break;
case Node.PROCESSING_INSTRUCTION_NODE :
{
// String data = pi.getData();
{
nextIsRaw = true;
}
else
{
}
}
break;
case Node.CDATA_SECTION_NODE :
{
if (isLexH)
{
lh.startCDATA();
}
{
if (isLexH)
{
}
}
}
break;
{
//String data = ((Text) node).getData();
if (nextIsRaw)
{
nextIsRaw = false;
}
else
{
}
}
break;
case Node.ENTITY_REFERENCE_NODE :
{
if (m_contentHandler instanceof LexicalHandler)
{
eref.getNodeName());
}
else
{
// warning("Can not output entity to a pure SAX ContentHandler");
}
}
break;
default :
}
}
/**
* End processing of given node
*
*
* @param node Node we just finished processing
*
* @throws org.xml.sax.SAXException
*/
{
switch (node.getNodeType())
{
case Node.DOCUMENT_NODE :
break;
case Node.ELEMENT_NODE :
ns = "";
node.getNodeName());
for (int i = 0; i < nAttrs; i++)
{
{
int index;
// Use "" instead of null, as Xerces likes "" for the
// name of the default namespace. Fix attributed
// to "Steven Murray" <smurray@ebt.com>.
}
}
break;
case Node.CDATA_SECTION_NODE :
break;
case Node.ENTITY_REFERENCE_NODE :
{
if (m_contentHandler instanceof LexicalHandler)
{
}
}
break;
default :
}
}
} //TreeWalker