Class DocumentParser
- All Implemented Interfaces:
DTDConstants
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:
- handleStartTag(html, ...)
- handleStartTag(head, ...)
- handleEndTag(head)
- handleStartTag(body, ...)
- handleStartTag(p, ...)
- handleText(...)
- handleEndTag(p)
- handleEndTag(body)
- handleEndTag(html)
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:
- If the DTD does not contain an definition for the element, or the
definition does not have an explicit value then the value in the
AttributeSet will be
HTML.NULL_ATTRIBUTE_VALUE. - If the DTD contains an explicit value, as in:
<!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.
-
Field Summary
Fields declared in interface DTDConstants
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, SYSTEMModifier and TypeFieldDescriptionstatic final intThe DTD constant corresponds to ANYstatic final intThe DTD constant corresponds to CDATAstatic final intThe DTD constant corresponds to CONREFstatic final intThe DTD constant corresponds to CURRENTstatic final intThe DTD constant corresponds to DEFAULTstatic final intThe DTD constant corresponds to EMPTYstatic final intThe DTD constant corresponds to ENDTAGstatic final intThe DTD constant corresponds to ENTITIESstatic final intThe DTD constant corresponds to ENTITYstatic final intThe DTD constant corresponds to FIXEDstatic final intThe DTD constant corresponds to GENERALstatic final intThe DTD constant corresponds to IDstatic final intThe DTD constant corresponds to IDREFstatic final intThe DTD constant corresponds to IDREFSstatic final intThe DTD constant corresponds to IMPLIEDstatic final intThe DTD constant corresponds to MDstatic final intThe DTD constant corresponds to MODELstatic final intThe DTD constant corresponds to MSstatic final intThe DTD constant corresponds to NAMEstatic final intThe DTD constant corresponds to NAMESstatic final intThe DTD constant corresponds to NMTOKENstatic final intThe DTD constant corresponds to NMTOKENSstatic final intThe DTD constant corresponds to NOTATIONstatic final intThe DTD constant corresponds to NUMBERstatic final intThe DTD constant corresponds to NUMBERSstatic final intThe DTD constant corresponds to NUTOKENstatic final intThe DTD constant corresponds to NUTOKENSstatic final intThe DTD constant corresponds to PARAMETERstatic final intThe DTD constant corresponds to PIstatic final intThe DTD constant corresponds to PUBLICstatic final intThe DTD constant corresponds to RCDATAstatic final intThe DTD constant corresponds to REQUIREDstatic final intThe DTD constant corresponds to SDATAstatic final intThe DTD constant corresponds to STARTTAGstatic final intThe DTD constant corresponds to SYSTEM -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidhandleEmptyTag(TagElement tag) Handle Empty Tag.protected voidhandleEndTag(TagElement tag) Handle End Tag.protected voidhandleStartTag(TagElement tag) Handle Start Tag.protected voidhandleText(char[] data) Handle Text.voidparse(Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) Parse an HTML stream, given a DTD.Methods declared in class Parser
endTag, error, error, error, error, flushAttributes, getAttributes, getCurrentLine, getCurrentPos, handleComment, handleEOFInComment, handleError, handleTitle, makeTag, makeTag, markFirstTime, parse, parseDTDMarkup, parseMarkupDeclarations, startTagModifier and TypeMethodDescriptionprotected voidendTag(boolean omitted) Handle an end tag.protected voidInvokes the error handler with the 1st, 2nd and 3rd error message argument "?".protected voidInvokes the error handler with the 2nd and 3rd error message argument "?".protected voidInvokes the error handler with the 3rd error message argument "?".protected voidInvokes the error handler.protected voidRemoves the current attributes.protected SimpleAttributeSetReturns attributes for the current tag.protected intReturns the line number of the line currently being parsed.protected intReturns the current position.protected voidhandleComment(char[] text) Called when an HTML comment is encountered.protected voidCalled when the content terminates without closing the HTML comment.protected voidhandleError(int ln, String msg) An error has occurred.protected voidhandleTitle(char[] text) Called when an HTML title tag is encountered.protected TagElementMakes a TagElement.protected TagElementMakes a TagElement.protected voidmarkFirstTime(Element elem) Marks the first time a tag has been seen in a documentvoidParse an HTML stream, given a DTD.Parses the Document Type Declaration markup declaration.protected booleanparseMarkupDeclarations(StringBuffer strBuff) Parse markup declarations.protected voidstartTag(TagElement tag) Handle a start tag.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
DocumentParser
Creates document parser with the specifieddtd.- Parameters:
dtd- the dtd.
-
-
Method Details
-
parse
public void parse(Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException Parse an HTML stream, given a DTD.- Parameters:
in- the reader to read the source fromcallback- the callbackignoreCharSet- iftruethe charset is ignored- Throws:
IOException- if an I/O error occurs
-
handleStartTag
Handle Start Tag.- Overrides:
handleStartTagin classParser- Parameters:
tag- the tag being handled
-
handleEmptyTag
Handle Empty Tag.- Overrides:
handleEmptyTagin classParser- Parameters:
tag- the tag being handled- Throws:
ChangedCharSetException- if the document charset was changed
-
handleEndTag
Handle End Tag.- Overrides:
handleEndTagin classParser- Parameters:
tag- the tag being handled
-
handleText
protected void handleText(char[] data) Handle Text.- Overrides:
handleTextin classParser- Parameters:
data- the section text
-