transformerhandlerimpl.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,106 行 · 第 1/3 页
JAVA
1,106 行
public void startDocument() throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#startDocument"); m_insideParse = true; // Thread listener = new Thread(m_transformer); if (m_contentHandler != null) { //m_transformer.setTransformThread(listener); if(DTMManager.getIncremental()) { m_transformer.setSourceTreeDocForThread(m_dtm.getDocument()); int cpriority = Thread.currentThread().getPriority(); // runTransformThread is equivalent with the 2.0.1 code, // except that the Thread may come from a pool. m_transformer.runTransformThread( cpriority ); } // This is now done _last_, because IncrementalSAXSource_Filter // will immediately go into a "wait until events are requested" // pause. I believe that will close our timing window. // %REVIEW% m_contentHandler.startDocument(); } //listener.setDaemon(false); //listener.start(); } /** * Filter an end document event. * * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#endDocument */ public void endDocument() throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#endDocument"); m_insideParse = false; if (m_contentHandler != null) { m_contentHandler.endDocument(); } if(DTMManager.getIncremental()) { m_transformer.waitTransformThread(); } else { m_transformer.setSourceTreeDocForThread(m_dtm.getDocument()); m_transformer.run(); } /* Thread transformThread = m_transformer.getTransformThread(); if (null != transformThread) { try { // This should wait until the transformThread is considered not alive. transformThread.join(); if (!m_transformer.hasTransformThreadErrorCatcher()) { Exception e = m_transformer.getExceptionThrown(); if (null != e) throw new org.xml.sax.SAXException(e); } m_transformer.setTransformThread(null); } catch (InterruptedException ie){} }*/ } /** * Filter a start Namespace prefix mapping event. * * @param prefix The Namespace prefix. * @param uri The Namespace URI. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#startPrefixMapping */ public void startPrefixMapping(String prefix, String uri) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#startPrefixMapping: " + prefix + ", " + uri); if (m_contentHandler != null) { m_contentHandler.startPrefixMapping(prefix, uri); } } /** * Filter an end Namespace prefix mapping event. * * @param prefix The Namespace prefix. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#endPrefixMapping */ public void endPrefixMapping(String prefix) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#endPrefixMapping: " + prefix); if (m_contentHandler != null) { m_contentHandler.endPrefixMapping(prefix); } } /** * Filter a start element event. * * @param uri The element's Namespace URI, or the empty string. * @param localName The element's local name, or the empty string. * @param qName The element's qualified (prefixed) name, or the empty * string. * @param atts The element's attributes. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#startElement */ public void startElement( String uri, String localName, String qName, Attributes atts) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#startElement: " + qName); if (m_contentHandler != null) { m_contentHandler.startElement(uri, localName, qName, atts); } } /** * Filter an end element event. * * @param uri The element's Namespace URI, or the empty string. * @param localName The element's local name, or the empty string. * @param qName The element's qualified (prefixed) name, or the empty * string. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#endElement */ public void endElement(String uri, String localName, String qName) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#endElement: " + qName); if (m_contentHandler != null) { m_contentHandler.endElement(uri, localName, qName); } } /** * Filter a character data event. * * @param ch An array of characters. * @param start The starting position in the array. * @param length The number of characters to use from the array. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#characters */ public void characters(char ch[], int start, int length) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#characters: " + start + ", " + length); if (m_contentHandler != null) { m_contentHandler.characters(ch, start, length); } } /** * Filter an ignorable whitespace event. * * @param ch An array of characters. * @param start The starting position in the array. * @param length The number of characters to use from the array. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#ignorableWhitespace */ public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#ignorableWhitespace: " + start + ", " + length); if (m_contentHandler != null) { m_contentHandler.ignorableWhitespace(ch, start, length); } } /** * Filter a processing instruction event. * * @param target The processing instruction target. * @param data The text following the target. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#processingInstruction */ public void processingInstruction(String target, String data) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#processingInstruction: " + target + ", " + data); if (m_contentHandler != null) { m_contentHandler.processingInstruction(target, data); } } /** * Filter a skipped entity event. * * @param name The name of the skipped entity. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ContentHandler#skippedEntity */ public void skippedEntity(String name) throws SAXException { if (DEBUG) System.out.println("TransformerHandlerImpl#skippedEntity: " + name); if (m_contentHandler != null) { m_contentHandler.skippedEntity(name); } } //////////////////////////////////////////////////////////////////// // Implementation of org.xml.sax.ErrorHandler. //////////////////////////////////////////////////////////////////// /** * Filter a warning event. * * @param e The nwarning as an exception. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ErrorHandler#warning */ public void warning(SAXParseException e) throws SAXException { // This is not great, but we really would rather have the error // handler be the error listener if it is a error handler. Coroutine's fatalError // can't really be configured, so I think this is the best thing right now // for error reporting. Possibly another JAXP 1.1 hole. -sb javax.xml.transform.ErrorListener errorListener = m_transformer.getErrorListener(); if(errorListener instanceof ErrorHandler) { ((ErrorHandler)errorListener).warning(e); } else { try { errorListener.warning(new javax.xml.transform.TransformerException(e)); } catch(javax.xml.transform.TransformerException te) { throw e; } } } /** * Filter an error event. * * @param e The error as an exception. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ErrorHandler#error */ public void error(SAXParseException e) throws SAXException { // %REVIEW% I don't think this should be called. -sb // clearCoRoutine(e); // This is not great, but we really would rather have the error // handler be the error listener if it is a error handler. Coroutine's fatalError // can't really be configured, so I think this is the best thing right now // for error reporting. Possibly another JAXP 1.1 hole. -sb javax.xml.transform.ErrorListener errorListener = m_transformer.getErrorListener(); if(errorListener instanceof ErrorHandler) { ((ErrorHandler)errorListener).error(e); if(null != m_errorHandler) m_errorHandler.error(e); // may not be called. } else { try { errorListener.error(new javax.xml.transform.TransformerException(e)); if(null != m_errorHandler) m_errorHandler.error(e); // may not be called. } catch(javax.xml.transform.TransformerException te) { throw e; } } } /** * Filter a fatal error event. * * @param e The error as an exception. * @throws SAXException The client may throw * an exception during processing. * @see org.xml.sax.ErrorHandler#fatalError */ public void fatalError(SAXParseException e) throws SAXException { if(null != m_errorHandler) { try { m_errorHandler.fatalError(e); } catch(SAXParseException se) { // ignore } // clearCoRoutine(e);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?