- Using HTMLEditorKit.Parser
- Using HTMLEditorKit.<br />ParserCallback
- Using HTML.Tag
- Using HTML.Attribute
- Conclusions
Using HTMLEditorKit.ParserCallback
You can use the ParserCallback class to create your own custom parser. Creating your own subclass of the ParserCallback class is how you implement your own handling of the file being processed. By overriding the handleComment, handleEndTag, handleError, handleSimpleTag, handleStartTag, and handleText methods, you can handle each of these types of information from your callback object. Each of these handler methods is described in detail now.
Method: handleComment
public void handleComment(char[] data,int pos)
Called by the parser when a HTML comment is located. The text of the comment is contained in data. The parameter pos gives the current position.
Method: handleEndTag
public void handleEndTag(HTML.Tag t,int pos)
Called by the parser when an ending HTML tag is located. The tag is contained in the parameter t. The parameter pos gives the current position.
Method: handleError
public void handleError(String errorMsg,int pos)
Called by the parser when an error occurs. The error message text is contained in errorMsg. The parameter pos gives the current position.
Method: handleSimpleTag
public void handleSimpleTag(HTML.Tag t,MutableAttributeSet a,int pos)
Called by the parser when a simple tag is located. The tag is contained in t; the list of attributes is contained in a. The parameter pos gives the current position.
Simple tags are sometimes ending tags. If the parser encounters an ending tag for a tag type that it considers either simple or unknown, handleSimpleTag will be called for the ending tag. The only way to detect whether this is an ending tag or a true simple tag is to check for the occurrence of the HTML.Attribute.ENDTAG attribute. Only ending tags contain this attribute.
Method: handleStartTag
public void handleStartTag(HTML.Tag t,MutableAttributeSet a,int pos)
Called by the parser when a starting HTML tag is located. The tag is contained in the parameter t. The parameter pos gives the current position.
Method: handleText
public void handleText(char[] data,int pos)
Called by the parser when text is located in the HTML document. The text is contained in the parameter data. The parameter pos gives the current position.