javax.swing.text.html

Class HTMLDocument.HTMLReader

public class HTMLDocument.HTMLReader extends HTMLEditorKit.ParserCallback

A reader to load an HTMLDocument with HTML structure.
Nested Class Summary
classHTMLDocument.HTMLReader.BlockAction
classHTMLDocument.HTMLReader.CharacterAction
classHTMLDocument.HTMLReader.FormAction
Processes elements that make up forms: <input>, <textarea>, <select> and <option>.
classHTMLDocument.HTMLReader.HiddenAction
This action indicates that the content between starting and closing HTML elements (like script - /script) should not be visible.
classHTMLDocument.HTMLReader.IsindexAction
Handles <isindex> tags.
classHTMLDocument.HTMLReader.ParagraphAction
classHTMLDocument.HTMLReader.PreAction
This action is performed when a <pre> tag is parsed.
classHTMLDocument.HTMLReader.SpecialAction
Inserts the elements that are represented by ths single tag with attributes (only).
classHTMLDocument.HTMLReader.TagAction
Field Summary
protected MutableAttributeSetcharAttr
Holds the current character attribute set *
protected Vector<ElementSpec>parseBuffer
Constructor Summary
HTMLReader(int offset)
HTMLReader(int offset, int popDepth, int pushDepth, HTML.Tag insertTag)
Method Summary
protected voidaddContent(char[] data, int offs, int length)
Adds text to the appropriate context using the current character attribute set.
protected voidaddContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary)
Adds text to the appropriate context using the current character attribute set, and possibly generating an IMPLIED Tag if necessary.
protected voidaddSpecialElement(HTML.Tag t, MutableAttributeSet a)
Adds content that is specified in the attribute set.
protected voidblockClose(HTML.Tag t)
Instructs the parse buffer to close the block element associated with the given HTML.Tag
protected voidblockOpen(HTML.Tag t, MutableAttributeSet attr)
Instructs the parse buffer to create a block element with the given attributes.
voidflush()
This is the last method called on the HTMLReader, allowing any pending changes to be flushed to the HTMLDocument.
voidhandleComment(char[] data, int pos)
This method called by parser to handle a comment block.
voidhandleEndOfLineString(String eol)
This is invoked after the stream has been parsed but before it has been flushed.
voidhandleEndTag(HTML.Tag t, int pos)
This method is called by the parser and should route the call to the proper handler for the tag.
voidhandleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
This is a callback from the parser that should be routed to the appropriate handler for the tag.
voidhandleStartTag(HTML.Tag t, MutableAttributeSet a, int pos)
This method is called by the parser and should route the call to the proper handler for the tag.
voidhandleText(char[] data, int pos)
This method is called by the parser to indicate a block of text was encountered.
protected voidpopCharacterStyle()
Pops a character style off of the stack and uses it as the current character style.
protected voidpreContent(char[] data)
Adds the given text that was encountered in a
 element.
 
protected voidpushCharacterStyle()
Pushes the current character style onto the stack.
protected voidregisterTag(HTML.Tag t, HTMLDocument.HTMLReader.TagAction a)
Registers a given tag with a given Action.
protected voidtextAreaContent(char[] data)
Adds the given text to the textarea document.

Field Detail

charAttr

protected MutableAttributeSet charAttr
Holds the current character attribute set *

parseBuffer

protected Vector<ElementSpec> parseBuffer

Constructor Detail

HTMLReader

public HTMLReader(int offset)

HTMLReader

public HTMLReader(int offset, int popDepth, int pushDepth, HTML.Tag insertTag)

Method Detail

addContent

protected void addContent(char[] data, int offs, int length)
Adds text to the appropriate context using the current character attribute set.

Parameters: data the text to add offs the offset at which to add it length the length of the text to add

addContent

protected void addContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary)
Adds text to the appropriate context using the current character attribute set, and possibly generating an IMPLIED Tag if necessary.

Parameters: data the text to add offs the offset at which to add it length the length of the text to add generateImpliedPIfNecessary whether or not we should generate an HTML.Tag.IMPLIED tag if necessary

addSpecialElement

protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
Adds content that is specified in the attribute set.

Parameters: t the HTML.Tag a the attribute set specifying the special content

blockClose

protected void blockClose(HTML.Tag t)
Instructs the parse buffer to close the block element associated with the given HTML.Tag

Parameters: t the HTML.Tag that is closing its block

blockOpen

protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
Instructs the parse buffer to create a block element with the given attributes.

Parameters: t the tag that requires opening a new block attr the attribute set for the new block

flush

public void flush()
This is the last method called on the HTMLReader, allowing any pending changes to be flushed to the HTMLDocument.

handleComment

public void handleComment(char[] data, int pos)
This method called by parser to handle a comment block.

Parameters: data the comment pos the position at which the comment was encountered

handleEndOfLineString

public void handleEndOfLineString(String eol)
This is invoked after the stream has been parsed but before it has been flushed.

Parameters: eol one of \n, \r, or \r\n, whichever was encountered the most in parsing the stream

Since: 1.3

handleEndTag

public void handleEndTag(HTML.Tag t, int pos)
This method is called by the parser and should route the call to the proper handler for the tag.

Parameters: t the HTML.Tag pos the position at which the tag was encountered

handleSimpleTag

public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
This is a callback from the parser that should be routed to the appropriate handler for the tag.

Parameters: t the HTML.Tag that was encountered a the attribute set pos the position at which the tag was encountered

handleStartTag

public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos)
This method is called by the parser and should route the call to the proper handler for the tag.

Parameters: t the HTML.Tag a the attribute set pos the position at which the tag was encountered

handleText

public void handleText(char[] data, int pos)
This method is called by the parser to indicate a block of text was encountered. Should insert the text appropriately.

Parameters: data the text that was inserted pos the position at which the text was inserted

popCharacterStyle

protected void popCharacterStyle()
Pops a character style off of the stack and uses it as the current character style.

preContent

protected void preContent(char[] data)
Adds the given text that was encountered in a
 element.
 This adds synthesized lines to hold the text runs.

Parameters: data the text

pushCharacterStyle

protected void pushCharacterStyle()
Pushes the current character style onto the stack.

registerTag

protected void registerTag(HTML.Tag t, HTMLDocument.HTMLReader.TagAction a)
Registers a given tag with a given Action. All of the well-known tags are registered by default, but this method can change their behaviour or add support for custom or currently unsupported tags.

Parameters: t the Tag to register a the Action for the Tag

textAreaContent

protected void textAreaContent(char[] data)
Adds the given text to the textarea document. Called only when we are within a textarea.

Parameters: data the text to add to the textarea