Code example for ContentHandler

Methods: processingInstruction, startDocument

0
        catch(TransformerException te)
        { 
            throw new SAXException(te);
        } 
      } 
      m_resultContentHandler.startDocument();
      m_flushedStartDoc = true;
    } 
  } 
 
  /** 
   * Receive notification of the end of the document. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method in a subclass to take specific actions at the end 
   * of a document (such as finalising a tree or closing an output 
   * file).</p> 
   * 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#endDocument 
   * 
   * @throws SAXException 
   */ 
  public void endDocument() throws SAXException 
  { 
    flushStartDoc(); 
    m_resultContentHandler.endDocument();
  } 
 
  /** 
   * Receive notification of the start of a Namespace mapping. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method in a subclass to take specific actions at the start of 
   * each Namespace prefix scope (such as storing the prefix mapping).</p> 
   * 
   * @param prefix The Namespace prefix being declared. 
   * @param uri The Namespace URI mapped to the prefix. 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#startPrefixMapping 
   * 
   * @throws SAXException 
   */ 
  public void startPrefixMapping(String prefix, String uri)
          throws SAXException 
  { 
    flushStartDoc(); 
    m_resultContentHandler.startPrefixMapping(prefix, uri);
  } 
 
  /** 
   * Receive notification of the end of a Namespace mapping. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method in a subclass to take specific actions at the end of 
   * each prefix mapping.</p> 
   * 
   * @param prefix The Namespace prefix being declared. 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#endPrefixMapping 
   * 
   * @throws SAXException 
   */ 
  public void endPrefixMapping(String prefix) throws SAXException
  { 
    flushStartDoc(); 
    m_resultContentHandler.endPrefixMapping(prefix);
  } 
 
  /** 
   * Receive notification of the start of an element. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method in a subclass to take specific actions at the start of 
   * each element (such as allocating a new tree node or writing 
   * output to a file).</p> 
   * 
   * @param uri The Namespace URI, or the empty string if the 
   *        element has no Namespace URI or if Namespace 
   *        processing is not being performed. 
   * @param localName The local name (without prefix), or the 
   *        empty string if Namespace processing is not being 
   *        performed. 
   * @param qName The qualified name (with prefix), or the 
   *        empty string if qualified names are not available. 
   * @param attributes The specified or defaulted attributes. 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#startElement 
   * 
   * @throws SAXException 
   */ 
  public void startElement( 
          String uri, String localName, String qName, Attributes attributes)
            throws SAXException 
  { 
 
    if (!m_foundFirstElement && null != m_serializer)
    { 
      m_foundFirstElement = true;
 
      Serializer newSerializer;
 
      try 
      { 
        newSerializer = SerializerSwitcher.switchSerializerIfHTML(uri,
                localName, m_outputFormat.getProperties(), m_serializer);
      } 
      catch (TransformerException te)
      { 
        throw new SAXException(te);
      } 
 
      if (newSerializer != m_serializer)
      { 
        try 
        { 
          m_resultContentHandler = newSerializer.asContentHandler();
        } 
        catch (IOException ioe)  // why?
        { 
          throw new SAXException(ioe);
        } 
 
        if (m_resultContentHandler instanceof DTDHandler)
          m_resultDTDHandler = (DTDHandler) m_resultContentHandler;
 
        if (m_resultContentHandler instanceof LexicalHandler)
          m_resultLexicalHandler = (LexicalHandler) m_resultContentHandler;
 
        m_serializer = newSerializer;
      } 
    } 
    flushStartDoc(); 
    m_resultContentHandler.startElement(uri, localName, qName, attributes);
  } 
 
  /** 
   * Receive notification of the end of an element. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method in a subclass to take specific actions at the end of 
   * each element (such as finalising a tree node or writing 
   * output to a file).</p> 
   * 
   * @param uri The Namespace URI, or the empty string if the 
   *        element has no Namespace URI or if Namespace 
   *        processing is not being performed. 
   * @param localName The local name (without prefix), or the 
   *        empty string if Namespace processing is not being 
   *        performed. 
   * @param qName The qualified name (with prefix), or the 
   *        empty string if qualified names are not available. 
   * 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#endElement 
   * 
   * @throws SAXException 
   */ 
  public void endElement(String uri, String localName, String qName)
          throws SAXException 
  { 
    m_resultContentHandler.endElement(uri, localName, qName);
  } 
 
  /** 
   * Receive notification of character data inside an element. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method to take specific actions for each chunk of character data 
   * (such as adding the data to a node or buffer, or printing it to 
   * a file).</p> 
   * 
   * @param ch The characters. 
   * @param start The start position in the character array. 
   * @param length The number of characters to use from the 
   *               character array. 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#characters 
   * 
   * @throws SAXException 
   */ 
  public void characters(char ch[], int start, int length) throws SAXException
  { 
    flushStartDoc(); 
    m_resultContentHandler.characters(ch, start, length);
  } 
 
  /** 
   * Receive notification of ignorable whitespace in element content. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method to take specific actions for each chunk of ignorable 
   * whitespace (such as adding data to a node or buffer, or printing 
   * it to a file).</p> 
   * 
   * @param ch The whitespace characters. 
   * @param start The start position in the character array. 
   * @param length The number of characters to use from the 
   *               character array. 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#ignorableWhitespace 
   * 
   * @throws SAXException 
   */ 
  public void ignorableWhitespace(char ch[], int start, int length)
          throws SAXException 
  { 
    m_resultContentHandler.ignorableWhitespace(ch, start, length);
  } 
 
  /** 
   * Receive notification of a processing instruction. 
   * 
   * <p>By default, do nothing.  Application writers may override this 
   * method in a subclass to take specific actions for each 
   * processing instruction, such as setting status variables or 
   * invoking other methods.</p> 
   * 
   * @param target The processing instruction target. 
   * @param data The processing instruction data, or null if 
   *             none is supplied. 
   * @throws org.xml.sax.SAXException Any SAX exception, possibly 
   *            wrapping another exception. 
   * @see org.xml.sax.ContentHandler#processingInstruction 
   * 
   * @throws SAXException 
   */ 
  public void processingInstruction(String target, String data)
          throws SAXException 
  { 
    flushStartDoc(); 
    m_resultContentHandler.processingInstruction(target, data);
  } 
 
  /** 
   * Receive notification of a skipped entity. 
   *