transformerhandlerimpl.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,106 行 · 第 1/3 页

JAVA
1,106
字号
    }    // 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).fatalError(e);      if(null != m_errorHandler)        m_errorHandler.fatalError(e); // may not be called.    }    else    {      try      {        errorListener.fatalError(new javax.xml.transform.TransformerException(e));        if(null != m_errorHandler)          m_errorHandler.fatalError(e); // may not be called.      }      catch(javax.xml.transform.TransformerException te)      {        throw e;      }    }  }  ////////////////////////////////////////////////////////////////////  // Implementation of org.xml.sax.ext.LexicalHandler.  ////////////////////////////////////////////////////////////////////  /**   * Report the start of DTD declarations, if any.   *   * <p>Any declarations are assumed to be in the internal subset   * unless otherwise indicated by a {@link #startEntity startEntity}   * event.</p>   *   * <p>Note that the start/endDTD events will appear within   * the start/endDocument events from ContentHandler and   * before the first startElement event.</p>   *   * @param name The document type name.   * @param publicId The declared public identifier for the   *        external DTD subset, or null if none was declared.   * @param systemId The declared system identifier for the   *        external DTD subset, or null if none was declared.   * @throws SAXException The application may raise an   *            exception.   * @see #endDTD   * @see #startEntity   */  public void startDTD(String name, String publicId, String systemId)          throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#startDTD: " + name + ", "                         + publicId + ", " + systemId);    if (null != m_lexicalHandler)    {      m_lexicalHandler.startDTD(name, publicId, systemId);    }  }  /**   * Report the end of DTD declarations.   *   * @throws SAXException The application may raise an exception.   * @see #startDTD   */  public void endDTD() throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#endDTD");    if (null != m_lexicalHandler)    {      m_lexicalHandler.endDTD();    }  }  /**   * Report the beginning of an entity in content.   *   * <p><strong>NOTE:</entity> entity references in attribute   * values -- and the start and end of the document entity --   * are never reported.</p>   *   * <p>The start and end of the external DTD subset are reported   * using the pseudo-name "[dtd]".  All other events must be   * properly nested within start/end entity events.</p>   *   * <p>Note that skipped entities will be reported through the   * {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity}   * event, which is part of the ContentHandler interface.</p>   *   * @param name The name of the entity.  If it is a parameter   *        entity, the name will begin with '%'.   * @throws SAXException The application may raise an exception.   * @see #endEntity   * @see org.xml.sax.ext.DeclHandler#internalEntityDecl   * @see org.xml.sax.ext.DeclHandler#externalEntityDecl   */  public void startEntity(String name) throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#startEntity: " + name);    if (null != m_lexicalHandler)    {      m_lexicalHandler.startEntity(name);    }  }  /**   * Report the end of an entity.   *   * @param name The name of the entity that is ending.   * @throws SAXException The application may raise an exception.   * @see #startEntity   */  public void endEntity(String name) throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#endEntity: " + name);    if (null != m_lexicalHandler)    {      m_lexicalHandler.endEntity(name);    }  }  /**   * Report the start of a CDATA section.   *   * <p>The contents of the CDATA section will be reported through   * the regular {@link org.xml.sax.ContentHandler#characters   * characters} event.</p>   *   * @throws SAXException The application may raise an exception.   * @see #endCDATA   */  public void startCDATA() throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#startCDATA");    if (null != m_lexicalHandler)    {      m_lexicalHandler.startCDATA();    }  }  /**   * Report the end of a CDATA section.   *   * @throws SAXException The application may raise an exception.   * @see #startCDATA   */  public void endCDATA() throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#endCDATA");    if (null != m_lexicalHandler)    {      m_lexicalHandler.endCDATA();    }  }  /**   * Report an XML comment anywhere in the document.   *   * <p>This callback will be used for comments inside or outside the   * document element, including comments in the external DTD   * subset (if read).</p>   *   * @param ch An array holding the characters in the comment.   * @param start The starting position in the array.   * @param length The number of characters to use from the array.   * @throws SAXException The application may raise an exception.   */  public void comment(char ch[], int start, int length) throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#comment: " + start + ", "                         + length);    if (null != m_lexicalHandler)    {      m_lexicalHandler.comment(ch, start, length);    }  }  ////////////////////////////////////////////////////////////////////  // Implementation of org.xml.sax.ext.DeclHandler.  ////////////////////////////////////////////////////////////////////  /**   * Report an element type declaration.   *   * <p>The content model will consist of the string "EMPTY", the   * string "ANY", or a parenthesised group, optionally followed   * by an occurrence indicator.  The model will be normalized so   * that all whitespace is removed,and will include the enclosing   * parentheses.</p>   *   * @param name The element type name.   * @param model The content model as a normalized string.   * @throws SAXException The application may raise an exception.   */  public void elementDecl(String name, String model) throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#elementDecl: " + name + ", "                         + model);    if (null != m_declHandler)    {      m_declHandler.elementDecl(name, model);    }  }  /**   * Report an attribute type declaration.   *   * <p>Only the effective (first) declaration for an attribute will   * be reported.  The type will be one of the strings "CDATA",   * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",   * "ENTITIES", or "NOTATION", or a parenthesized token group with   * the separator "|" and all whitespace removed.</p>   *   * @param eName The name of the associated element.   * @param aName The name of the attribute.   * @param type A string representing the attribute type.   * @param valueDefault A string representing the attribute default   *        ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if   *        none of these applies.   * @param value A string representing the attribute's default value,   *        or null if there is none.   * @throws SAXException The application may raise an exception.   */  public void attributeDecl(          String eName, String aName, String type, String valueDefault, String value)            throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#attributeDecl: " + eName                         + ", " + aName + ", etc...");    if (null != m_declHandler)    {      m_declHandler.attributeDecl(eName, aName, type, valueDefault, value);    }  }  /**   * Report an internal entity declaration.   *   * <p>Only the effective (first) declaration for each entity   * will be reported.</p>   *   * @param name The name of the entity.  If it is a parameter   *        entity, the name will begin with '%'.   * @param value The replacement text of the entity.   * @throws SAXException The application may raise an exception.   * @see #externalEntityDecl   * @see org.xml.sax.DTDHandler#unparsedEntityDecl   */  public void internalEntityDecl(String name, String value)          throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#internalEntityDecl: " + name                         + ", " + value);    if (null != m_declHandler)    {      m_declHandler.internalEntityDecl(name, value);    }  }  /**   * Report a parsed external entity declaration.   *   * <p>Only the effective (first) declaration for each entity   * will be reported.</p>   *   * @param name The name of the entity.  If it is a parameter   *        entity, the name will begin with '%'.   * @param publicId The declared public identifier of the entity, or   *        null if none was declared.   * @param systemId The declared system identifier of the entity.   * @throws SAXException The application may raise an exception.   * @see #internalEntityDecl   * @see org.xml.sax.DTDHandler#unparsedEntityDecl   */  public void externalEntityDecl(          String name, String publicId, String systemId) throws SAXException  {    if (DEBUG)      System.out.println("TransformerHandlerImpl#externalEntityDecl: " + name                         + ", " + publicId + ", " + systemId);    if (null != m_declHandler)    {      m_declHandler.externalEntityDecl(name, publicId, systemId);    }  }  ////////////////////////////////////////////////////////////////////  // Internal state.  ////////////////////////////////////////////////////////////////////  /** Set to true for diagnostics output.         */  private static boolean DEBUG = false;  /**   * The transformer this will use to transform a   * source tree into a result tree.   */  private TransformerImpl m_transformer;  /** The system ID to use as a base for relative URLs. */  private String m_baseSystemID;  /** The result for the transformation. */  private Result m_result = null;  /** The locator for this TransformerHandler. */  private Locator m_locator = null;  /** The entity resolver to aggregate to. */  private EntityResolver m_entityResolver = null;  /** The DTD handler to aggregate to. */  private DTDHandler m_dtdHandler = null;  /** The content handler to aggregate to. */  private ContentHandler m_contentHandler = null;  /** The error handler to aggregate to. */  private ErrorHandler m_errorHandler = null;  /** The lexical handler to aggregate to. */  private LexicalHandler m_lexicalHandler = null;  /** The decl handler to aggregate to. */  private DeclHandler m_declHandler = null;    /** The Document Table Instance we are transforming. */  DTM m_dtm;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?