/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-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: SAXImpl.java,v 1.5 2005/09/28 13:48:37 pvedula Exp $
*/
/**
* SAXImpl is the core model for SAX input source. SAXImpl objects are
* usually created from an XSLTCDTMManager.
*
* <p>DOMSource inputs are handled using DOM2SAX + SAXImpl. SAXImpl has a
* few specific fields (e.g. _node2Ids, _document) to keep DOM-related
* information. They are used when the processing behavior between DOM and
* SAX has to be different. Examples of these include id function and
* unparsed entity.
*
* <p>SAXImpl extends SAX2DTM2 instead of SAX2DTM for better performance.
* @author Jacek Ambroziak
* @author Santiago Pericas-Geertsen
* @author Morten Jorgensen
* @author Douglas Sellers <douglasjsellers@hotmail.com>
*/
implements DOMEnhancedForDTM, DOMBuilder
{
/* ------------------------------------------------------------------- */
/* DOMBuilder fields BEGIN */
/* ------------------------------------------------------------------- */
// Namespace prefix-to-uri mapping stuff
// Stack used to keep track of what whitespace text nodes are protected
// by xml:space="preserve" attributes and which nodes that are not.
private int[] _xmlSpaceStack;
private boolean _preserve = false;
private boolean _escaping = true;
private boolean _disableEscaping = false;
/* ------------------------------------------------------------------- */
/* DOMBuilder fields END */
/* ------------------------------------------------------------------- */
// empty String for null attribute values
// empty iterator to be returned when there are no children
// The number of expanded names
// Namespace related stuff
// The initial size of the text buffer
// Tracks which textnodes are not escaped
// The URI to this document
// The owner Document when the input source is DOMSource.
// The hashtable for org.w3c.dom.Node to node id mapping.
// This is only used when the input is a DOMSource and the
// buildIdIndex flag is true.
// True if the input source is a DOMSource.
private boolean _hasDOMSource = false;
// The DTMManager
// Support for access/navigation through org.w3c.dom API
/**
* Define the origin of the document from which the tree was built
*/
}
}
/**
* Returns the origin of the document from which the tree was built
*/
}
return getDocumentURI();
}
// This method only has a function in DOM adapters
}
/**
* Lookup a namespace URI from a prefix starting at node. This method
* is used in the execution of xsl:element when the prefix is not known
* at compile time.
*/
throws TransletException
{
}
return getNodeValue(nsnode);
}
}
}
return null;
}
/**
* Returns 'true' if a specific node is an element (of any type)
*/
}
/**
* Returns 'true' if a specific node is an attribute (of any type)
*/
}
/**
* Returns the number of nodes in the tree (used for indexing)
*/
public int getSize() {
return getNumberOfNodes();
}
/**
* Part of the DOM interface - no function here.
*/
}
/**
* Returns true if node1 comes before node2 in document order
*/
return false;
}
return true;
}
}
/**
* Create an org.w3c.dom.Node from a node in the tree
*/
}
if (nodeID < 0) {
return null;
}
}
else {
}
}
/**
* Create an org.w3c.dom.Node from a node in an iterator
* The iterator most be started before this method is called
*/
}
/**
* Create an org.w3c.dom.NodeList from a node in the tree
*/
if (_nodeLists == null) {
}
if (nodeID < 0) {
return null;
}
new SingletonIterator(index)));
}
else {
}
}
/**
* Create an org.w3c.dom.NodeList from a node iterator
* The iterator most be started before this method is called
*/
return new DTMAxisIterNodeList(this, iter);
}
/**
* Iterator that returns the namespace nodes as defined by the XPath data
* model for a given node, filtered by extended type ID.
*/
/**
* Constructor TypedChildrenIterator
*
*
* @param nodeType The extended type ID being requested.
*/
super();
if(m_expandedNameTable != null){
}
}
/**
* Get the next node in the iteration.
*
* @return The next node handle in the iteration, or END.
*/
public int next() {
return (END);
}
return returnNode(node);
}
}
return (END);
}
} // end of TypedNamespaceIterator
/**************************************************************
* This is a specialised iterator for predicates comparing node or
* attribute values to variable or parameter values.
*/
{
private boolean _op;
private final boolean _isReverse;
{
}
public boolean isReverse()
{
return _isReverse;
}
{
try {
clone._isRestartable = false;
}
catch (CloneNotSupportedException e) {
e.toString());
return null;
}
}
{
}
{
return resetPosition();
}
public int next()
{
int node;
if (_returnType == RETURN_CURRENT) {
return returnNode(node);
}
else {
}
}
}
return END;
}
{
if (_isRestartable) {
return resetPosition();
}
return this;
}
public void setMark()
{
}
public void gotoMark()
{
}
} // end NodeValueIterator
{
}
/**
* Encapsulates an iterator in an OrderedIterator to ensure node order
*/
{
return new DupFilterIterator(source);
}
/**
* Returns singleton iterator containg the document root
* Works for them main document (mark == 0). It cannot be made
* to point to any other node through setStartNode().
*/
{
return new SingletonIterator(getDocument(), true);
}
/**
* Get mapping from DOM namespace types to external namespace types
*/
{
if (s == null) {
return 0;
}
int eType = getIdForNamespace(s);
}
/**
* Returns the namespace type of a specific node
*/
{
return super.getNamespaceType(node);
}
/**
* Sets up a translet-to-dom type mapping table
*/
// Padding with number of names, because they
// may need to be added, i.e for RTFs. See copy03
for (int i = 0; i < nNames; i++) {
//int type = getGeneralizedType(namesArray[i]);
}
return result;
}
/**
* Returns the internal type associated with an expanded QName
*/
return getGeneralizedType(name, true);
}
/**
* Returns the internal type associated with an expanded QName
*/
int index = -1;
int code;
// Is there a prefix?
}
// Local part of name is after colon. lastIndexOf returns -1 if
// there is no colon, so lNameStartIdx will be zero in that case.
// Distinguish attribute and element names. Attribute has @ before
// local part of name.
}
else {
}
// Extract local name
}
/**
*/
{
// Delegate the work to getMapping2 if the document is not fully built.
// Some of the processing has to be different in this case.
if (_namesSize < 0) {
}
int i;
// primitive types map to themselves
result[i] = (short)i;
}
}
// actual mapping of caller requested names
for (i = 0; i < namesLength; i++) {
names[i],
types[i],
true);
}
}
return result;
}
/**
*/
{
int i;
// primitive types map to themselves
result[i] = i;
}
// caller's types map into appropriate dom types
}
return(result);
}
/**
* This method is used when the document is not fully built.
*/
{
int i;
int[] generalizedTypes = null;
if (namesLength > 0) {
generalizedTypes = new int[namesLength];
}
int resultLength = exLength;
for (i = 0; i < namesLength; i++) {
// When the document is not fully built, the searchOnly
// flag should be set to false. That means we should add
// the type if it is not already in the expanded name table.
//generalizedTypes[i] = getGeneralizedType(names[i], false);
generalizedTypes[i] =
names[i],
types[i],
false);
}
}
final short[] result = new short[resultLength];
// primitive types map to themselves
result[i] = (short)i;
}
}
// actual mapping of caller requested names
for (i = 0; i < namesLength; i++) {
int genType = generalizedTypes[i];
}
}
return(result);
}
/**
* Get mapping from DOM namespace types to external namespace types
*/
{
int i;
final int mappingLength = _uriCount;
final short[] result = new short[mappingLength];
// Initialize all entries to -1
for (i=0; i<mappingLength; i++) {
result[i] = (short)(-1);
}
for (i=0; i<nsLength; i++) {
}
}
return(result);
}
/**
* Get mapping from external namespace types to DOM namespace types
*/
{
int i;
for (i = 0; i < length; i++) {
}
return result;
}
/**
* Construct a SAXImpl object using the default block size.
*/
boolean doIndexing, boolean buildIdIndex)
{
}
/**
* Construct a SAXImpl object using the given block size.
*/
boolean doIndexing, int blocksize,
boolean buildIdIndex,
boolean newNameTable)
{
_dtmManager = mgr;
// Use a smaller size for the space stack if the blocksize is small
/* From DOMBuilder */
// If the input source is DOMSource, set the _document field and
// create the node2Ids table.
_hasDOMSource = true;
}
else {
}
}
}
/**
* Migrate a DTM built with an old DTMManager to a new DTMManager.
* After the migration, the new DTMManager will treat the DTM as
* one that is built by itself.
* This is used to support DTM sharing between multiple transformations.
* @param manager the DTMManager
*/
if (manager instanceof XSLTCDTMManager) {
}
}
/**
* Return the node identity for a given id String
*
* @param idString The id String
* @return The identity of the node whose id is the given String.
*/
{
}
else {
}
}
/**
* Return true if the input source is DOMSource.
*/
public boolean hasDOMSource()
{
return _hasDOMSource;
}
/*---------------------------------------------------------------------------*/
/* DOMBuilder methods begin */
/*---------------------------------------------------------------------------*/
/**
* Call this when an xml:space attribute is encountered to
*/
{
}
}
/**
* to whatever it was before the corresponding startElement().
*/
{
_idx--;
}
}
/**
* Find out whether or not to strip whitespace nodes.
*
*
* @return whether or not to strip whitespace nodes.
*/
protected boolean getShouldStripWhitespace()
{
return _preserve ? false : super.getShouldStripWhitespace();
}
/**
* Creates a text-node and checks if it is a whitespace node.
*/
private void handleTextEscaping() {
if (_dontEscape == null) {
}
// Resize the _dontEscape BitArray if necessary.
}
_disableEscaping = false;
}
}
/****************************************************************/
/* SAX Interface Starts Here */
/****************************************************************/
/**
* SAX2: Receive notification of character data.
*/
{
}
/**
* SAX2: Receive notification of the beginning of a document.
*/
{
super.startDocument();
}
/**
* SAX2: Receive notification of the end of a document.
*/
{
super.endDocument();
}
/**
* Specialized interface used by DOM2SAX. This one has an extra Node
* parameter to build the Node -> id map.
*/
throws SAXException
{
if (m_buildIdIndex) {
}
}
/**
* SAX2: Receive notification of the beginning of an element.
*/
throws SAXException
{
if (m_wsfilter != null) {
// Look for any xml:space attributes
// Depending on the implementation of attributes, this
// might be faster than looping through all attributes. ILENE
if (index >= 0) {
}
}
}
/**
* SAX2: Receive notification of the end of an element.
*/
throws SAXException
{
// Revert to strip/preserve-space setting from before this element
if (m_wsfilter != null) {
}
}
/**
* SAX2: Receive notification of a processing instruction.
*/
throws SAXException
{
}
/**
* SAX2: Receive notification of ignorable whitespace in element
* content. Similar to characters(char[], int, int).
*/
throws SAXException
{
}
/**
* SAX2: Begin the scope of a prefix-URI Namespace mapping.
*/
throws SAXException
{
}
throws SAXException
{
// Check if the URI already exists before pushing on stack
}
}
/**
* SAX2: Report an XML comment anywhere in the document.
*/
throws SAXException
{
}
return temp;
}
/*---------------------------------------------------------------------------*/
/* DOMBuilder methods end */
/*---------------------------------------------------------------------------*/
/**
* Prints the whole tree to standard output
*/
{
switch(getNodeType(node))
{
case DTM.DOCUMENT_NODE:
break;
case DTM.COMMENT_NODE:
break;
default:
{
}
}
break;
}
}
/**
* Returns the name of a node (attribute or element).
*/
{
// Get the node type and make sure that it is within limits
switch(type)
{
case DTM.DOCUMENT_NODE:
case DTM.COMMENT_NODE:
return EMPTYSTRING;
case DTM.NAMESPACE_NODE:
return this.getLocalName(nodeh);
default:
return super.getNodeName(nodeh);
}
}
/**
* Returns the namespace URI to which a node belongs
*/
{
return "";
}
String s;
}
/**
* Returns the attribute node of a given type (if any) for an element
*/
{
{
}
}
/**
* Returns the value of a given attribute type of a given element
*/
{
}
/**
*/
{
}
/**
* Returns an iterator with all the children of a given node
*/
{
}
/**
* Returns an iterator with all children of a specific type
* for a given node (element)
*/
{
return(new TypedChildrenIterator(type));
}
/**
* This is a shortcut to the iterators that implement the
* supported XPath axes (only namespace::) is not supported.
* Returns a bare-bones iterator that must be initialized
* with a start node (using iterator.setStartNode()).
*/
{
switch (axis)
{
return new SingletonIterator();
return new ChildrenIterator();
return new ParentIterator();
return new AncestorIterator();
case Axis.ANCESTORORSELF:
return (new AncestorIterator()).includeSelf();
return new AttributeIterator();
case Axis.DESCENDANT:
return new DescendantIterator();
case Axis.DESCENDANTORSELF:
return (new DescendantIterator()).includeSelf();
return new FollowingIterator();
return new PrecedingIterator();
case Axis.FOLLOWINGSIBLING:
return new FollowingSiblingIterator();
case Axis.PRECEDINGSIBLING:
return new PrecedingSiblingIterator();
return new NamespaceIterator();
return new RootIterator();
default:
}
return null;
}
/**
* Similar to getAxisIterator, but this one returns an iterator
* containing nodes of a typed axis (ex.: child::foo)
*/
{
// Most common case handled first
return new TypedChildrenIterator(type);
}
return(EMPTYITERATOR);
}
switch (axis)
{
return new TypedSingletonIterator(type);
return new TypedChildrenIterator(type);
return new TypedAncestorIterator(type);
case Axis.ANCESTORORSELF:
return new TypedAttributeIterator(type);
case Axis.DESCENDANT:
return new TypedDescendantIterator(type);
case Axis.DESCENDANTORSELF:
return new TypedFollowingIterator(type);
return new TypedPrecedingIterator(type);
case Axis.FOLLOWINGSIBLING:
return new TypedFollowingSiblingIterator(type);
case Axis.PRECEDINGSIBLING:
return new TypedPrecedingSiblingIterator(type);
return new TypedNamespaceIterator(type);
return new TypedRootIterator(type);
default:
}
return null;
}
/**
* Do not think that this returns an iterator for the namespace axis.
* It returns an iterator with nodes that belong in a certain namespace,
* The 'axis' specifies the axis for the base iterator from which the
* nodes are taken, while 'ns' specifies the namespace URI type.
*/
{
return EMPTYITERATOR;
}
else {
switch (axis) {
return new NamespaceChildrenIterator(ns);
return new NamespaceAttributeIterator(ns);
default:
}
}
}
/**
* Iterator that handles node tests that test for a namespace, but have
* a wild card for the local name of the node, i.e., node tests of the
* form <axis>::<prefix>:*
*/
public final class NamespaceWildcardIterator
extends InternalAxisIteratorBase
{
/**
* The namespace type index.
*/
protected int m_nsType;
/**
* A nested typed axis iterator that retrieves nodes of the principal
* node kind for that axis.
*/
/**
* Constructor NamespaceWildcard
*
* @param axis The axis that this iterator will traverse
* @param nsType The namespace type index
*/
// Create a nested iterator that will select nodes of
// the principal node kind for the selected axis.
switch (axis) {
// For "attribute::p:*", the principal node kind is
// attribute
}
// This covers "namespace::p:*". It is syntactically
// correct, though it doesn't make much sense.
}
default: {
// In all other cases, the principal node kind is
// element
}
}
}
/**
* Set start to END should 'close' the iterator,
* i.e. subsequent call to next() should return END.
*
* @param node Sets the root of the iteration.
*
* @return A DTMAxisIterator set to the start of the iteration.
*/
if (_isRestartable) {
_startNode = node;
}
return this;
}
/**
* Get the next node in the iteration.
*
* @return The next node handle in the iteration, or END.
*/
public int next() {
int node;
// Return only nodes that are in the selected namespace
return returnNode(node);
}
}
return END;
}
/**
* Returns a deep copy of this iterator. The cloned iterator is not
* reset.
*
* @return a deep copy of this iterator.
*/
try {
(NamespaceWildcardIterator) super.clone();
clone._isRestartable = false;
return clone;
} catch (CloneNotSupportedException e) {
e.toString());
return null;
}
}
/**
* True if this iterator has a reversed axis.
*
* @return <code>true</code> if this iterator is a reversed axis.
*/
public boolean isReverse() {
return m_baseIterator.isReverse();
}
public void setMark() {
}
public void gotoMark() {
}
}
/**
* Iterator that returns children within a given namespace for a
* given node. The functionality chould be achieved by putting a
* filter on top of a basic child iterator, but a specialised
* iterator is used for efficiency (both speed and size of translet).
*/
public final class NamespaceChildrenIterator
extends InternalAxisIteratorBase
{
/** The extended type ID being requested. */
private final int _nsType;
/**
* Constructor NamespaceChildrenIterator
*
*
* @param type The extended type ID being requested.
*/
}
/**
* Set start to END should 'close' the iterator,
* i.e. subsequent call to next() should return END.
*
* @param node Sets the root of the iteration.
*
* @return A DTMAxisIterator set to the start of the iteration.
*/
//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
node = getDocument();
}
if (_isRestartable) {
_startNode = node;
return resetPosition();
}
return this;
}
/**
* Get the next node in the iteration.
*
* @return The next node handle in the iteration, or END.
*/
public int next() {
: _nextsib(_currentNode);
_currentNode = node;
return returnNode(nodeHandle);
}
}
}
return END;
}
} // end of NamespaceChildrenIterator
/**
* Iterator that returns attributes within a given namespace for a node.
*/
public final class NamespaceAttributeIterator
extends InternalAxisIteratorBase
{
/** The extended type ID being requested. */
private final int _nsType;
/**
* Constructor NamespaceAttributeIterator
*
*
* @param nsType The extended type ID being requested.
*/
super();
}
/**
* Set start to END should 'close' the iterator,
* i.e. subsequent call to next() should return END.
*
* @param node Sets the root of the iteration.
*
* @return A DTMAxisIterator set to the start of the iteration.
*/
//%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
node = getDocument();
}
if (_isRestartable) {
_startNode = node;
break;
}
}
_currentNode = node;
return resetPosition();
}
return this;
}
/**
* Get the next node in the iteration.
*
* @return The next node handle in the iteration, or END.
*/
public int next() {
int node = _currentNode;
int nextNode;
return END;
}
break;
}
}
return returnNode(node);
}
} // end of NamespaceAttributeIterator
/**
* Returns an iterator with all descendants of a node that are of
* a given type.
*/
{
return new TypedDescendantIterator(type);
}
/**
* Returns the nth descendant of a node
*/
{
return new NthDescendantIterator(n);
}
/**
* Copy the string value of a node directly to an output handler
*/
throws TransletException
{
try {
} catch (SAXException e) {
throw new TransletException(e);
}
}
}
/**
* Copy a node-set to an output handler
*/
throws TransletException
{
int node;
}
}
/**
* Copy the whole tree to an output handler
*/
{
}
/**
* Performs a deep copy (ref. XSLs copy-of())
*
* TODO: Copy namespace declarations. Can't be done until we
* add namespace nodes and keep track of NS prefixes
* TODO: Copy comment nodes
*/
throws TransletException
{
}
throws TransletException
{
try {
switch(type)
{
case DTM.DOCUMENT_NODE:
}
break;
break;
case DTM.COMMENT_NODE:
break;
boolean oldEscapeSetting = false;
boolean escapeBit = false;
if (_dontEscape != null) {
if (escapeBit) {
}
}
if (escapeBit) {
}
break;
case DTM.ATTRIBUTE_NODE:
break;
case DTM.NAMESPACE_NODE:
break;
default:
{
// Start element definition
//if(isChild) => not to copy any namespaces from parents
// else copy all namespaces in scope
// Copy element children
}
// Close element definition
}
// Shallow copy of attribute to output handler
else {
}
}
break;
}
}
catch (Exception e) {
throw new TransletException(e);
}
}
/**
* Copies a processing instruction node to an output handler
*/
throws TransletException
{
try {
} catch (Exception e) {
throw new TransletException(e);
}
}
/**
* Performs a shallow copy (ref. XSLs copy())
*/
throws TransletException
{
try {
switch(type)
{
case DTM.ELEMENT_NODE:
return name;
case DTM.DOCUMENT_NODE:
return EMPTYSTRING;
return null;
return null;
case DTM.COMMENT_NODE:
return null;
case DTM.NAMESPACE_NODE:
return null;
case DTM.ATTRIBUTE_NODE:
return null;
default:
}
return null;
}
} catch (Exception e) {
throw new TransletException(e);
}
}
/**
* Returns a node' defined language for a node (if any)
*/
{
return getNodeValue(langAttr);
}
}
}
return(null);
}
/**
* Returns an instance of the DOMBuilder inner class
* This class will consume the input document through a SAX2
* interface and populate the tree.
*/
{
return this;
}
/**
* Return a SerializationHandler for output handling.
* This method is used by Result Tree Fragments.
*/
{
return new ToXMLSAXHandler(this, "UTF-8");
}
/**
* Return a instance of a DOM class to be used as an RTF
*/
{
}
/**
* Return a instance of a DOM class to be used as an RTF
*
* @param initSize The initial size of the DOM.
* @param rtfType The type of the RTF
* @param addToManager true if the RTF should be registered with the DTMManager.
* @return The DOM object which represents the RTF.
*/
{
if (addToManager) {
return rtf;
}
else {
}
}
if (addToManager) {
return rtf;
}
else {
}
}
else {
true, false, false,
}
}
/**
* %HZ% Need Javadoc
*/
if (m_idAttributes == null) {
return null;
}
// Convert a java.util.Hashtable to an xsltc.runtime.Hashtable
if (!idValues.hasMoreElements()) {
return null;
}
while (idValues.hasMoreElements()) {
}
return idAttrsTable;
}
/**
* The getUnparsedEntityURI function returns the URI of the unparsed
* entity with the specified name in the same document as the context
* node (see [3.3 Unparsed Entities]). It returns the empty string if
* there is no such entity.
*/
{
// Special handling for DOM input
return uri;
}
return uri;
}
if (notationName != null) {
}
}
}
return uri;
}
else {
return super.getUnparsedEntityURI(name);
}
}
}