- Using HTMLEditorKit.Parser
- Using HTMLEditorKit.<br />ParserCallback
- Using HTML.Tag
- Using HTML.Attribute
- Conclusions
Using HTML.Attribute
You often need to look at the attributes of a particular HTML tag, and the HTML.Attribute class is used to represent an HTML tag. Table 2 lists the 80 HTML attributes recognized by the Swing HTML parser. The handleSimpleTag and handleStartTag pass in a MutableAttributeSet that contains a list of attributes. For example, to retrieve the HREF attribute from a MutableAttributeSet named a, use the following command:
String value = a.getAttribute(HTML.Attribute.HREF);
Table 2 shows all available attribute constants.
Table 2: HTML.Attribute Constants
HTML.Attribute.ACTION |
HTML.Attribute.ALIGN |
HTML.Attribute.ALINK |
HTML.Attribute.ALT |
HTML.Attribute.ARCHIVE |
HTML.Attribute.BACKGROUND |
HTML.Attribute.BGCOLOR |
HTML.Attribute.BORDER |
HTML.Attribute.CELLPADDING |
HTML.Attribute.CELLSPACING |
HTML.Attribute.CHECKED |
HTML.Attribute.CLASS |
HTML.Attribute.CLASSID |
HTML.Attribute.CLEAR |
HTML.Attribute.CODE |
HTML.Attribute.CODEBASE |
HTML.Attribute.CODETYPE |
HTML.Attribute.COLOR |
HTML.Attribute.COLS |
HTML.Attribute.COLSPAN |
HTML.Attribute.COMMENT |
HTML.Attribute.COMPACT |
HTML.Attribute.CONTENT |
HTML.Attribute.COORDS |
HTML.Attribute.DATA |
HTML.Attribute.DECLARE |
HTML.Attribute.DIR |
HTML.Attribute.DUMMY |
HTML.Attribute.ENCTYPE |
HTML.Attribute.ENDTAG |
HTML.Attribute.FACE |
HTML.Attribute.FRAMEBORDER |
HTML.Attribute.HALIGN |
HTML.Attribute.HEIGHT |
HTML.Attribute.HREF |
HTML.Attribute.HSPACE |
HTML.Attribute.HTTPEQUIV |
HTML.Attribute.ID |
HTML.Attribute.ISMAP |
HTML.Attribute.LANG |
HTML.Attribute.LANGUAGE |
HTML.Attribute.LINK |
HTML.Attribute.LOWSRC |
HTML.Attribute.MARGINHEIGHT |
HTML.Attribute.MARGINWIDTH |
HTML.Attribute.MAXLENGTH |
HTML.Attribute.METHOD |
HTML.Attribute.MULTIPLE |
HTML.Attribute.N |
HTML.Attribute.NAME |
HTML.Attribute.NOHREF |
HTML.Attribute.NORESIZE |
HTML.Attribute.NOSHADE |
HTML.Attribute.NOWRAP |
HTML.Attribute.PROMPT |
HTML.Attribute.REL |
HTML.Attribute.REV |
HTML.Attribute.ROWS |
HTML.Attribute.ROWSPAN |
HTML.Attribute.SCROLLING |
HTML.Attribute.SELECTED |
HTML.Attribute.SHAPE |
HTML.Attribute.SHAPES |
HTML.Attribute.SIZE |
HTML.Attribute.SRC |
HTML.Attribute.STANDBY |
HTML.Attribute.START |
HTML.Attribute.STYLE |
HTML.Attribute.TARGET |
HTML.Attribute.TEXT |
HTML.Attribute.TITLE |
HTML.Attribute.TYPE |
HTML.Attribute.USEMAP |
HTML.Attribute.VALIGN |
HTML.Attribute.VALUE |
HTML.Attribute.VALUETYPE |
HTML.Attribute.VERSION |
HTML.Attribute.VLINK |
HTML.Attribute.VSPACE |
HTML.Attribute.WIDTH |
If you construct your own parser call back, it will look something like Listing 2.
Listing 2: A Custom Callback Template
protected class Parser extends HTMLEditorKit.ParserCallback { public void handleComment(char[] data,int pos) { // insert code to handle comments } public void handleEndTag(HTML.Tag t,int pos) { // insert code to handle ending tags } public void handleError(String errorMsg,int pos) { // insert error handling code } public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a,int pos) { // insert code to handle simple tags } public void handleStartTag(HTML.Tag t, MutableAttributeSet a,int pos) { // insert code to handle starting tags } }