📄 adaptiveresulttreeimpl.java
字号:
/* * 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 * * http://www.apache.org/licenses/LICENSE-2.0 * * 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: AdaptiveResultTreeImpl.java,v 1.2.4.1 2005/09/06 05:52:18 pvedula Exp $ */package com.sun.org.apache.xalan.internal.xsltc.dom;import com.sun.org.apache.xalan.internal.xsltc.DOM;import com.sun.org.apache.xalan.internal.xsltc.TransletException;import com.sun.org.apache.xalan.internal.xsltc.StripFilter;import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;import com.sun.org.apache.xalan.internal.xsltc.runtime.AttributeList;import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;import com.sun.org.apache.xml.internal.utils.XMLString;import com.sun.org.apache.xml.internal.serializer.SerializationHandler;import javax.xml.transform.SourceLocator;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.Attributes;import org.xml.sax.SAXException;/** * AdaptiveResultTreeImpl is a adaptive DOM model for result tree fragments (RTF). It is * used in the case where the RTF is likely to be pure text yet it can still be a DOM tree. * It is designed for RTFs which have <xsl:call-template> or <xsl:apply-templates> in * the contents. Example: * <pre> * <xsl:variable name = "x"> * <xsl:call-template name = "test"> * <xsl:with-param name="a" select="."/> * </xsl:call-template> * </xsl:variable> * </pre> * <p>In this example the result produced by <xsl:call-template> is likely to be a single * Text node. But it can also be a DOM tree. This kind of RTF cannot be modelled by * SimpleResultTreeImpl. * <p> * AdaptiveResultTreeImpl can be considered as a smart switcher between SimpleResultTreeImpl * and SAXImpl. It treats the RTF as simple Text and uses the SimpleResultTreeImpl model * at the beginning. However, if it receives a call which indicates that this is a DOM tree * (e.g. startElement), it will automatically transform itself into a wrapper around a * SAXImpl. In this way we can have a light-weight model when the result only contains * simple text, while at the same time it still works when the RTF is a DOM tree. * <p> * All methods in this class are overridden to delegate the action to the wrapped SAXImpl object * if it is non-null, or delegate the action to the SimpleResultTreeImpl if there is no * wrapped SAXImpl. * <p> * %REVISIT% Can we combine this class with SimpleResultTreeImpl? I think it is possible, but * it will make SimpleResultTreeImpl more expensive. I will use two separate classes at * this time. */public class AdaptiveResultTreeImpl extends SimpleResultTreeImpl{ // Document URI index, which increases by 1 at each getDocumentURI() call. private static int _documentURIIndex = 0; // The SAXImpl object wrapped by this class, if the RTF is a tree. private SAXImpl _dom; /** The following fields are only used for the nested SAXImpl **/ // The whitespace filter private DTMWSFilter _wsfilter; // The size of the RTF private int _initSize; // True if we want to build the ID index table private boolean _buildIdIndex; // The AttributeList private final AttributeList _attributes = new AttributeList(); // The element name private String _openElementName; // Create a AdaptiveResultTreeImpl public AdaptiveResultTreeImpl(XSLTCDTMManager dtmManager, int documentID, DTMWSFilter wsfilter, int initSize, boolean buildIdIndex) { super(dtmManager, documentID); _wsfilter = wsfilter; _initSize = initSize; _buildIdIndex = buildIdIndex; } // Return the DOM object wrapped in this object. public DOM getNestedDOM() { return _dom; } // Return the document ID public int getDocument() { if (_dom != null) { return _dom.getDocument(); } else { return super.getDocument(); } } // Return the String value of the RTF public String getStringValue() { if (_dom != null) { return _dom.getStringValue(); } else { return super.getStringValue(); } } public DTMAxisIterator getIterator() { if (_dom != null) { return _dom.getIterator(); } else { return super.getIterator(); } } public DTMAxisIterator getChildren(final int node) { if (_dom != null) { return _dom.getChildren(node); } else { return super.getChildren(node); } } public DTMAxisIterator getTypedChildren(final int type) { if (_dom != null) { return _dom.getTypedChildren(type); } else { return super.getTypedChildren(type); } } public DTMAxisIterator getAxisIterator(final int axis) { if (_dom != null) { return _dom.getAxisIterator(axis); } else { return super.getAxisIterator(axis); } } public DTMAxisIterator getTypedAxisIterator(final int axis, final int type) { if (_dom != null) { return _dom.getTypedAxisIterator(axis, type); } else { return super.getTypedAxisIterator(axis, type); } } public DTMAxisIterator getNthDescendant(int node, int n, boolean includeself) { if (_dom != null) { return _dom.getNthDescendant(node, n, includeself); } else { return super.getNthDescendant(node, n, includeself); } } public DTMAxisIterator getNamespaceAxisIterator(final int axis, final int ns) { if (_dom != null) { return _dom.getNamespaceAxisIterator(axis, ns); } else { return super.getNamespaceAxisIterator(axis, ns); } } public DTMAxisIterator getNodeValueIterator(DTMAxisIterator iter, int returnType, String value, boolean op) { if (_dom != null) { return _dom.getNodeValueIterator(iter, returnType, value, op); } else { return super.getNodeValueIterator(iter, returnType, value, op); } } public DTMAxisIterator orderNodes(DTMAxisIterator source, int node) { if (_dom != null) { return _dom.orderNodes(source, node); } else { return super.orderNodes(source, node); } } public String getNodeName(final int node) { if (_dom != null) { return _dom.getNodeName(node); } else { return super.getNodeName(node); } } public String getNodeNameX(final int node) { if (_dom != null) { return _dom.getNodeNameX(node); } else { return super.getNodeNameX(node); } } public String getNamespaceName(final int node) { if (_dom != null) { return _dom.getNamespaceName(node); } else { return super.getNamespaceName(node); } } // Return the expanded type id of a given node public int getExpandedTypeID(final int nodeHandle) { if (_dom != null) { return _dom.getExpandedTypeID(nodeHandle); } else { return super.getExpandedTypeID(nodeHandle); } } public int getNamespaceType(final int node) { if (_dom != null) { return _dom.getNamespaceType(node); } else { return super.getNamespaceType(node); } } public int getParent(final int nodeHandle) { if (_dom != null) { return _dom.getParent(nodeHandle); } else { return super.getParent(nodeHandle); } } public int getAttributeNode(final int gType, final int element) { if (_dom != null) { return _dom.getAttributeNode(gType, element); } else { return super.getAttributeNode(gType, element); } } public String getStringValueX(final int nodeHandle) { if (_dom != null) { return _dom.getStringValueX(nodeHandle); } else { return super.getStringValueX(nodeHandle); } } public void copy(final int node, SerializationHandler handler) throws TransletException { if (_dom != null) { _dom.copy(node, handler); } else { super.copy(node, handler); } } public void copy(DTMAxisIterator nodes, SerializationHandler handler) throws TransletException { if (_dom != null) { _dom.copy(nodes, handler); } else { super.copy(nodes, handler); } } public String shallowCopy(final int node, SerializationHandler handler) throws TransletException { if (_dom != null) { return _dom.shallowCopy(node, handler); } else { return super.shallowCopy(node, handler); } } public boolean lessThan(final int node1, final int node2) { if (_dom != null) { return _dom.lessThan(node1, node2); } else { return super.lessThan(node1, node2); } } /** * Dispatch the character content of a node to an output handler. * * The escape setting should be taken care of when outputting to * a handler. */ public void characters(final int node, SerializationHandler handler) throws TransletException { if (_dom != null) { _dom.characters(node, handler); } else { super.characters(node, handler); } } public Node makeNode(int index) { if (_dom != null) { return _dom.makeNode(index); } else { return super.makeNode(index); } } public Node makeNode(DTMAxisIterator iter) { if (_dom != null) { return _dom.makeNode(iter); } else { return super.makeNode(iter); } } public NodeList makeNodeList(int index) { if (_dom != null) { return _dom.makeNodeList(index); } else { return super.makeNodeList(index); } } public NodeList makeNodeList(DTMAxisIterator iter) { if (_dom != null) { return _dom.makeNodeList(iter); } else { return super.makeNodeList(iter); } } public String getLanguage(int node) { if (_dom != null) { return _dom.getLanguage(node); } else { return super.getLanguage(node); } } public int getSize() { if (_dom != null) { return _dom.getSize(); } else { return super.getSize(); } } public String getDocumentURI(int node) { if (_dom != null) { return _dom.getDocumentURI(node); } else { return "adaptive_rtf" + _documentURIIndex++; } } public void setFilter(StripFilter filter)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -