Package org.custommonkey.xmlunit
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 javax.swing.text.html.HTMLEditorKit.ParserCallback
Adapts Swing HTML callback messages to Sax equivalents, passing them to a Sax-aware ContentHandler.
-
-
Field Summary
Fields Modifier and Type Field Description private org.xml.sax.helpers.AttributesImpl
attributes
private javax.swing.text.html.parser.ParserDelegator
delegator
private org.xml.sax.SAXException
firstUnhandledException
private static boolean
IGNORE_HTML_CHAR_SET
private boolean
lastTagWasSimpleTag
private org.xml.sax.ContentHandler
saxContentHandler
-
Constructor Summary
Constructors Constructor Description SwingEvent2SaxAdapter()
Default constructor
-
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 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(javax.swing.text.html.HTML.Tag tag, int pos)
Equivalent to SaxendElement
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-parsevoid
handleSimpleTag(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributeSet, int pos)
Equivalent to SaxstartElement
plusendElement
void
handleStartTag(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributeSet, int pos)
Equivalent to SaxstartElement
void
handleText(char[] data, int pos)
Equivalent to Saxcharacters
void
parse(java.io.Reader reader, org.xml.sax.ContentHandler saxContentHandler)
Perform Swing-HTML-parse-event-to-Sax-event conversionprivate void
postParse()
Equivalent to SaxendDocument
private void
preParse()
Equivalent to SaxstartDocument
-
-
-
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
-
-
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 SaxstartDocument
- Throws:
org.xml.sax.SAXException
-
postParse
private void postParse() throws org.xml.sax.SAXException
Equivalent to SaxendDocument
- 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 classjavax.swing.text.html.HTMLEditorKit.ParserCallback
- Throws:
javax.swing.text.BadLocationException
-
handleText
public void handleText(char[] data, int pos)
Equivalent to Saxcharacters
- Overrides:
handleText
in classjavax.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 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 classjavax.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 SaxstartElement
- Overrides:
handleStartTag
in classjavax.swing.text.html.HTMLEditorKit.ParserCallback
-
handleEndTag
public void handleEndTag(javax.swing.text.html.HTML.Tag tag, int pos)
Equivalent to SaxendElement
- Overrides:
handleEndTag
in classjavax.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 SaxstartElement
plusendElement
- Overrides:
handleSimpleTag
in classjavax.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 classjavax.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
-
-