javax.swing.text.html

Class 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
parseBuffer

Fields inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback

IMPLIED

Constructor Summary

HTMLReader(int offset)
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

flush, handleComment, handleEndOfLineString, handleEndTag, handleError, handleSimpleTag, handleStartTag, handleText

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

charAttr

protected MutableAttributeSet charAttr
Holds the current character attribute set *

parseBuffer

protected Vector parseBuffer

Constructor Details

HTMLReader

public HTMLReader(int offset)

HTMLReader

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

Method Details

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()
            throws BadLocationException
This is the last method called on the HTMLReader, allowing any pending changes to be flushed to the HTMLDocument.
Overrides:
flush in interface HTMLEditorKit.ParserCallback

handleComment

public void handleComment(char[] data,
                          int pos)
This method called by parser to handle a comment block.
Overrides:
handleComment in interface HTMLEditorKit.ParserCallback
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.
Overrides:
handleEndOfLineString in interface HTMLEditorKit.ParserCallback
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.
Overrides:
handleEndTag in interface 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 interface HTMLEditorKit.ParserCallback
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.
Overrides:
handleStartTag in interface HTMLEditorKit.ParserCallback
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.
Overrides:
handleText in interface HTMLEditorKit.ParserCallback
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

HTMLDocument.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.