- Enclosing class:
- HTMLDocument
 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:
 
- Block
- Build the structure like it's specified in the stream. This produces elements that contain other elements.
- Paragraph
- Like block except that it's expected that the element will be used with a paragraph view so a paragraph element won't need to be synthesized.
- Character
- Contribute the element as an attribute that will start and stop at arbitrary text locations. This will ultimately be mixed into a run of text, with all of the currently flattened HTML character elements.
- Special
- Produce an embedded graphical element.
- Form
- Produce an element that is like the embedded graphical element, except that it also has a component model associated with it.
- Hidden
- Create an element that is hidden from view when the document is being viewed read-only, and visible when the document is being edited. This is useful to keep the model from losing information, and used to store things like comments and unrecognized tags.
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 SummaryNested ClassesModifier and TypeClassDescriptionclassAction assigned by default to handle the Block task of the reader.classAction assigned by default to handle the Character task of the reader.classAction to support forms by building all of the elements used to represent form controls.classAction assigned by default to handle the Hidden task of the reader.classAction assigned by default to handle the Isindex task of the reader.classAction assigned by default to handle the Paragraph task of the reader.classAction assigned by default to handle the Pre block task of the reader.classAction assigned by default to handle the Special task of the reader.classAn action to be performed in response to parsing a tag.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected MutableAttributeSetCurrent character attribute set.protected Vector<DefaultStyledDocument.ElementSpec> Buffer to keep building elements.Fields declared in class javax.swing.text.html.HTMLEditorKit.ParserCallbackIMPLIED
- 
Constructor SummaryConstructorsConstructorDescriptionHTMLReader(int offset) Constructs an HTMLReader using default pop and push depth and no tag to insert.HTMLReader(int offset, int popDepth, int pushDepth, HTML.Tag insertTag) Constructs an HTMLReader.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidaddContent(char[] data, int offs, int length) Adds some text with the current character attributes.protected voidaddContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary) Adds some text with the current character attributes.protected voidAdds content that is basically specified entirely in the attribute set.protected voidAdds an instruction to the parse buffer to close out a block element of the given type.protected voidblockOpen(HTML.Tag t, MutableAttributeSet attr) Adds an instruction to the parse buffer to create a block element with the given attributes.voidflush()The last method called on the reader.voidThis is invoked after the stream has been parsed, but beforeflush.voidhandleEndTag(HTML.Tag t, int pos) Callback from the parser.voidhandleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) Callback from the parser.voidhandleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) Callback from the parser.voidhandleText(char[] data, int pos) Called by the parser to indicate a block of text was encountered.protected voidPops a previously pushed character style off the stack to return to a previous style.protected voidpreContent(char[] data) Adds the given content that was encountered in a PRE element.protected voidPushes the current character style on a stack in preparation for forming a new nested character style.protected voidRegisters a handler for the given tag.protected voidtextAreaContent(char[] data) Adds the given content to the textarea document.Methods declared in class javax.swing.text.html.HTMLEditorKit.ParserCallbackhandleComment, handleError
- 
Field Details- 
parseBufferBuffer to keep building elements.
- 
charAttrCurrent character attribute set.
 
- 
- 
Constructor Details- 
HTMLReaderpublic HTMLReader(int offset) Constructs an HTMLReader using default pop and push depth and no tag to insert.- Parameters:
- offset- the starting offset
 
- 
HTMLReaderConstructs an HTMLReader.- Parameters:
- offset- the starting offset
- popDepth- how many parents to ascend before insert new element
- pushDepth- how many parents to descend (relative to popDepth) before inserting
- insertTag- a tag to insert (may be null)
 
 
- 
- 
Method Details- 
flushThe last method called on the reader. It allows any pending changes to be flushed into the document. Since this is currently loading synchronously, the entire set of changes are pushed in at this point.- Overrides:
- flushin class- HTMLEditorKit.ParserCallback
- Throws:
- BadLocationException- if the given position does not represent a valid location in the associated document.
 
- 
handleTextpublic void handleText(char[] data, int pos) Called by the parser to indicate a block of text was encountered.- Overrides:
- handleTextin class- HTMLEditorKit.ParserCallback
- Parameters:
- data- a data
- pos- a position
 
- 
handleStartTagCallback from the parser. Route to the appropriate handler for the tag.- Overrides:
- handleStartTagin class- HTMLEditorKit.ParserCallback
- Parameters:
- t- an HTML tag
- a- a set of attributes
- pos- a position
 
- 
handleEndTagCallback from the parser. Route to the appropriate handler for the tag.- Overrides:
- handleEndTagin class- HTMLEditorKit.ParserCallback
- Parameters:
- t- an HTML tag
- pos- a position
 
- 
handleSimpleTagCallback from the parser. Route to the appropriate handler for the tag.- Overrides:
- handleSimpleTagin class- HTMLEditorKit.ParserCallback
- Parameters:
- t- an HTML tag
- a- a set of attributes
- pos- a position
 
- 
handleEndOfLineStringThis is invoked after the stream has been parsed, but beforeflush.eolwill be one of \n, \r or \r\n, which ever is encountered the most in parsing the stream.- Overrides:
- handleEndOfLineStringin class- HTMLEditorKit.ParserCallback
- Parameters:
- eol- value of eol
- Since:
- 1.3
 
- 
registerTagRegisters a handler for the given tag. By default all of the well-known tags will have been registered. This can be used to change the handling of a particular tag or to add support for custom tags.- Parameters:
- t- an HTML tag
- a- tag action handler
 
- 
pushCharacterStyleprotected void pushCharacterStyle()Pushes the current character style on a stack in preparation for forming a new nested character style.
- 
popCharacterStyleprotected void popCharacterStyle()Pops a previously pushed character style off the stack to return to a previous style.
- 
textAreaContentprotected void textAreaContent(char[] data) Adds the given content to the textarea document. This method gets called when we are in a textarea context. Therefore all text that is seen belongs to the text area and is hence added to the TextAreaDocument associated with the text area.- Parameters:
- data- the given content
 
- 
preContentprotected void preContent(char[] data) Adds the given content that was encountered in a PRE element. This synthesizes lines to hold the runs of text, and makes calls to addContent to actually add the text.- Parameters:
- data- the given content
 
- 
blockOpenAdds an instruction to the parse buffer to create a block element with the given attributes.- Parameters:
- t- an HTML tag
- attr- the attribute set
 
- 
blockCloseAdds an instruction to the parse buffer to close out a block element of the given type.- Parameters:
- t- the HTML tag
 
- 
addContentprotected void addContent(char[] data, int offs, int length) Adds some text with the current character attributes.- Parameters:
- data- the content to add
- offs- the initial offset
- length- the length
 
- 
addContentprotected void addContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary) Adds some text with the current character attributes.- Parameters:
- data- the content to add
- offs- the initial offset
- length- the length
- generateImpliedPIfNecessary- whether to generate implied paragraphs
 
- 
addSpecialElementAdds content that is basically specified entirely in the attribute set.- Parameters:
- t- an HTML tag
- a- the attribute set
 
 
-