stylesheethandler.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,722 行 · 第 1/4 页
JAVA
1,722 行
* @return Valid XSLTElementProcessor, which should never be null. */ XSLTElementProcessor getCurrentProcessor() { return (XSLTElementProcessor) m_processors.peek(); } /** * Push the current XSLTElementProcessor onto the top of the stack. * * @param processor non-null reference to the current element processor. */ void pushProcessor(XSLTElementProcessor processor) { m_processors.push(processor); } /** * Pop the current XSLTElementProcessor from the top of the stack. * @return the XSLTElementProcessor which was popped. */ XSLTElementProcessor popProcessor() { return (XSLTElementProcessor) m_processors.pop(); } /** * The root of the XSLT Schema, which tells us how to * transition content handlers, create elements, etc. * For the moment at least, this can't be static, since * the processors store state. */ private XSLTSchema m_schema = new XSLTSchema(); /** * Get the root of the XSLT Schema, which tells us how to * transition content handlers, create elements, etc. * * @return The root XSLT Schema, which should never be null. */ XSLTSchema getSchema() { return m_schema; } /** * The stack of elements, pushed and popped as events occur. */ private Stack m_elems = new Stack(); /** * Get the current ElemTemplateElement at the top of the stack. * @return Valid ElemTemplateElement, which may be null. */ ElemTemplateElement getElemTemplateElement() { try { return (ElemTemplateElement) m_elems.peek(); } catch (java.util.EmptyStackException ese) { return null; } } /** An increasing number that is used to indicate the order in which this element * was encountered during the parse of the XSLT tree. */ private int m_docOrderCount = 0; /** * Returns the next m_docOrderCount number and increments the number for future use. */ int nextUid() { return m_docOrderCount++; } /** * Push the current XSLTElementProcessor to the top of the stack. As a * side-effect, set the document order index (simply because this is a * convenient place to set it). * * @param elem Should be a non-null reference to the intended current * template element. */ void pushElemTemplateElement(ElemTemplateElement elem) { if (elem.getUid() == -1) elem.setUid(nextUid()); m_elems.push(elem); } /** * Get the current XSLTElementProcessor from the top of the stack. * @return the ElemTemplateElement which was popped. */ ElemTemplateElement popElemTemplateElement() { return (ElemTemplateElement) m_elems.pop(); } /** * A XSLMessages instance capable of producing user messages. */ private static XSLMessages m_XSLMessages = new XSLMessages(); /** * Get an XSLMessages instance capable of producing user messages. * * @return non-null reference to the error and warnings table. */ XSLMessages getXSLMessages() { return m_XSLMessages; } /** * This will act as a stack to keep track of the * current include base. */ Stack m_baseIdentifiers = new Stack(); /** * Push a base identifier onto the base URI stack. * * @param baseID The current base identifier for this position in the * stylesheet, which may be a fragment identifier, or which may be null. * @see <a href="http://www.w3.org/TR/xslt#base-uri"> * Section 3.2 Base URI of XSLT specification.</a> */ void pushBaseIndentifier(String baseID) { if (null != baseID) { int posOfHash = baseID.indexOf('#'); if (posOfHash > -1) { m_fragmentIDString = baseID.substring(posOfHash + 1); m_shouldProcess = false; } else m_shouldProcess = true; } else m_shouldProcess = true; m_baseIdentifiers.push(baseID); } /** * Pop a base URI from the stack. * @return baseIdentifier. */ String popBaseIndentifier() { return (String) m_baseIdentifiers.pop(); } /** * Return the base identifier. * * @return The base identifier of the current stylesheet. */ public String getBaseIdentifier() { // Try to get the baseIdentifier from the baseIdentifier's stack, // which may not be the same thing as the value found in the // SourceLocators stack. String base = (String) (m_baseIdentifiers.isEmpty() ? null : m_baseIdentifiers.peek()); // Otherwise try the stylesheet. if (null == base) { SourceLocator locator = getLocator(); base = (null == locator) ? "" : locator.getSystemId(); } return base; } /** * The top of this stack should contain the currently processed * stylesheet SAX locator object. */ private Stack m_stylesheetLocatorStack = new Stack(); /** * Get the current stylesheet Locator object. * * @return non-null reference to the current locator object. */ public SAXSourceLocator getLocator() { if (m_stylesheetLocatorStack.isEmpty()) { SAXSourceLocator locator = new SAXSourceLocator(); locator.setSystemId(this.getStylesheetProcessor().getDOMsystemID()); return locator; // m_stylesheetLocatorStack.push(locator); } return ((SAXSourceLocator) m_stylesheetLocatorStack.peek()); } /** * A stack of URL hrefs for imported stylesheets. This is * used to diagnose circular imports. */ private Stack m_importStack = new Stack(); /** * Push an import href onto the stylesheet stack. * * @param hrefUrl non-null reference to the URL for the current imported * stylesheet. */ void pushImportURL(String hrefUrl) { m_importStack.push(hrefUrl); } /** * See if the imported stylesheet stack already contains * the given URL. Used to test for recursive imports. * * @param hrefUrl non-null reference to a URL string. * * @return true if the URL is on the import stack. */ boolean importStackContains(String hrefUrl) { return stackContains(m_importStack, hrefUrl); } /** * Pop an import href from the stylesheet stack. * * @return non-null reference to the import URL that was popped. */ String popImportURL() { return (String) m_importStack.pop(); } /** * If this is set to true, we've already warned about using the * older XSLT namespace URL. */ private boolean warnedAboutOldXSLTNamespace = false; /** Stack of NamespaceSupport objects. */ Stack m_nsSupportStack = new Stack(); /** * Push a new NamespaceSupport instance. */ void pushNewNamespaceSupport() { m_nsSupportStack.push(new NamespaceSupport2()); } /** * Pop the current NamespaceSupport object. * */ void popNamespaceSupport() { m_nsSupportStack.pop(); } /** * Get the current NamespaceSupport object. * * @return a non-null reference to the current NamespaceSupport object, * which is the top of the namespace support stack. */ NamespaceSupport getNamespaceSupport() { return (NamespaceSupport) m_nsSupportStack.peek(); } /** * The originating node if the current stylesheet is being created * from a DOM. * @see org.apache.xml.utils.NodeConsumer */ private Node m_originatingNode; /** * Set the node that is originating the SAX event. * * @param n Reference to node that originated the current event. * @see org.apache.xml.utils.NodeConsumer */ public void setOriginatingNode(Node n) { m_originatingNode = n; } /** * Set the node that is originating the SAX event. * * @return Reference to node that originated the current event. * @see org.apache.xml.utils.NodeConsumer */ public Node getOriginatingNode() { return m_originatingNode; } /** * Stack of booleans that are pushed and popped in start/endElement depending * on the value of xml:space=default/preserve. */ private BoolStack m_spacePreserveStack = new BoolStack(); /** * Return boolean value from the spacePreserve stack depending on the value * of xml:space=default/preserve. * * @return true if space should be preserved, false otherwise. */ boolean isSpacePreserve() { return m_spacePreserveStack.peek(); } /** * Pop boolean value from the spacePreserve stack. */ void popSpaceHandling() { m_spacePreserveStack.pop(); } /** * Push boolean value on to the spacePreserve stack. * * @param b true if space should be preserved, false otherwise. */ void pushSpaceHandling(boolean b) throws org.xml.sax.SAXParseException { m_spacePreserveStack.push(b); } /** * Push boolean value on to the spacePreserve stack depending on the value * of xml:space=default/preserve. * * @param attrs list of attributes that were passed to startElement. */ void pushSpaceHandling(Attributes attrs) throws org.xml.sax.SAXParseException { String value = attrs.getValue("xml:space"); if(null == value) { m_spacePreserveStack.push(m_spacePreserveStack.peekOrFalse()); } else if(value.equals("preserve")) { m_spacePreserveStack.push(true); } else if(value.equals("default")) { m_spacePreserveStack.push(false); } else { SAXSourceLocator locator = getLocator(); ErrorListener handler = m_stylesheetProcessor.getErrorListener(); try { handler.error(new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_ILLEGAL_XMLSPACE_VALUE, null), locator)); //"Illegal value for xml:space", locator)); } catch (TransformerException te) { throw new org.xml.sax.SAXParseException(te.getMessage(), locator, te); } m_spacePreserveStack.push(m_spacePreserveStack.peek()); } } private double getElemVersion() { ElemTemplateElement elem = getElemTemplateElement(); double version = -1; while ((version == -1 || version == Constants.XSLTVERSUPPORTED) && elem != null) { try{ version = Double.valueOf(elem.getVersion()).doubleValue(); } catch (Exception ex) { version = -1; } elem = elem.getParentElem(); } return (version == -1)? Constants.XSLTVERSUPPORTED : version; } /** * @see PrefixResolver#handlesNullPrefixes() */ public boolean handlesNullPrefixes() { return false; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?