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.ParserCallbackAdapts 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.AttributesImplattributesprivate javax.swing.text.html.parser.ParserDelegatordelegatorprivate org.xml.sax.SAXExceptionfirstUnhandledExceptionprivate static booleanIGNORE_HTML_CHAR_SETprivate booleanlastTagWasSimpleTagprivate org.xml.sax.ContentHandlersaxContentHandler
-
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.AttributesconvertToSaxAttributes(javax.swing.text.MutableAttributeSet attributeSet)Simple conversion method.voidflush()Swing-HTML-parser template method, no ContentHandler equivalentprivate intgetStartIgnoringClosingSimpleTag(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.voidhandleComment(char[] data, int pos)Equivalent to Sax LexicalHandlercommentmethod.voidhandleEndTag(javax.swing.text.html.HTML.Tag tag, int pos)Equivalent to SaxendElementvoidhandleError(java.lang.String errorMsg, int pos)Swing-HTML-parser template method, no ContentHandler equivalent.private voidhandleSAXException(org.xml.sax.SAXException e)Log an error from the ContentHandler for raising post-parsevoidhandleSimpleTag(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributeSet, int pos)Equivalent to SaxstartElementplusendElementvoidhandleStartTag(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributeSet, int pos)Equivalent to SaxstartElementvoidhandleText(char[] data, int pos)Equivalent to Saxcharactersvoidparse(java.io.Reader reader, org.xml.sax.ContentHandler saxContentHandler)Perform Swing-HTML-parse-event-to-Sax-event conversionprivate voidpostParse()Equivalent to SaxendDocumentprivate voidpreParse()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.IOExceptionPerform Swing-HTML-parse-event-to-Sax-event conversion- Throws:
org.xml.sax.SAXExceptionjava.io.IOException
-
preParse
private void preParse() throws org.xml.sax.SAXExceptionEquivalent to SaxstartDocument- Throws:
org.xml.sax.SAXException
-
postParse
private void postParse() throws org.xml.sax.SAXExceptionEquivalent to SaxendDocument- Throws:
org.xml.sax.SAXException- if any SAXExceptions have occurred during parsing
-
flush
public void flush() throws javax.swing.text.BadLocationExceptionSwing-HTML-parser template method, no ContentHandler equivalent- Overrides:
flushin classjavax.swing.text.html.HTMLEditorKit.ParserCallback- Throws:
javax.swing.text.BadLocationException
-
handleText
public void handleText(char[] data, int pos)Equivalent to Saxcharacters- Overrides:
handleTextin 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 LexicalHandlercommentmethod. If the supplied ContentHandler is also an LexicalHandler then the cast will be made and the sax event passed on.- Overrides:
handleCommentin 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:
handleStartTagin classjavax.swing.text.html.HTMLEditorKit.ParserCallback
-
handleEndTag
public void handleEndTag(javax.swing.text.html.HTML.Tag tag, int pos)Equivalent to SaxendElement- Overrides:
handleEndTagin 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 SaxstartElementplusendElement- Overrides:
handleSimpleTagin 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:
handleErrorin 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
-
-