Package org.custommonkey.xmlunit
Class HTMLDocumentBuilder.SwingEvent2SaxAdapter
java.lang.Object
javax.swing.text.html.HTMLEditorKit.ParserCallback
org.custommonkey.xmlunit.HTMLDocumentBuilder.SwingEvent2SaxAdapter
- Enclosing class:
HTMLDocumentBuilder
Adapts Swing HTML callback messages to Sax equivalents, passing them
to a Sax-aware ContentHandler.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AttributesImpl
private final ParserDelegator
private SAXException
private static final boolean
private boolean
private ContentHandler
Fields inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback
IMPLIED
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Attributes
convertToSaxAttributes
(MutableAttributeSet attributeSet) Simple conversion method.void
flush()
Swing-HTML-parser template method, no ContentHandler equivalentprivate 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 LexicalHandlercomment
method.void
handleEndTag
(HTML.Tag tag, int pos) Equivalent to SaxendElement
void
handleError
(String errorMsg, int pos) Swing-HTML-parser template method, no ContentHandler equivalent.private void
Log an error from the ContentHandler for raising post-parsevoid
handleSimpleTag
(HTML.Tag tag, MutableAttributeSet attributeSet, int pos) Equivalent to SaxstartElement
plusendElement
void
handleStartTag
(HTML.Tag tag, MutableAttributeSet attributeSet, int pos) Equivalent to SaxstartElement
void
handleText
(char[] data, int pos) Equivalent to Saxcharacters
void
parse
(Reader reader, ContentHandler saxContentHandler) Perform Swing-HTML-parse-event-to-Sax-event conversionprivate void
Equivalent to SaxendDocument
private void
preParse()
Equivalent to SaxstartDocument
Methods inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback
handleEndOfLineString
-
Field Details
-
IGNORE_HTML_CHAR_SET
private static final boolean IGNORE_HTML_CHAR_SET- See Also:
-
attributes
-
delegator
-
lastTagWasSimpleTag
private boolean lastTagWasSimpleTag -
saxContentHandler
-
firstUnhandledException
-
-
Constructor Details
-
SwingEvent2SaxAdapter
public SwingEvent2SaxAdapter()Default constructor
-
-
Method Details
-
parse
Perform Swing-HTML-parse-event-to-Sax-event conversion- Parameters:
reader
- reader to read the document fromsaxContentHandler
- content handler receiving SAX events while parsing the document- Throws:
SAXException
- if the parser feels like itIOException
- on I/O errors
-
preParse
Equivalent to SaxstartDocument
- Throws:
SAXException
-
postParse
Equivalent to SaxendDocument
- Throws:
SAXException
- if any SAXExceptions have occurred during parsing
-
flush
Swing-HTML-parser template method, no ContentHandler equivalent- Overrides:
flush
in classHTMLEditorKit.ParserCallback
- Throws:
BadLocationException
-
handleText
public void handleText(char[] data, int pos) Equivalent to Saxcharacters
- Overrides:
handleText
in classHTMLEditorKit.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 LexicalHandlercomment
method. If the supplied ContentHandler is also an LexicalHandler then the cast will be made and the sax event passed on.- Overrides:
handleComment
in classHTMLEditorKit.ParserCallback
-
handleStartTag
Equivalent to SaxstartElement
- Overrides:
handleStartTag
in classHTMLEditorKit.ParserCallback
-
handleEndTag
Equivalent to SaxendElement
- Overrides:
handleEndTag
in classHTMLEditorKit.ParserCallback
-
handleSimpleTag
Equivalent to SaxstartElement
plusendElement
- Overrides:
handleSimpleTag
in classHTMLEditorKit.ParserCallback
-
handleError
Swing-HTML-parser template method, no ContentHandler equivalent. These errors are generally recoverable, so they are logged.- Overrides:
handleError
in classHTMLEditorKit.ParserCallback
-
convertToSaxAttributes
Simple conversion method.- Parameters:
attributeSet
-- Returns:
- Sax CDATA Attributes from the Swing MutableAttributeSet
-
handleSAXException
Log an error from the ContentHandler for raising post-parse
-