stylesheethandler.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,722 行 · 第 1/4 页
JAVA
1,722 行
* method in a subclass to take specific actions for each * processing instruction, such as setting status variables or * invoking other methods.</p> * * @param name The name of the skipped entity. * @see org.xml.sax.ContentHandler#processingInstruction * * @throws org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. */ public void skippedEntity(String name) throws org.xml.sax.SAXException { if (!m_shouldProcess) return; getCurrentProcessor().skippedEntity(this, name); } /** * <meta name="usage" content="internal"/> * Warn the user of an problem. * * @param msg An key into the {@link org.apache.xalan.res.XSLTErrorResources} * table, that is one of the WG_ prefixed definitions. * @param args An array of arguments for the given warning. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the current * {@link javax.xml.transform.ErrorListener#warning} * method chooses to flag this condition as an error. */ public void warn(String msg, Object args[]) throws org.xml.sax.SAXException { String formattedMsg = m_XSLMessages.createWarning(msg, args); SAXSourceLocator locator = getLocator(); ErrorListener handler = m_stylesheetProcessor.getErrorListener(); try { if (null != handler) handler.warning(new TransformerException(formattedMsg, locator)); } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } /** * <meta name="usage" content="internal"/> * Assert that a condition is true. If it is not true, throw an error. * * @param condition false if an error should not be thrown, otherwise true. * @param msg Error message to be passed to the RuntimeException as an * argument. * @throws RuntimeException if the condition is not true. */ private void assertion(boolean condition, String msg) throws RuntimeException { if (!condition) throw new RuntimeException(msg); } /** * <meta name="usage" content="internal"/> * Tell the user of an error, and probably throw an * exception. * * @param msg An error message. * @param e An error which the SAXException should wrap. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the current * {@link javax.xml.transform.ErrorListener#error} * method chooses to flag this condition as an error. */ protected void error(String msg, Exception e) throws org.xml.sax.SAXException { SAXSourceLocator locator = getLocator(); ErrorListener handler = m_stylesheetProcessor.getErrorListener(); TransformerException pe; if (!(e instanceof TransformerException)) { pe = (null == e) ? new TransformerException(msg, locator) : new TransformerException(msg, locator, e); } else pe = (TransformerException) e; if (null != handler) { try { handler.error(pe); } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } else throw new org.xml.sax.SAXException(pe); } /** * <meta name="usage" content="internal"/> * Tell the user of an error, and probably throw an * exception. * * @param msg A key into the {@link org.apache.xalan.res.XSLTErrorResources} * table, that is one of the WG_ prefixed definitions. * @param args An array of arguments for the given warning. * @param e An error which the SAXException should wrap. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the current * {@link javax.xml.transform.ErrorListener#error} * method chooses to flag this condition as an error. */ protected void error(String msg, Object args[], Exception e) throws org.xml.sax.SAXException { String formattedMsg = m_XSLMessages.createMessage(msg, args); error(formattedMsg, e); } /** * Receive notification of a XSLT processing warning. * * @param e The warning information encoded as an exception. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the current * {@link javax.xml.transform.ErrorListener#warning} * method chooses to flag this condition as an error. */ public void warning(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException { String formattedMsg = e.getMessage(); SAXSourceLocator locator = getLocator(); ErrorListener handler = m_stylesheetProcessor.getErrorListener(); try { handler.warning(new TransformerException(formattedMsg, locator)); } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } /** * Receive notification of a recoverable XSLT processing error. * * @param e The error information encoded as an exception. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the current * {@link javax.xml.transform.ErrorListener#error} * method chooses to flag this condition as an error. */ public void error(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException { String formattedMsg = e.getMessage(); SAXSourceLocator locator = getLocator(); ErrorListener handler = m_stylesheetProcessor.getErrorListener(); try { handler.error(new TransformerException(formattedMsg, locator)); } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } /** * Report a fatal XSLT processing error. * * @param e The error information encoded as an exception. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the current * {@link javax.xml.transform.ErrorListener#fatalError} * method chooses to flag this condition as an error. */ public void fatalError(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException { String formattedMsg = e.getMessage(); SAXSourceLocator locator = getLocator(); ErrorListener handler = m_stylesheetProcessor.getErrorListener(); try { handler.fatalError(new TransformerException(formattedMsg, locator)); } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } /** * If we have a URL to a XML fragment, this is set * to false until the ID is found. * (warning: I worry that this should be in a stack). */ private boolean m_shouldProcess = true; /** * If we have a URL to a XML fragment, the value is stored * in this string, and the m_shouldProcess flag is set to * false until we match an ID with this string. * (warning: I worry that this should be in a stack). */ private String m_fragmentIDString; /** * Keep track of the elementID, so we can tell when * is has completed. This isn't a real ID, but rather * a nesting level. However, it's good enough for * our purposes. * (warning: I worry that this should be in a stack). */ private int m_elementID = 0; /** * The ID of the fragment that has been found * (warning: I worry that this should be in a stack). */ private int m_fragmentID = 0; /** * Check to see if an ID attribute matched the #id, called * from startElement. * * @param attributes The specified or defaulted attributes. */ private void checkForFragmentID(Attributes attributes) { if (!m_shouldProcess) { if ((null != attributes) && (null != m_fragmentIDString)) { int n = attributes.getLength(); for (int i = 0; i < n; i++) { String name = attributes.getQName(i); if (name.equals(Constants.ATTRNAME_ID)) { String val = attributes.getValue(i); if (val.equalsIgnoreCase(m_fragmentIDString)) { m_shouldProcess = true; m_fragmentID = m_elementID; } } } } } } /** * The XSLT TransformerFactory for needed services. */ private TransformerFactoryImpl m_stylesheetProcessor; /** * Get the XSLT TransformerFactoryImpl for needed services. * TODO: This method should be renamed. * * @return The TransformerFactoryImpl that owns this handler. */ TransformerFactoryImpl getStylesheetProcessor() { return m_stylesheetProcessor; } /** * If {@link #getStylesheetType} returns this value, the current stylesheet * is a root stylesheet. */ static final int STYPE_ROOT = 1; /** * If {@link #getStylesheetType} returns this value, the current stylesheet * is an included stylesheet. */ static final int STYPE_INCLUDE = 2; /** * If {@link #getStylesheetType} returns this value, the current stylesheet * is an imported stylesheet. */ static final int STYPE_IMPORT = 3; /** The current stylesheet type. */ private int m_stylesheetType = STYPE_ROOT; /** * Get the type of stylesheet that should be built * or is being processed. * * @return one of STYPE_ROOT, STYPE_INCLUDE, or STYPE_IMPORT. */ int getStylesheetType() { return m_stylesheetType; } /** * Set the type of stylesheet that should be built * or is being processed. * * @param type Must be one of STYPE_ROOT, STYPE_INCLUDE, or STYPE_IMPORT. */ void setStylesheetType(int type) { m_stylesheetType = type; } /** * The stack of stylesheets being processed. */ private Stack m_stylesheets = new Stack(); /** * Return the stylesheet that this handler is constructing. * * @return The current stylesheet that is on top of the stylesheets stack, * or null if no stylesheet is on the stylesheets stack. */ Stylesheet getStylesheet() { return (m_stylesheets.size() == 0) ? null : (Stylesheet) m_stylesheets.peek(); } /** * Return the last stylesheet that was popped off the stylesheets stack. * * @return The last popped stylesheet, or null. */ Stylesheet getLastPoppedStylesheet() { return m_lastPoppedStylesheet; } /** * Return the stylesheet root that this handler is constructing. * * @return The root stylesheet of the stylesheets tree. */ public StylesheetRoot getStylesheetRoot() { return m_stylesheetRoot; } /** The root stylesheet of the stylesheets tree. */ StylesheetRoot m_stylesheetRoot; /** The last stylesheet that was popped off the stylesheets stack. */ Stylesheet m_lastPoppedStylesheet; /** * Push the current stylesheet being constructed. If no other stylesheets * have been pushed onto the stack, assume the argument is a stylesheet * root, and also set the stylesheet root member. * * @param s non-null reference to a stylesheet. */ public void pushStylesheet(Stylesheet s) { if (m_stylesheets.size() == 0) m_stylesheetRoot = (StylesheetRoot) s; m_stylesheets.push(s); } /** * Pop the last stylesheet pushed, and return the stylesheet that this * handler is constructing, and set the last popped stylesheet member. * Also pop the stylesheet locator stack. * * @return The stylesheet popped off the stack, or the last popped stylesheet. */ Stylesheet popStylesheet() { // The stylesheetLocatorStack needs to be popped because // a locator was pushed in for this stylesheet by the SAXparser by calling // setDocumentLocator(). if (!m_stylesheetLocatorStack.isEmpty()) m_stylesheetLocatorStack.pop(); if (!m_stylesheets.isEmpty()) m_lastPoppedStylesheet = (Stylesheet) m_stylesheets.pop(); // Shouldn't this be null if stylesheets is empty? -sb return m_lastPoppedStylesheet; } /** * The stack of current processors. */ private Stack m_processors = new Stack(); /** * Get the current XSLTElementProcessor at the top of the stack. *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?