|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.text.html.HTMLEditorKit.ParserCallback javax.swing.text.html.HTMLDocument.HTMLReader
An HTML reader to load an HTML document with an HTML element structure. This is a set of callbacks from the parser, implemented to create a set of elements tagged with attributes. The parse builds up tokens (ElementSpec) that describe the element subtree desired, and burst it into the document under the protection of a write lock using the insert method on the document outer class.
The reader can be configured by registering actions
(of type HTMLDocument.HTMLReader.TagAction
)
that describe how to handle the action. The idea behind
the actions provided is that the most natural text editing
operations can be provided if the element structure boils
down to paragraphs with runs of some kind of style
in them. Some things are more naturally specified
structurally, so arbitrary structure should be allowed
above the paragraphs, but will need to be edited with structural
actions. The implication of this is that some of the
HTML elements specified in the stream being parsed will
be collapsed into attributes, and in some cases paragraphs
will be synthesized. When HTML elements have been
converted to attributes, the attribute key will be of
type HTML.Tag, and the value will be of type AttributeSet
so that no information is lost. This enables many of the
existing actions to work so that the user can type input,
hit the return key, backspace, delete, etc and have a
reasonable result. Selections can be created, and attributes
applied or removed, etc. With this in mind, the work done
by the reader can be categorized into the following kinds
of tasks:
Currently, <APPLET>, <PARAM>, <MAP>, <AREA>, <LINK>, <SCRIPT> and <STYLE> are unsupported.
The assignment of the actions described is shown in the
following table for the tags defined in HTML.Tag
.
Tag | Action |
---|---|
HTML.Tag.A | CharacterAction |
HTML.Tag.ADDRESS | CharacterAction |
HTML.Tag.APPLET | HiddenAction |
HTML.Tag.AREA | AreaAction |
HTML.Tag.B | CharacterAction |
HTML.Tag.BASE | BaseAction |
HTML.Tag.BASEFONT | CharacterAction |
HTML.Tag.BIG | CharacterAction |
HTML.Tag.BLOCKQUOTE | BlockAction |
HTML.Tag.BODY | BlockAction |
HTML.Tag.BR | SpecialAction |
HTML.Tag.CAPTION | BlockAction |
HTML.Tag.CENTER | BlockAction |
HTML.Tag.CITE | CharacterAction |
HTML.Tag.CODE | CharacterAction |
HTML.Tag.DD | BlockAction |
HTML.Tag.DFN | CharacterAction |
HTML.Tag.DIR | BlockAction |
HTML.Tag.DIV | BlockAction |
HTML.Tag.DL | BlockAction |
HTML.Tag.DT | ParagraphAction |
HTML.Tag.EM | CharacterAction |
HTML.Tag.FONT | CharacterAction |
HTML.Tag.FORM | As of 1.4 a BlockAction |
HTML.Tag.FRAME | SpecialAction |
HTML.Tag.FRAMESET | BlockAction |
HTML.Tag.H1 | ParagraphAction |
HTML.Tag.H2 | ParagraphAction |
HTML.Tag.H3 | ParagraphAction |
HTML.Tag.H4 | ParagraphAction |
HTML.Tag.H5 | ParagraphAction |
HTML.Tag.H6 | ParagraphAction |
HTML.Tag.HEAD | HeadAction |
HTML.Tag.HR | SpecialAction |
HTML.Tag.HTML | BlockAction |
HTML.Tag.I | CharacterAction |
HTML.Tag.IMG | SpecialAction |
HTML.Tag.INPUT | FormAction |
HTML.Tag.ISINDEX | IsndexAction |
HTML.Tag.KBD | CharacterAction |
HTML.Tag.LI | BlockAction |
HTML.Tag.LINK | LinkAction |
HTML.Tag.MAP | MapAction |
HTML.Tag.MENU | BlockAction |
HTML.Tag.META | MetaAction |
HTML.Tag.NOFRAMES | BlockAction |
HTML.Tag.OBJECT | SpecialAction |
HTML.Tag.OL | BlockAction |
HTML.Tag.OPTION | FormAction |
HTML.Tag.P | ParagraphAction |
HTML.Tag.PARAM | HiddenAction |
HTML.Tag.PRE | PreAction |
HTML.Tag.SAMP | CharacterAction |
HTML.Tag.SCRIPT | HiddenAction |
HTML.Tag.SELECT | FormAction |
HTML.Tag.SMALL | CharacterAction |
HTML.Tag.STRIKE | CharacterAction |
HTML.Tag.S | CharacterAction |
HTML.Tag.STRONG | CharacterAction |
HTML.Tag.STYLE | StyleAction |
HTML.Tag.SUB | CharacterAction |
HTML.Tag.SUP | CharacterAction |
HTML.Tag.TABLE | BlockAction |
HTML.Tag.TD | BlockAction |
HTML.Tag.TEXTAREA | FormAction |
HTML.Tag.TH | BlockAction |
HTML.Tag.TITLE | TitleAction |
HTML.Tag.TR | BlockAction |
HTML.Tag.TT | CharacterAction |
HTML.Tag.U | CharacterAction |
HTML.Tag.UL | BlockAction |
HTML.Tag.VAR | CharacterAction |
Once </html> is encountered, the Actions are no longer notified.
Nested Class Summary | |
(package private) class |
HTMLDocument.HTMLReader.AnchorAction
|
(package private) class |
HTMLDocument.HTMLReader.AreaAction
|
(package private) class |
HTMLDocument.HTMLReader.BaseAction
|
class |
HTMLDocument.HTMLReader.BlockAction
|
class |
HTMLDocument.HTMLReader.CharacterAction
|
(package private) class |
HTMLDocument.HTMLReader.ConvertAction
Provides conversion of HTML tag/attribute mappings that have a corresponding StyleConstants and CSS mapping. |
class |
HTMLDocument.HTMLReader.FormAction
Action to support forms by building all of the elements used to represent form controls. |
private class |
HTMLDocument.HTMLReader.FormTagAction
Action used for the actual element form tag. |
(package private) class |
HTMLDocument.HTMLReader.HeadAction
End if overridden to create the necessary stylesheets that are referenced via the link tag. |
class |
HTMLDocument.HTMLReader.HiddenAction
|
class |
HTMLDocument.HTMLReader.IsindexAction
|
(package private) class |
HTMLDocument.HTMLReader.LinkAction
A subclass to add the AttributeSet to styles if the attributes contains an attribute for 'rel' with value 'stylesheet' or 'alternate stylesheet'. |
(package private) class |
HTMLDocument.HTMLReader.MapAction
|
(package private) class |
HTMLDocument.HTMLReader.MetaAction
Subclass of HiddenAction to set the content type for style sheets, and to set the name of the default style sheet. |
(package private) class |
HTMLDocument.HTMLReader.ObjectAction
|
class |
HTMLDocument.HTMLReader.ParagraphAction
|
class |
HTMLDocument.HTMLReader.PreAction
|
class |
HTMLDocument.HTMLReader.SpecialAction
|
(package private) class |
HTMLDocument.HTMLReader.StyleAction
|
class |
HTMLDocument.HTMLReader.TagAction
An action to be performed in response to parsing a tag. |
(package private) class |
HTMLDocument.HTMLReader.TitleAction
|
Field Summary | |
protected MutableAttributeSet |
charAttr
|
(package private) Stack |
charAttrStack
|
(package private) String |
defaultStyle
Name of style to use. |
(package private) boolean |
emptyAnchor
|
(package private) boolean |
emptyDocument
True if inserting into an empty document. |
private int |
flushCount
Number of times flushBuffer has been invoked. |
(package private) boolean |
foundInsertTag
Set to true when insertTag has been found. |
(package private) boolean |
impliedP
|
(package private) int |
inBlock
|
(package private) boolean |
inBody
True when the body has been encountered. |
(package private) boolean |
inHead
True if inside the head tag. |
(package private) boolean |
inParagraph
|
(package private) boolean |
inPre
|
private boolean |
insertAfterImplied
If true, behavior is similiar to insertTag, but instead of waiting for insertTag will wait for first Element without an 'implied' attribute and begin inserting then. |
(package private) boolean |
insertInsertTag
If true, the insertTag is inserted, otherwise elements after the insertTag is found are inserted. |
(package private) HTML.Tag |
insertTag
If non null, gives parent Tag that insert is to happen at. |
(package private) int |
insertTagDepthDelta
When foundInsertTag is set to true, this will be updated to reflect the delta between the two structures. |
(package private) boolean |
inStyle
Set to true when a style element is encountered. |
(package private) boolean |
inTextArea
|
(package private) boolean |
inTitle
|
(package private) boolean |
isStyleCSS
Set to true if the style language is text/css. |
(package private) Map |
lastMap
Last Map that was encountered. |
(package private) boolean |
lastWasNewline
|
(package private) boolean |
midInsert
True if (! |
(package private) int |
offset
|
(package private) Option |
option
Current option, if in an option element (needed to load the label. |
protected Vector |
parseBuffer
|
(package private) int |
popDepth
How many parents to ascend before insert new elements. |
(package private) int |
pushDepth
How many parents to descend (relative to popDepth) before inserting. |
private boolean |
receivedEndHTML
This is set to true when and end is invoked for . |
(package private) AttributeSet |
styleAttributes
Attributes from a style Attribute. |
(package private) Vector |
styles
Vector describing styles that should be include. |
(package private) Hashtable |
tagMap
|
(package private) TextAreaDocument |
textAreaDocument
|
(package private) int |
threshold
|
private boolean |
wantsTrailingNewline
This is only used if insertAfterImplied is true. |
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)
|
(package private) |
HTMLDocument.HTMLReader(int offset,
int popDepth,
int pushDepth,
HTML.Tag insertTag,
boolean insertInsertTag,
boolean insertAfterImplied,
boolean wantsTrailingNewline)
Generates a RuntimeException (will eventually generate a BadLocationException when API changes are alloced) if inserting into non empty document, insertTag is
non-null , and offset is not in the body. |
Method Summary | |
protected void |
addContent(char[] data,
int offs,
int length)
Adds some text with the current character attributes. |
protected void |
addContent(char[] data,
int offs,
int length,
boolean generateImpliedPIfNecessary)
Adds some text with the current character attributes. |
(package private) void |
addCSSRules(String rules)
Adds the CSS rules in rules . |
private void |
addExternalComment(String comment)
Adds the comment comment to the set of comments
maintained outside of the scope of elements. |
protected void |
addSpecialElement(HTML.Tag t,
MutableAttributeSet a)
Adds content that is basically specified entirely in the attribute set. |
private void |
adjustEndElement()
This will make sure there aren't two BODYs (the second is typically created when you do a remove all, and then an insert). |
private void |
adjustEndSpecsForPartialInsert()
This will be invoked for the last flush, if insertTag
is non null. |
protected void |
blockClose(HTML.Tag t)
Adds an instruction to the parse buffer to close out a block element of the given type. |
protected void |
blockOpen(HTML.Tag t,
MutableAttributeSet attr)
Adds an instruction to the parse buffer to create a block element with the given attributes. |
private boolean |
canInsertTag(HTML.Tag t,
AttributeSet attr,
boolean isBlockTag)
Returns true if can insert starting at t . |
private int |
depthTo(int offset)
|
void |
flush()
The last method called on the reader. |
(package private) void |
flushBuffer(boolean endOfStream)
Flushes the current parse buffer into the document. |
private void |
foundInsertTag(boolean isBlockTag)
|
private void |
generateEndsSpecsForMidInsert()
Generates an initial batch of end ElementSpecs
in parseBuffer to position future inserts into the body. |
private Element[] |
getPathTo(int offset)
|
void |
handleComment(char[] data,
int pos)
|
void |
handleEndOfLineString(String eol)
This is invoked after the stream has been parsed, but before flush . |
void |
handleEndTag(HTML.Tag t,
int pos)
Callback from the parser. |
void |
handleSimpleTag(HTML.Tag t,
MutableAttributeSet a,
int pos)
Callback from the parser. |
void |
handleStartTag(HTML.Tag t,
MutableAttributeSet a,
int pos)
Callback from the parser. |
void |
handleText(char[] data,
int pos)
Called by the parser to indicate a block of text was encountered. |
private int |
heightToElementWithName(Object name,
int offset)
|
private boolean |
isInsertTag(HTML.Tag tag)
|
(package private) void |
linkCSSStyleSheet(String href)
Adds the CSS stylesheet at href to the known list
of stylesheets. |
protected void |
popCharacterStyle()
Pops a previously pushed character style off the stack to return to a previous style. |
protected void |
preContent(char[] data)
Adds the given content that was encountered in a PRE element. |
protected void |
pushCharacterStyle()
Pushes the current character style on a stack in preparation for forming a new nested character style. |
protected void |
registerTag(HTML.Tag t,
HTMLDocument.HTMLReader.TagAction a)
Registers a handler for the given tag. |
protected void |
textAreaContent(char[] data)
Adds the given content 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 |
private boolean receivedEndHTML
private int flushCount
flushBuffer
has been invoked.
private boolean insertAfterImplied
private boolean wantsTrailingNewline
int threshold
int offset
boolean inParagraph
boolean impliedP
boolean inPre
boolean inTextArea
TextAreaDocument textAreaDocument
boolean inTitle
boolean lastWasNewline
boolean emptyAnchor
boolean midInsert
boolean inBody
HTML.Tag insertTag
boolean insertInsertTag
boolean foundInsertTag
int insertTagDepthDelta
int popDepth
int pushDepth
Map lastMap
boolean inStyle
String defaultStyle
Vector styles
LINK: in which case it is followed by an AttributeSet
STYLE: in which case the following element is a String indicating the type (may be null), and the elements following it until the next HTML.Tag are the rules as Strings.
boolean inHead
boolean isStyleCSS
boolean emptyDocument
AttributeSet styleAttributes
Option option
protected Vector parseBuffer
protected MutableAttributeSet charAttr
Stack charAttrStack
Hashtable tagMap
int inBlock
Constructor Detail |
public HTMLDocument.HTMLReader(int offset)
public HTMLDocument.HTMLReader(int offset, int popDepth, int pushDepth, HTML.Tag insertTag)
HTMLDocument.HTMLReader(int offset, int popDepth, int pushDepth, HTML.Tag insertTag, boolean insertInsertTag, boolean insertAfterImplied, boolean wantsTrailingNewline)
insertTag
is
non-null
, and offset
is not in the body.
Method Detail |
private void generateEndsSpecsForMidInsert()
ElementSpecs
in parseBuffer to position future inserts into the body.
private int depthTo(int offset)
private int heightToElementWithName(Object name, int offset)
offset
until a parent with name, name
has been
found. -1 indicates no matching parent with
name
.private void adjustEndElement()
private Element[] getPathTo(int offset)
public void flush() throws BadLocationException
flush
in class HTMLEditorKit.ParserCallback
BadLocationException
public void handleText(char[] data, int pos)
handleText
in class HTMLEditorKit.ParserCallback
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos)
handleStartTag
in class HTMLEditorKit.ParserCallback
public void handleComment(char[] data, int pos)
handleComment
in class HTMLEditorKit.ParserCallback
private void addExternalComment(String comment)
comment
to the set of comments
maintained outside of the scope of elements.
public void handleEndTag(HTML.Tag t, int pos)
handleEndTag
in class HTMLEditorKit.ParserCallback
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
handleSimpleTag
in class HTMLEditorKit.ParserCallback
public void handleEndOfLineString(String eol)
flush
. eol
will be one of \n, \r
or \r\n, which ever is encountered the most in parsing the
stream.
handleEndOfLineString
in class HTMLEditorKit.ParserCallback
protected void registerTag(HTML.Tag t, HTMLDocument.HTMLReader.TagAction a)
protected void pushCharacterStyle()
protected void popCharacterStyle()
protected void textAreaContent(char[] data)
protected void preContent(char[] data)
protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
protected void blockClose(HTML.Tag t)
protected void addContent(char[] data, int offs, int length)
data
- text to be addedoffs
- location to insert text in the Documentlength
- length of new textprotected void addContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary)
data
- text to be addedoffs
- location to insert text in the Documentlength
- length of new textgenerateImpliedPIfNecessary
- If false, the text is added as is.
If true and the current Element is not
a valid Element to contain textual content,
a paragraph will be created to contain the text.protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
void flushBuffer(boolean endOfStream) throws BadLocationException
endOfStream
- true if there is no more content to parser
BadLocationException
private void adjustEndSpecsForPartialInsert()
insertTag
is non null.
void addCSSRules(String rules)
rules
.
void linkCSSStyleSheet(String href)
href
to the known list
of stylesheets.
private boolean canInsertTag(HTML.Tag t, AttributeSet attr, boolean isBlockTag)
t
. This
will return false if the insert tag is set, and hasn't been found
yet.
private boolean isInsertTag(HTML.Tag tag)
private void foundInsertTag(boolean isBlockTag)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |