Class HTMLDocumentBuilder.SwingEvent2SaxAdapter

  • Enclosing class:
    HTMLDocumentBuilder

    public class HTMLDocumentBuilder.SwingEvent2SaxAdapter
    extends javax.swing.text.html.HTMLEditorKit.ParserCallback
    Adapts Swing HTML callback messages to Sax equivalents, passing them to a Sax-aware ContentHandler.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private org.xml.sax.Attributes convertToSaxAttributes​(javax.swing.text.MutableAttributeSet attributeSet)
      Simple conversion method.
      void flush()
      Swing-HTML-parser template method, no ContentHandler equivalent
      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.
      void handleComment​(char[] data, int pos)
      Equivalent to Sax LexicalHandler comment method.
      void handleEndTag​(javax.swing.text.html.HTML.Tag tag, int pos)
      Equivalent to Sax endElement
      void handleError​(java.lang.String errorMsg, int pos)
      Swing-HTML-parser template method, no ContentHandler equivalent.
      private void handleSAXException​(org.xml.sax.SAXException e)
      Log an error from the ContentHandler for raising post-parse
      void handleSimpleTag​(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributeSet, int pos)
      Equivalent to Sax startElement plus endElement
      void handleStartTag​(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributeSet, int pos)
      Equivalent to Sax startElement
      void handleText​(char[] data, int pos)
      Equivalent to Sax characters
      void parse​(java.io.Reader reader, org.xml.sax.ContentHandler saxContentHandler)
      Perform Swing-HTML-parse-event-to-Sax-event conversion
      private void postParse()
      Equivalent to Sax endDocument
      private void preParse()
      Equivalent to Sax startDocument
      • Methods inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback

        handleEndOfLineString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • IGNORE_HTML_CHAR_SET

        private static final boolean IGNORE_HTML_CHAR_SET
        See Also:
        Constant Field Values
      • attributes

        private final org.xml.sax.helpers.AttributesImpl attributes
      • delegator

        private final javax.swing.text.html.parser.ParserDelegator delegator
      • lastTagWasSimpleTag

        private boolean lastTagWasSimpleTag
      • saxContentHandler

        private org.xml.sax.ContentHandler saxContentHandler
      • firstUnhandledException

        private org.xml.sax.SAXException firstUnhandledException
    • Constructor Detail

      • SwingEvent2SaxAdapter

        public SwingEvent2SaxAdapter()
        Default constructor
    • Method Detail

      • parse

        public void parse​(java.io.Reader reader,
                          org.xml.sax.ContentHandler saxContentHandler)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
        Perform Swing-HTML-parse-event-to-Sax-event conversion
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • preParse

        private void preParse()
                       throws org.xml.sax.SAXException
        Equivalent to Sax startDocument
        Throws:
        org.xml.sax.SAXException
      • postParse

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

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

        public void handleText​(char[] data,
                               int pos)
        Equivalent to Sax characters
        Overrides:
        handleText in class javax.swing.text.html.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 javax.swing.text.html.HTMLEditorKit.ParserCallback
      • handleStartTag

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

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

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

        public void handleError​(java.lang.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 javax.swing.text.html.HTMLEditorKit.ParserCallback
      • convertToSaxAttributes

        private org.xml.sax.Attributes convertToSaxAttributes​(javax.swing.text.MutableAttributeSet attributeSet)
        Simple conversion method.
        Parameters:
        attributeSet -
        Returns:
        Sax CDATA Attributes from the Swing MutableAttributeSet
      • handleSAXException

        private void handleSAXException​(org.xml.sax.SAXException e)
        Log an error from the ContentHandler for raising post-parse