stylesheetroot.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,336 行 · 第 1/3 页
JAVA
1,336 行
* @return Whether the caller should bother with check for * whitespace nodes. */ public boolean shouldCheckWhitespace() { return null != m_whiteSpaceInfoList; } /** * Get information about whether or not an element should strip whitespace. * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * * @param support The XPath runtime state. * @param targetElement Element to check * * @return WhiteSpaceInfo for the given element * * @throws TransformerException */ public WhiteSpaceInfo getWhiteSpaceInfo( XPathContext support, int targetElement, DTM dtm) throws TransformerException { if (null != m_whiteSpaceInfoList) return (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support, targetElement, null, false, dtm); else return null; } /** * Get information about whether or not an element should strip whitespace. * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * * @param support The XPath runtime state. * @param targetElement Element to check * * @return true if the whitespace should be stripped. * * @throws TransformerException */ public boolean shouldStripWhiteSpace( XPathContext support, int targetElement) throws TransformerException { if (null != m_whiteSpaceInfoList) { while(DTM.NULL != targetElement) { DTM dtm = support.getDTM(targetElement); WhiteSpaceInfo info = (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support, targetElement, null, false, dtm); if(null != info) return info.getShouldStripSpace(); int parent = dtm.getParent(targetElement); if(DTM.NULL != parent && DTM.ELEMENT_NODE == dtm.getNodeType(parent)) targetElement = parent; else targetElement = DTM.NULL; } } return false; } /** * Get information about whether or not whitespace can be stripped. * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * * @return true if the whitespace can be stripped. */ public boolean canStripWhiteSpace() { return (null != m_whiteSpaceInfoList); } /** * <meta name="usage" content="advanced"/> * The default template to use for text nodes if we don't find * anything else. This is initialized in initDefaultRule(). * @serial */ private ElemTemplate m_defaultTextRule; /** * <meta name="usage" content="advanced"/> * Get the default template for text. * * @return the default template for text. */ public final ElemTemplate getDefaultTextRule() { return m_defaultTextRule; } /** * <meta name="usage" content="advanced"/> * The default template to use if we don't find anything * else. This is initialized in initDefaultRule(). * @serial */ private ElemTemplate m_defaultRule; /** * <meta name="usage" content="advanced"/> * Get the default template for elements. * * @return the default template for elements. */ public final ElemTemplate getDefaultRule() { return m_defaultRule; } /** * <meta name="usage" content="advanced"/> * The default template to use for the root if we don't find * anything else. This is initialized in initDefaultRule(). * We kind of need this because the defaultRule isn't good * enough because it doesn't supply a document context. * For now, I default the root document element to "HTML". * Don't know if this is really a good idea or not. * I suspect it is not. * @serial */ private ElemTemplate m_defaultRootRule; /** * <meta name="usage" content="advanced"/> * Get the default template for a root node. * * @return The default template for a root node. */ public final ElemTemplate getDefaultRootRule() { return m_defaultRootRule; } /** * <meta name="usage" content="advanced"/> * The start rule to kick off the transformation. * @serial */ private ElemTemplate m_startRule; /** * <meta name="usage" content="advanced"/> * Get the default template for a root node. * * @return The default template for a root node. */ public final ElemTemplate getStartRule() { return m_startRule; } /** * Used for default selection. * @serial */ XPath m_selectDefault; /** * Create the default rule if needed. * * @throws TransformerException */ private void initDefaultRule(ErrorListener errorListener) throws TransformerException { // Then manufacture a default m_defaultRule = new ElemTemplate(); m_defaultRule.setStylesheet(this); XPath defMatch = new XPath("*", this, this, XPath.MATCH, errorListener); m_defaultRule.setMatch(defMatch); ElemApplyTemplates childrenElement = new ElemApplyTemplates(); childrenElement.setIsDefaultTemplate(true); childrenElement.setSelect(m_selectDefault); m_defaultRule.appendChild(childrenElement); m_startRule = m_defaultRule; // ----------------------------- m_defaultTextRule = new ElemTemplate(); m_defaultTextRule.setStylesheet(this); defMatch = new XPath("text() | @*", this, this, XPath.MATCH, errorListener); m_defaultTextRule.setMatch(defMatch); ElemValueOf elemValueOf = new ElemValueOf(); m_defaultTextRule.appendChild(elemValueOf); XPath selectPattern = new XPath(".", this, this, XPath.SELECT, errorListener); elemValueOf.setSelect(selectPattern); //-------------------------------- m_defaultRootRule = new ElemTemplate(); m_defaultRootRule.setStylesheet(this); defMatch = new XPath("/", this, this, XPath.MATCH, errorListener); m_defaultRootRule.setMatch(defMatch); childrenElement = new ElemApplyTemplates(); childrenElement.setIsDefaultTemplate(true); m_defaultRootRule.appendChild(childrenElement); childrenElement.setSelect(m_selectDefault); } /** * This is a generic version of C.A.R Hoare's Quick Sort * algorithm. This will handle arrays that are already * sorted, and arrays with duplicate keys. It was lifted from * the NodeSorter class but should probably be eliminated and replaced * with a call to Collections.sort when we migrate to Java2.<BR> * * If you think of a one dimensional array as going from * the lowest index on the left to the highest index on the right * then the parameters to this function are lowest index or * left and highest index or right. The first time you call * this function it will be with the parameters 0, a.length - 1. * * @param v a vector of ElemTemplateElement elements * @param lo0 left boundary of partition * @param hi0 right boundary of partition * */ private void QuickSort2(Vector v, int lo0, int hi0) { int lo = lo0; int hi = hi0; if ( hi0 > lo0) { // Arbitrarily establishing partition element as the midpoint of // the array. ElemTemplateElement midNode = (ElemTemplateElement) v.elementAt( ( lo0 + hi0 ) / 2 ); // loop through the array until indices cross while( lo <= hi ) { // find the first element that is greater than or equal to // the partition element starting from the left Index. while( (lo < hi0) && (((ElemTemplateElement) v.elementAt(lo)).compareTo(midNode) < 0) ) { ++lo; } // end while // find an element that is smaller than or equal to // the partition element starting from the right Index. while( (hi > lo0) && (((ElemTemplateElement) v.elementAt(hi)).compareTo(midNode) > 0) ) { --hi; } // if the indexes have not crossed, swap if( lo <= hi ) { ElemTemplateElement node = (ElemTemplateElement) v.elementAt(lo); v.setElementAt(v.elementAt(hi), lo); v.setElementAt(node, hi); ++lo; --hi; } } // If the right index has not reached the left side of array // must now sort the left partition. if( lo0 < hi ) { QuickSort2( v, lo0, hi ); } // If the left index has not reached the right side of array // must now sort the right partition. if( lo < hi0 ) { QuickSort2( v, lo, hi0 ); } } } // end QuickSort2 */ private ComposeState m_composeState; /** * Initialize a new ComposeState. */ void initComposeState() { m_composeState = new ComposeState(); } /** * Return class to track state global state during the compose() operation. * @return ComposeState reference, or null if endCompose has been called. */ ComposeState getComposeState() { return m_composeState; } /** * Clear the compose state. */ private void clearComposeState() { m_composeState = null; } /** * Class to track state global state during the compose() operation. */ class ComposeState { ComposeState() { int size = m_variables.size(); for (int i = 0; i < size; i++) { ElemVariable ev = (ElemVariable)m_variables.elementAt(i); m_variableNames.addElement(ev.getName()); } } private ExpandedNameTable m_ent = new ExpandedNameTable(); /** * Given a qualified name, return an integer ID that can be * quickly compared. * * @param qname a qualified name object, must not be null. * * @return the expanded-name id of the qualified name. */ public int getQNameID(QName qname) { return m_ent.getExpandedTypeID(qname.getNamespace(), qname.getLocalName(), // The type doesn't matter for our // purposes. org.apache.xml.dtm.DTM.ELEMENT_NODE); } /** * A Vector of the current params and QNames within the current template. * Set by ElemTemplate and used by ProcessorVariable. */ private java.util.Vector m_variableNames = new java.util.Vector(); /** * Add the name of a qualified name within the template. The position in * the vector is its ID. * @param qname A qualified name of a param or variable, should be non-null. * @return the index where the variable was added. */ int addVariableName(final org.apache.xml.utils.QName qname) { int pos = m_variableNames.size(); m_variableNames.addElement(qname); int frameSize = m_variableNames.size() - getGlobalsSize(); if(frameSize > m_maxStackFrameSize) m_maxStackFrameSize++; return pos; } void resetStackFrameSize() { m_maxStackFrameSize = 0; } int getFrameSize() { return m_maxStackFrameSize; } /** * Get the current size of the stack frame. Use this to record the position * in a template element at startElement, so that it can be popped * at endElement. */ int getCurrentStackFrameSize() { return m_variableNames.size(); } /** * Set the current size of the stack frame. */ void setCurrentStackFrameSize(int sz) { m_variableNames.setSize(sz); } int getGlobalsSize() { return m_variables.size(); } IntStack m_marks = new IntStack(); void pushStackMark() { m_marks.push(getCurrentStackFrameSize()); } void popStackMark() { int mark = m_marks.pop(); setCurrentStackFrameSize(mark); } /** * Get the Vector of the current params and QNames to be collected * within the current template. * @return A reference to the vector of variable names. The reference * returned is owned by this class, and so should not really be mutated, or * stored anywhere. */ java.util.Vector getVariableNames() { return m_variableNames; } private int m_maxStackFrameSize; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?