Package nu.validator.htmlparser.impl
Class TreeBuilder<T>
java.lang.Object
nu.validator.htmlparser.impl.TreeBuilder<T>
- All Implemented Interfaces:
TokenHandler,TreeBuilderState<T>
- Direct Known Subclasses:
CoalescingTreeBuilder
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected char[]protected intprotected ErrorHandlerprotected Tokenizer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaccumulateCharacters(char[] buf, int start, int length) protected abstract voidaddAttributesToElement(T element, HtmlAttributes attributes) protected abstract voidappendCharacters(T parent, char[] buf, int start, int length) protected abstract voidappendChildrenToNewParent(T oldParent, T newParent) protected abstract voidappendComment(T parent, char[] buf, int start, int length) protected abstract voidappendCommentToDocument(char[] buf, int start, int length) protected voidappendDoctypeToDocument(String name, String publicIdentifier, String systemIdentifier) protected abstract voidappendElement(T child, T newParent) booleanChecks if the CDATA sections are allowed.final voidcharacters(char[] buf, int start, int length) Receive character tokens.final voidcomment(char[] buf, int start, int length) Receive a comment token.protected abstract TcreateAndInsertFosterParentedElement(String ns, String name, HtmlAttributes attributes, T table, T stackParent) protected TcreateAndInsertFosterParentedElement(String ns, String name, HtmlAttributes attributes, T form, T table, T stackParent) protected abstract TcreateElement(String ns, String name, HtmlAttributes attributes, T intendedParent) protected TcreateElement(String ns, String name, HtmlAttributes attributes, T form, T intendedParent) protected abstract TcreateHtmlElementSetAsRoot(HtmlAttributes attributes) protected final Tprotected abstract voiddetachFromParent(T element) final voidReceive a doctype token.protected voiddocumentMode(DocumentMode m, String publicIdentifier, String systemIdentifier) booleandropBufferIfLongerThan(int length) protected voidelementPopped(String ns, String name, T node) protected voidelementPushed(String ns, String name, T node) protected voidend()final voidendTag(ElementName elementName) Receive an end tag token.final voidThe perform final cleanup.voidensureBufferSpace(int inputLength) Notifies the token handler of the worst case amount of data to be reported viacharacters()andzeroOriginatingReplacementCharacter().final voideof()The end-of-file token.static StringextractCharsetFromContent(String attributeValue) C++ memory note: The return value must be released.protected voidfatal()Reports an condition that would make the infoset incompatible with XML 1.0 as fatal.protected final voidfinal voidFlushes the pending characters.Returns the errorHandler.Returns the formPointer.Returns the headPointer.nu.validator.htmlparser.impl.StackNode<T>[]Returns the listOfActiveFormattingElements.intReturn the length of the list of active formatting elements.intgetMode()Returns the mode.intReturns the originalMode.nu.validator.htmlparser.impl.StackNode<T>[]getStack()Returns the stack.intReturn the length of the stack.int[]Returns the stack of template insertion modes.intReturn the length of the stack of template insertion modes.protected abstract booleanhasChildren(T element) protected abstract voidinsertFosterParentedCharacters(char[] buf, int start, int length, T table, T stackParent) protected abstract voidinsertFosterParentedChild(T child, T table, T stackParent) booleanbooleanReturns the framesetOk.booleanReturns the needToDropLF.booleanisQuirks()Returns the quirks.booleanReturns the scriptingEnabled.voidloadState(TreeBuilderState<T> snapshot) protected voidmarkMalformedIfScript(T elt) Creates a comparable snapshot of the tree builder state.protected final voidvoidsetAllowDeclarativeShadowRoots(boolean allow) voidsetDocumentModeHandler(DocumentModeHandler documentModeHandler) Sets the documentModeHandler.final voidsetErrorHandler(ErrorHandler errorHandler) Sets the errorHandler.voidsetForceNoQuirks(boolean forceNoQuirks) final voidsetFragmentContext(String context) The argument MUST be an interned string ornull.final voidsetFragmentContext(String context, String ns, T node, boolean quirks) The argument MUST be an interned string ornull.voidsetIgnoringComments(boolean ignoreComments) voidsetIsSrcdocDocument(boolean isSrcdocDocument) voidsetKeepBuffer(boolean keepBuffer) voidsetNamePolicy(XmlViolationPolicy namePolicy) voidsetReportingDoctype(boolean reportingDoctype) Sets the reportingDoctype.voidsetScriptingEnabled(boolean scriptingEnabled) Sets the scriptingEnabled.booleansnapshotMatches(TreeBuilderState<T> snapshot) protected voidstart(boolean fragmentMode) final voidstartTag(ElementName elementName, HtmlAttributes attributes, boolean selfClosing) Receive a start tag token.final voidstartTokenization(Tokenizer self) This method is called at the start of tokenization before any other methods on this interface are called.booleanIf this handler implementation cares about comments, returntrue.voidReports a U+0000 that's being turned into a U+FFFD.voidEmits: * U+0000 if only tokenization is being performed * U+FFFD if tree construction is being performed also
-
Field Details
-
tokenizer
-
errorHandler
-
charBuffer
protected char[] charBuffer -
charBufferLen
protected int charBufferLen
-
-
Constructor Details
-
TreeBuilder
protected TreeBuilder()
-
-
Method Details
-
fatal
Reports an condition that would make the infoset incompatible with XML 1.0 as fatal.- Throws:
SAXExceptionSAXParseException
-
fatal
- Throws:
SAXException
-
setKeepBuffer
public void setKeepBuffer(boolean keepBuffer) -
dropBufferIfLongerThan
public boolean dropBufferIfLongerThan(int length) -
startTokenization
Description copied from interface:TokenHandlerThis method is called at the start of tokenization before any other methods on this interface are called. Implementations should hold the reference to theTokenizerin order to set the content model flag and in order to be able to query forLocatordata.- Specified by:
startTokenizationin interfaceTokenHandler- Parameters:
self- theTokenizer.- Throws:
SAXException- if something went wrong
-
doctype
public final void doctype(String name, String publicIdentifier, String systemIdentifier, boolean forceQuirks) throws SAXException Description copied from interface:TokenHandlerReceive a doctype token.- Specified by:
doctypein interfaceTokenHandler- Parameters:
name- the namepublicIdentifier- the public idsystemIdentifier- the system idforceQuirks- whether the token is correct- Throws:
SAXException- if something went wrong
-
comment
Description copied from interface:TokenHandlerReceive a comment token. The data is junk if thewantsComments()returnedfalse.- Specified by:
commentin interfaceTokenHandler- Parameters:
buf- a buffer holding the datastart- the offset into the bufferlength- the number of code units to read- Throws:
SAXException- if something went wrong
-
characters
Description copied from interface:TokenHandlerReceive character tokens. This method has the same semantics as the SAX method of the same name.- Specified by:
charactersin interfaceTokenHandler- Parameters:
buf- a buffer holding the datastart- offset into the bufferlength- the number of code units to read- Throws:
SAXException- if something went wrong- See Also:
-
zeroOriginatingReplacementCharacter
Description copied from interface:TokenHandlerReports a U+0000 that's being turned into a U+FFFD.- Specified by:
zeroOriginatingReplacementCharacterin interfaceTokenHandler- Throws:
SAXException- if something went wrong- See Also:
-
zeroOrReplacementCharacter
Description copied from interface:TokenHandlerEmits: * U+0000 if only tokenization is being performed * U+FFFD if tree construction is being performed also- Specified by:
zeroOrReplacementCharacterin interfaceTokenHandler- Throws:
SAXException- if something went wrong- See Also:
-
eof
Description copied from interface:TokenHandlerThe end-of-file token.- Specified by:
eofin interfaceTokenHandler- Throws:
SAXException- if something went wrong
-
endTokenization
Description copied from interface:TokenHandlerThe perform final cleanup.- Specified by:
endTokenizationin interfaceTokenHandler- Throws:
SAXException- if something went wrong- See Also:
-
startTag
public final void startTag(ElementName elementName, HtmlAttributes attributes, boolean selfClosing) throws SAXException Description copied from interface:TokenHandlerReceive a start tag token.- Specified by:
startTagin interfaceTokenHandler- Parameters:
elementName- the tag nameattributes- the attributesselfClosing- TODO- Throws:
SAXException- if something went wrong
-
extractCharsetFromContent
C++ memory note: The return value must be released.
- Returns:
-
endTag
Description copied from interface:TokenHandlerReceive an end tag token.- Specified by:
endTagin interfaceTokenHandler- Parameters:
elementName- the tag name- Throws:
SAXException- if something went wrong
-
ensureBufferSpace
Description copied from interface:TokenHandlerNotifies the token handler of the worst case amount of data to be reported viacharacters()andzeroOriginatingReplacementCharacter().- Specified by:
ensureBufferSpacein interfaceTokenHandler- Parameters:
inputLength- the maximum number of chars that can be reported viacharacters()andzeroOriginatingReplacementCharacter()before a new call to this method.- Throws:
SAXException
-
accumulateCharacters
- Throws:
SAXException
-
requestSuspension
protected final void requestSuspension() -
createElement
protected abstract T createElement(String ns, String name, HtmlAttributes attributes, T intendedParent) throws SAXException - Throws:
SAXException
-
createElement
protected T createElement(String ns, String name, HtmlAttributes attributes, T form, T intendedParent) throws SAXException - Throws:
SAXException
-
createHtmlElementSetAsRoot
- Throws:
SAXException
-
detachFromParent
- Throws:
SAXException
-
hasChildren
- Throws:
SAXException
-
appendElement
- Throws:
SAXException
-
appendChildrenToNewParent
- Throws:
SAXException
-
insertFosterParentedChild
protected abstract void insertFosterParentedChild(T child, T table, T stackParent) throws SAXException - Throws:
SAXException
-
createAndInsertFosterParentedElement
protected abstract T createAndInsertFosterParentedElement(String ns, String name, HtmlAttributes attributes, T table, T stackParent) throws SAXException - Throws:
SAXException
-
createAndInsertFosterParentedElement
protected T createAndInsertFosterParentedElement(String ns, String name, HtmlAttributes attributes, T form, T table, T stackParent) throws SAXException - Throws:
SAXException
-
insertFosterParentedCharacters
protected abstract void insertFosterParentedCharacters(char[] buf, int start, int length, T table, T stackParent) throws SAXException - Throws:
SAXException
-
appendCharacters
protected abstract void appendCharacters(T parent, char[] buf, int start, int length) throws SAXException - Throws:
SAXException
-
appendComment
protected abstract void appendComment(T parent, char[] buf, int start, int length) throws SAXException - Throws:
SAXException
-
appendCommentToDocument
protected abstract void appendCommentToDocument(char[] buf, int start, int length) throws SAXException - Throws:
SAXException
-
addAttributesToElement
protected abstract void addAttributesToElement(T element, HtmlAttributes attributes) throws SAXException - Throws:
SAXException
-
markMalformedIfScript
- Throws:
SAXException
-
start
- Throws:
SAXException
-
end
- Throws:
SAXException
-
appendDoctypeToDocument
protected void appendDoctypeToDocument(String name, String publicIdentifier, String systemIdentifier) throws SAXException - Throws:
SAXException
-
elementPushed
- Throws:
SAXException
-
elementPopped
- Throws:
SAXException
-
documentMode
protected void documentMode(DocumentMode m, String publicIdentifier, String systemIdentifier) throws SAXException - Throws:
SAXException
-
wantsComments
public boolean wantsComments()Description copied from interface:TokenHandlerIf this handler implementation cares about comments, returntrue. If not, returnfalse.- Specified by:
wantsCommentsin interfaceTokenHandler- Returns:
- whether this handler wants comments
- See Also:
-
setIgnoringComments
public void setIgnoringComments(boolean ignoreComments) -
setErrorHandler
Sets the errorHandler.- Parameters:
errorHandler- the errorHandler to set
-
getErrorHandler
Returns the errorHandler.- Returns:
- the errorHandler
-
setFragmentContext
The argument MUST be an interned string ornull.- Parameters:
context-
-
cdataSectionAllowed
Description copied from interface:TokenHandlerChecks if the CDATA sections are allowed.- Specified by:
cdataSectionAllowedin interfaceTokenHandler- Returns:
trueif CDATA sections are allowed- Throws:
SAXException- if something went wrong- See Also:
-
setFragmentContext
The argument MUST be an interned string ornull.- Parameters:
context-
-
currentNode
-
isScriptingEnabled
public boolean isScriptingEnabled()Returns the scriptingEnabled.- Returns:
- the scriptingEnabled
-
setScriptingEnabled
public void setScriptingEnabled(boolean scriptingEnabled) Sets the scriptingEnabled.- Parameters:
scriptingEnabled- the scriptingEnabled to set
-
setForceNoQuirks
public void setForceNoQuirks(boolean forceNoQuirks) -
setIsSrcdocDocument
public void setIsSrcdocDocument(boolean isSrcdocDocument) -
isAllowDeclarativeShadowRoots
public boolean isAllowDeclarativeShadowRoots() -
setAllowDeclarativeShadowRoots
public void setAllowDeclarativeShadowRoots(boolean allow) -
setNamePolicy
-
setDocumentModeHandler
Sets the documentModeHandler.- Parameters:
documentModeHandler- the documentModeHandler to set
-
setReportingDoctype
public void setReportingDoctype(boolean reportingDoctype) Sets the reportingDoctype.- Parameters:
reportingDoctype- the reportingDoctype to set
-
flushCharacters
Flushes the pending characters. Public for document.write use cases only.- Throws:
SAXException
-
newSnapshot
Creates a comparable snapshot of the tree builder state. Snapshot creation is only supported immediately after a script end tag has been processed. In C++ the caller is responsible for callingdeleteon the returned object.- Returns:
- a snapshot.
- Throws:
SAXException
-
snapshotMatches
-
loadState
- Throws:
SAXException
-
getFormPointer
Description copied from interface:TreeBuilderStateReturns the formPointer.- Specified by:
getFormPointerin interfaceTreeBuilderState<T>- Returns:
- the formPointer
- See Also:
-
getHeadPointer
Returns the headPointer.- Specified by:
getHeadPointerin interfaceTreeBuilderState<T>- Returns:
- the headPointer
-
getListOfActiveFormattingElements
Description copied from interface:TreeBuilderStateReturns the listOfActiveFormattingElements.- Specified by:
getListOfActiveFormattingElementsin interfaceTreeBuilderState<T>- Returns:
- the listOfActiveFormattingElements
- See Also:
-
getStack
Description copied from interface:TreeBuilderStateReturns the stack.- Specified by:
getStackin interfaceTreeBuilderState<T>- Returns:
- the stack
- See Also:
-
getTemplateModeStack
public int[] getTemplateModeStack()Description copied from interface:TreeBuilderStateReturns the stack of template insertion modes.- Specified by:
getTemplateModeStackin interfaceTreeBuilderState<T>- Returns:
- the stack of template insertion modes
- See Also:
-
getMode
public int getMode()Returns the mode.- Specified by:
getModein interfaceTreeBuilderState<T>- Returns:
- the mode
-
getOriginalMode
public int getOriginalMode()Returns the originalMode.- Specified by:
getOriginalModein interfaceTreeBuilderState<T>- Returns:
- the originalMode
-
isFramesetOk
public boolean isFramesetOk()Returns the framesetOk.- Specified by:
isFramesetOkin interfaceTreeBuilderState<T>- Returns:
- the framesetOk
-
isNeedToDropLF
public boolean isNeedToDropLF()Returns the needToDropLF.- Specified by:
isNeedToDropLFin interfaceTreeBuilderState<T>- Returns:
- the needToDropLF
-
isQuirks
public boolean isQuirks()Returns the quirks.- Specified by:
isQuirksin interfaceTreeBuilderState<T>- Returns:
- the quirks
-
getListOfActiveFormattingElementsLength
public int getListOfActiveFormattingElementsLength()Description copied from interface:TreeBuilderStateReturn the length of the list of active formatting elements.- Specified by:
getListOfActiveFormattingElementsLengthin interfaceTreeBuilderState<T>- Returns:
- the length of the list of active formatting elements.
- See Also:
-
getStackLength
public int getStackLength()Description copied from interface:TreeBuilderStateReturn the length of the stack.- Specified by:
getStackLengthin interfaceTreeBuilderState<T>- Returns:
- the length of the stack.
- See Also:
-
getTemplateModeStackLength
public int getTemplateModeStackLength()Description copied from interface:TreeBuilderStateReturn the length of the stack of template insertion modes.- Specified by:
getTemplateModeStackLengthin interfaceTreeBuilderState<T>- Returns:
- the length of the stack of template insertion modes.
- See Also:
-