/*
* 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: SimpleResultTreeImpl.java,v 1.2.4.1 2005/09/06 10:09:25 pvedula Exp $
*/
/**
* This class represents a light-weight DOM model for simple result tree fragment(RTF).
* A simple RTF is an RTF that has only one Text node. The Text node can be produced by a
* combination of Text, xsl:value-of and xsl:number instructions. It can also be produced
* by a control structure (xsl:if or xsl:choose) whose body is pure Text.
* <p>
* A SimpleResultTreeImpl has only two nodes, i.e. the ROOT node and its Text child. All DOM
* interfaces are overridden with this in mind. For example, the getStringValue() interface
* returns the value of the Text node. This class receives the character data from the
* characters() interface.
* <p>
* This class implements DOM and SerializationHandler. It also implements the DTM interface
* for support in MultiDOM. The nested iterators (SimpleIterator and SingletonIterator) are
* used to support the nodeset() extension function.
*/
{
/**
* The SimpleIterator is designed to support the nodeset() extension function. It has
* a traversal direction parameter. The DOWN direction is used for child and descendant
* axes, while the UP direction is used for parent and ancestor axes.
*
* This iterator only handles two nodes (RTF_ROOT and RTF_TEXT). If the type is set,
* it will also match the node type with the given type.
*/
{
// The direction of traversal (default to DOWN).
// DOWN is for child and descendant. UP is for parent and ancestor.
int _currentNode;
public SimpleIterator()
{
}
{
}
{
}
public int next()
{
// Increase the node ID for down traversal. Also match the node type
// if the type is given.
if (_direction == DIRECTION_DOWN) {
while (_currentNode < NUMBER_OF_NODES) {
else
_currentNode++;
}
else
}
return END;
}
// Decrease the node ID for up traversal.
else {
while (_currentNode >= 0) {
else
_currentNode--;
}
else
}
return END;
}
}
{
_startNode = nodeID;
// Increase the node ID by 1 if self is not included.
if (_direction == DIRECTION_DOWN)
nodeID++;
else if (_direction == DIRECTION_UP)
nodeID--;
}
return this;
}
public void setMark()
{
}
public void gotoMark()
{
}
} // END of SimpleIterator
/**
* The SingletonIterator is used for the self axis.
*/
{
int _currentNode;
public SingletonIterator()
{
}
{
}
public void setMark()
{
}
public void gotoMark()
{
}
{
return this;
}
public int next()
{
if (_currentNode == END)
return END;
_currentNode = END;
return getNodeHandle(_currentNode);
}
else
return getNodeHandle(_currentNode);
return END;
}
} // END of SingletonIterator
// empty iterator to be returned when there are no children
new DTMAxisIteratorBase() {
public DTMAxisIterator reset() { return this; }
public void setMark() {}
public void gotoMark() {}
public int getLast() { return 0; }
public int getPosition() { return 0; }
public DTMAxisIterator cloneIterator() { return this; }
public void setRestartable(boolean isRestartable) { }
};
// The root node id of the simple RTF
// The Text node id of the simple RTF (simple RTF has only one Text node).
// The number of nodes.
// Document URI index, which increases by 1 at each getDocumentURI() call.
// Constant for empty String
// The String value of the Text node.
// This is set at the endDocument() call.
// The array of Text items, which is built by the characters() call.
// The characters() interface can be called multiple times. Each character item
// can have different escape settings.
// The DTMManager
// Number of character items
// The document ID
private int _documentID;
// A BitArray, each bit holding the escape setting for a character item.
// The current escape setting
private boolean _escaping = true;
// Create a SimpleResultTreeImpl from a DTMManager and a document ID.
{
}
{
return _dtmManager;
}
// Return the document ID
public int getDocument()
{
return _documentID;
}
// Return the String value of the RTF
{
return _text;
}
{
return new SingletonIterator(getDocument());
}
{
}
{
}
// Return the axis iterator for a given axis.
// The SimpleIterator is used for the child, descendant, parent and ancestor axes.
{
switch (axis)
{
case Axis.DESCENDANT:
case Axis.ANCESTORORSELF:
case Axis.DESCENDANTORSELF:
return new SingletonIterator();
default:
return EMPTY_ITERATOR;
}
}
{
switch (axis)
{
case Axis.DESCENDANT:
case Axis.ANCESTORORSELF:
case Axis.DESCENDANTORSELF:
return new SingletonIterator(type);
default:
return EMPTY_ITERATOR;
}
}
// %REVISIT% Can this one ever get used?
{
return null;
}
{
return null;
}
// %REVISIT% Can this one ever get used?
{
return null;
}
{
return source;
}
{
return "#text";
else
return EMPTY_STR;
}
{
return EMPTY_STR;
}
{
return EMPTY_STR;
}
// Return the expanded type id of a given node
{
else
}
{
return 0;
}
{
}
{
}
{
return _text;
else
return EMPTY_STR;
}
throws TransletException
{
}
throws TransletException
{
int node;
{
}
}
throws TransletException
{
return null;
}
{
return false;
}
return true;
}
else
}
/**
* Dispatch the character content of a node to an output handler.
*
* The escape setting should be taken care of when outputting to
* a handler.
*/
throws TransletException
{
boolean escapeBit = false;
boolean oldEscapeSetting = false;
try {
for (int i = 0; i < _size; i++) {
if (_dontEscape != null) {
if (escapeBit) {
}
}
if (escapeBit) {
}
}
} catch (SAXException e) {
throw new TransletException(e);
}
}
}
// %REVISIT% Can the makeNode() and makeNodeList() interfaces ever get used?
{
return null;
}
{
return null;
}
{
return null;
}
{
return null;
}
{
return null;
}
public int getSize()
{
return 2;
}
{
return "simple_rtf" + _documentURIIndex++;
}
{
}
{
}
{
return false;
}
{
return false;
}
throws TransletException
{
return null;
}
/**
* Return the node identity from a node handle.
*/
{
}
/**
* Return the node handle from a node identity.
*/
{
}
{
return null;
}
{
return null;
}
{
return this;
}
{
return 0;
}
{
return null;
}
{
return null;
}
/** Implementation of the SerializationHandler interfaces **/
/**
* We only need to override the endDocument, characters, and
* setEscaping interfaces. A simple RTF does not have element
* nodes. We do not need to touch startElement and endElement.
*/
{
}
{
// Set the String value when the document is built.
if (_size == 1)
else {
for (int i = 0; i < _size; i++) {
}
}
}
{
// Resize the text array if necessary
}
// If the escape setting is false, set the corresponding bit in
// the _dontEscape BitArray.
if (!_escaping) {
// The _dontEscape array is only created when needed.
if (_dontEscape == null) {
}
// Resize the _dontEscape array if necessary
}
}
throws SAXException
{
}
if (!_escaping) {
if (_dontEscape == null) {
}
}
}
{
return temp;
}
/** Implementation of the DTM interfaces **/
/**
* The DTM interfaces are not used in this class. Implementing the DTM
* interface is a requirement from MultiDOM. If we have a better way
* of handling multiple documents, we can get rid of the DTM dependency.
*
* The following interfaces are just placeholders. The implementation
* does not have an impact because they will not be used.
*/
{
}
{
}
{
return null;
}
{
}
{
return getNodeHandle(RTF_TEXT);
else
}
{
return getFirstChild(nodeHandle);
}
{
}
{
}
{
}
{
}
{
}
{
}
boolean inScope)
{
}
{
return getDocument();
}
{
return getDocument();
}
{
}
{
return 0;
}
int[] startAndLen)
{
return null;
}
{
}
{
return EMPTY_STR;
}
{
return EMPTY_STR;
}
{
return EMPTY_STR;
}
{
return null;
}
{
return EMPTY_STR;
}
{
}
{
else
}
{
return 2;
return 1;
else
}
{
return false;
}
{
return EMPTY_STR;
}
{
}
{
return null;
}
{
return null;
}
{
return null;
}
{
return null;
}
public boolean getDocumentAllDeclarationsProcessed()
{
return false;
}
{
return null;
}
{
return null;
}
{
}
public boolean supportsPreStripping()
{
return false;
}
{
}
{
return false;
}
{
return false;
}
{
return false;
}
public void dispatchCharactersEvents(
int nodeHandle,
boolean normalize)
{
}
{
}
{
return makeNode(nodeHandle);
}
public boolean needsTwoThreads()
{
return false;
}
{
return null;
}
{
return null;
}
{
return null;
}
{
return null;
}
{
return null;
}
{
return null;
}
{
}
{
}
{
return null;
}
public void documentRegistration()
{
}
public void documentRelease()
{
}
{
}
}