DTDConstants
public class DocumentParser extends Parser
This will message the callback for all valid tags, as well as tags that are implied but not explicitly specified. For example, the html string (<p>blah) only has a p tag defined. The callback will see the following methods:
Boolean.TRUE
for the key HTMLEditorKit.ParserCallback.IMPLIED
. HTML.Attributes defines a type safe enumeration of html attributes. If an attribute key of a tag is defined in HTML.Attribute, the HTML.Attribute will be used as the key, otherwise a String will be used. For example <p foo=bar class=neat> has two attributes. foo is not defined in HTML.Attribute, where as class is, therefore the AttributeSet will have two values in it, HTML.Attribute.CLASS with a String value of 'neat' and the String key 'foo' with a String value of 'bar'.
The position argument will indicate the start of the tag, comment or text. Similar to arrays, the first character in the stream has a position of 0. For tags that are implied the position will indicate the location of the next encountered tag. In the first example, the implied start body and html tags will have the same position as the p tag, and the implied end p, html and body tags will all have the same position.
As html skips whitespace the position for text will be the position of the first valid character, eg in the string '\n\n\nblah' the text 'blah' will have a position of 3, the newlines are skipped.
For attributes that do not have a value, eg in the html string <foo blah>
the attribute blah
does not have a value, there are two possible values that will be placed in the AttributeSet's value:
HTML.NULL_ATTRIBUTE_VALUE
. <!ATTLIST OPTION selected (selected) #IMPLIED>
this value from the dtd (in this case selected) will be used. Once the stream has been parsed, the callback is notified of the most likely end of line string. The end of line string will be one of \n, \r or \r\n, which ever is encountered the most in parsing the stream.
ANY, CDATA, CONREF, CURRENT, DEFAULT, EMPTY, ENDTAG, ENTITIES, ENTITY, FIXED, GENERAL, ID, IDREF, IDREFS, IMPLIED, MD, MODEL, MS, NAME, NAMES, NMTOKEN, NMTOKENS, NOTATION, NUMBER, NUMBERS, NUTOKEN, NUTOKENS, PARAMETER, PI, PUBLIC, RCDATA, REQUIRED, SDATA, STARTTAG, SYSTEM
Constructor | Description |
---|---|
DocumentParser |
Creates document parser with the specified dtd . |
Modifier and Type | Method | Description |
---|---|---|
protected void |
handleEmptyTag |
Handle Empty Tag. |
protected void |
handleEndTag |
Handle End Tag. |
protected void |
handleStartTag |
Handle Start Tag. |
protected void |
handleText |
Handle Text. |
void |
parse |
Parse an HTML stream, given a DTD. |
endTag, error, error, error, error, flushAttributes, getAttributes, getCurrentLine, getCurrentPos, handleComment, handleEOFInComment, handleError, handleTitle, makeTag, makeTag, markFirstTime, parse, parseDTDMarkup, parseMarkupDeclarations, startTag
public DocumentParser(DTD dtd)
dtd
.dtd
- the dtd.public void parse(Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException
in
- the reader to read the source fromcallback
- the callbackignoreCharSet
- if true
the charset is ignoredIOException
- if an I/O error occursprotected void handleStartTag(TagElement tag)
handleStartTag
in class Parser
tag
- the tag being handledprotected void handleEmptyTag(TagElement tag) throws ChangedCharSetException
handleEmptyTag
in class Parser
tag
- the tag being handledChangedCharSetException
- if the document charset was changedprotected void handleEndTag(TagElement tag)
handleEndTag
in class Parser
tag
- the tag being handledprotected void handleText(char[] data)
handleText
in class Parser
data
- the section text
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/text/html/parser/DocumentParser.html