Class HTMLDocumentBuilder.SwingEvent2SaxAdapter

java.lang.Object
javax.swing.text.html.HTMLEditorKit.ParserCallback
org.custommonkey.xmlunit.HTMLDocumentBuilder.SwingEvent2SaxAdapter
Enclosing class:
HTMLDocumentBuilder

public class HTMLDocumentBuilder.SwingEvent2SaxAdapter extends HTMLEditorKit.ParserCallback
Adapts Swing HTML callback messages to Sax equivalents, passing them to a Sax-aware ContentHandler.
  • Field Details

    • IGNORE_HTML_CHAR_SET

      private static final boolean IGNORE_HTML_CHAR_SET
      See Also:
    • attributes

      private final AttributesImpl attributes
    • delegator

      private final ParserDelegator delegator
    • lastTagWasSimpleTag

      private boolean lastTagWasSimpleTag
    • saxContentHandler

      private ContentHandler saxContentHandler
    • firstUnhandledException

      private SAXException firstUnhandledException
  • Constructor Details

    • SwingEvent2SaxAdapter

      public SwingEvent2SaxAdapter()
      Default constructor
  • Method Details

    • parse

      public void parse(Reader reader, ContentHandler saxContentHandler) throws SAXException, IOException
      Perform Swing-HTML-parse-event-to-Sax-event conversion
      Parameters:
      reader - reader to read the document from
      saxContentHandler - content handler receiving SAX events while parsing the document
      Throws:
      SAXException - if the parser feels like it
      IOException - on I/O errors
    • preParse

      private void preParse() throws SAXException
      Equivalent to Sax startDocument
      Throws:
      SAXException
    • postParse

      private void postParse() throws SAXException
      Equivalent to Sax endDocument
      Throws:
      SAXException - if any SAXExceptions have occurred during parsing
    • flush

      public void flush() throws BadLocationException
      Swing-HTML-parser template method, no ContentHandler equivalent
      Overrides:
      flush in class HTMLEditorKit.ParserCallback
      Throws:
      BadLocationException
    • handleText

      public void handleText(char[] data, int pos)
      Equivalent to Sax characters
      Overrides:
      handleText in class HTMLEditorKit.ParserCallback
    • getStartIgnoringClosingSimpleTag

      private int getStartIgnoringClosingSimpleTag(char[] data)
      Adjusts the start offset into the character array for the fact that the Swing HTML parser doesn't handle simple tags with explicit closing angle brackets e.g. <hr/>
      Parameters:
      data -
      Returns:
      offset of actual character data into the array
    • handleComment

      public void handleComment(char[] data, int pos)
      Equivalent to Sax LexicalHandler comment method. If the supplied ContentHandler is also an LexicalHandler then the cast will be made and the sax event passed on.
      Overrides:
      handleComment in class HTMLEditorKit.ParserCallback
    • handleStartTag

      public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributeSet, int pos)
      Equivalent to Sax startElement
      Overrides:
      handleStartTag in class HTMLEditorKit.ParserCallback
    • handleEndTag

      public void handleEndTag(HTML.Tag tag, int pos)
      Equivalent to Sax endElement
      Overrides:
      handleEndTag in class HTMLEditorKit.ParserCallback
    • handleSimpleTag

      public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributeSet, int pos)
      Equivalent to Sax startElement plus endElement
      Overrides:
      handleSimpleTag in class HTMLEditorKit.ParserCallback
    • handleError

      public void handleError(String errorMsg, int pos)
      Swing-HTML-parser template method, no ContentHandler equivalent. These errors are generally recoverable, so they are logged.
      Overrides:
      handleError in class HTMLEditorKit.ParserCallback
    • convertToSaxAttributes

      private Attributes convertToSaxAttributes(MutableAttributeSet attributeSet)
      Simple conversion method.
      Parameters:
      attributeSet -
      Returns:
      Sax CDATA Attributes from the Swing MutableAttributeSet
    • handleSAXException

      private void handleSAXException(SAXException e)
      Log an error from the ContentHandler for raising post-parse