javax.swing.text.html
Class HTMLDocument.HTMLReader

java.lang.Object
  extended by javax.swing.text.html.HTMLEditorKit.ParserCallback
      extended by javax.swing.text.html.HTMLDocument.HTMLReader
Enclosing class:
HTMLDocument

public class HTMLDocument.HTMLReader
extends HTMLEditorKit.ParserCallback

A reader to load an HTMLDocument with HTML structure.


Nested Class Summary
 class HTMLDocument.HTMLReader.BlockAction
           
 class HTMLDocument.HTMLReader.CharacterAction
           
 class HTMLDocument.HTMLReader.FormAction
          Processes elements that make up forms: <input>, <textarea>, <select> and <option>.
 class HTMLDocument.HTMLReader.HiddenAction
          This action indicates that the content between starting and closing HTML elements (like script - /script) should not be visible.
 class HTMLDocument.HTMLReader.IsindexAction
          Handles <isindex> tags.
 class HTMLDocument.HTMLReader.ParagraphAction
           
 class HTMLDocument.HTMLReader.PreAction
          This action is performed when a <pre> tag is parsed.
 class HTMLDocument.HTMLReader.SpecialAction
          Inserts the elements that are represented by ths single tag with attributes (only).
 class HTMLDocument.HTMLReader.TagAction
           
 
Field Summary
protected  MutableAttributeSet charAttr
          Holds the current character attribute set *
protected  Vector<DefaultStyledDocument.ElementSpec> parseBuffer
           
 
Fields inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback
IMPLIED
 
Constructor Summary
HTMLDocument.HTMLReader(int offset)
           
HTMLDocument.HTMLReader(int offset, int popDepth, int pushDepth, HTML.Tag insertTag)
           
 
Method Summary
protected  void addContent(char[] data, int offs, int length)
          Adds text to the appropriate context using the current character attribute set.
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.
protected  void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
          Adds content that is specified in the attribute set.
protected  void blockClose(HTML.Tag t)
          Instructs the parse buffer to close the block element associated with the given HTML.Tag
protected  void blockOpen(HTML.Tag t, MutableAttributeSet attr)
          Instructs the parse buffer to create a block element with the given attributes.
 void flush()
          This is the last method called on the HTMLReader, allowing any pending changes to be flushed to the HTMLDocument.
 void handleComment(char[] data, int pos)
          This method called by parser to handle a comment block.
 void handleEndOfLineString(String eol)
          This is invoked after the stream has been parsed but before it has been flushed.
 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.
 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.
 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.
 void handleText(char[] data, int pos)
          This method is called by the parser to indicate a block of text was encountered.
protected  void popCharacterStyle()
          Pops a character style off of the stack and uses it as the current character style.
protected  void preContent(char[] data)
          Adds the given text that was encountered in a element.
protected  void pushCharacterStyle()
          Pushes the current character style onto the stack.
protected  void registerTag(HTML.Tag t, HTMLDocument.HTMLReader.TagAction a)
          Registers a given tag with a given Action.
protected  void textAreaContent(char[] data)
          Adds the given text to the textarea document.
 
Methods inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback
handleError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charAttr

protected MutableAttributeSet charAttr
Holds the current character attribute set *


parseBuffer

protected Vector<DefaultStyledDocument.ElementSpec> parseBuffer
Constructor Detail

HTMLDocument.HTMLReader

public HTMLDocument.HTMLReader(int offset)

HTMLDocument.HTMLReader

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

pushCharacterStyle

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


popCharacterStyle

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


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

flush

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

Overrides:
flush in class HTMLEditorKit.ParserCallback
Throws:
BadLocationException

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.

Overrides:
handleText in class HTMLEditorKit.ParserCallback
Parameters:
data - the text that was inserted
pos - the position at which the text was inserted

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.

Overrides:
handleStartTag in class HTMLEditorKit.ParserCallback
Parameters:
t - the HTML.Tag
a - the attribute set
pos - the position at which the tag was encountered

handleComment

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

Overrides:
handleComment in class HTMLEditorKit.ParserCallback
Parameters:
data - the comment
pos - the position at which the comment was encountered

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.

Overrides:
handleEndTag in class HTMLEditorKit.ParserCallback
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.

Overrides:
handleSimpleTag in class HTMLEditorKit.ParserCallback
Parameters:
t - the HTML.Tag that was encountered
a - the attribute set
pos - the position at which the tag was encountered

handleEndOfLineString

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

Overrides:
handleEndOfLineString in class HTMLEditorKit.ParserCallback
Parameters:
eol - one of \n, \r, or \r\n, whichever was encountered the most in parsing the stream
Since:
1.3

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

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

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

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

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