Class HtmlTreeBuilder


  • public class HtmlTreeBuilder
    extends TreeBuilder
    HTML Tree Builder; creates a DOM from Tokens.
    • Field Detail

      • TagsSearchInScope

        static final java.lang.String[] TagsSearchInScope
      • TagSearchList

        static final java.lang.String[] TagSearchList
      • TagSearchButton

        static final java.lang.String[] TagSearchButton
      • TagSearchTableScope

        static final java.lang.String[] TagSearchTableScope
      • TagSearchSelectScope

        static final java.lang.String[] TagSearchSelectScope
      • TagSearchEndTags

        static final java.lang.String[] TagSearchEndTags
      • TagThoroughSearchEndTags

        static final java.lang.String[] TagThoroughSearchEndTags
      • TagSearchSpecial

        static final java.lang.String[] TagSearchSpecial
      • TagMathMlTextIntegration

        static final java.lang.String[] TagMathMlTextIntegration
      • TagSvgHtmlIntegration

        static final java.lang.String[] TagSvgHtmlIntegration
      • baseUriSetFromDoc

        private boolean baseUriSetFromDoc
      • headElement

        private Element headElement
      • contextElement

        private Element contextElement
      • formattingElements

        private java.util.ArrayList<Element> formattingElements
      • pendingTableCharacters

        private java.util.List<Token.Character> pendingTableCharacters
      • framesetOk

        private boolean framesetOk
      • fosterInserts

        private boolean fosterInserts
      • fragmentParsing

        private boolean fragmentParsing
      • specificScopeTarget

        private final java.lang.String[] specificScopeTarget
      • maxUsedFormattingElements

        private static final int maxUsedFormattingElements
        See Also:
        Constant Field Values
    • Constructor Detail

      • HtmlTreeBuilder

        public HtmlTreeBuilder()
    • Method Detail

      • initialiseParse

        protected void initialiseParse​(java.io.Reader input,
                                       java.lang.String baseUri,
                                       Parser parser)
        Overrides:
        initialiseParse in class TreeBuilder
      • useCurrentOrForeignInsert

        boolean useCurrentOrForeignInsert​(Token token)
      • isMathmlTextIntegration

        static boolean isMathmlTextIntegration​(Element el)
      • isHtmlIntegration

        static boolean isHtmlIntegration​(Element el)
      • markInsertionMode

        void markInsertionMode()
      • framesetOk

        void framesetOk​(boolean framesetOk)
      • framesetOk

        boolean framesetOk()
      • getBaseUri

        java.lang.String getBaseUri()
      • maybeSetBaseUri

        void maybeSetBaseUri​(Element base)
      • isFragmentParsing

        boolean isFragmentParsing()
      • createElementFor

        Element createElementFor​(Token.StartTag startTag,
                                 java.lang.String namespace,
                                 boolean forcePreserveCase)
      • insertElementFor

        Element insertElementFor​(Token.StartTag startTag)
        Inserts an HTML element for the given tag)
      • insertForeignElementFor

        Element insertForeignElementFor​(Token.StartTag startTag,
                                        java.lang.String namespace)
        Inserts a foreign element. Preserves the case of the tag name and of the attributes.
      • insertFormElement

        FormElement insertFormElement​(Token.StartTag startTag,
                                      boolean onStack,
                                      boolean checkTemplateStack)
      • doInsertElement

        private void doInsertElement​(Element el,
                                     Token token)
        Inserts the Element onto the stack. All element inserts must run through this method. Performs any general tests on the Element before insertion.
        Parameters:
        el - the Element to insert and make the current element
        token - the token this element was parsed from. If null, uses a zero-width current token as intrinsic insert
      • insertCommentNode

        void insertCommentNode​(Token.Comment token)
      • insertCharacterNode

        void insertCharacterNode​(Token.Character characterToken)
        Inserts the provided character token into the current element.
      • insertCharacterToElement

        void insertCharacterToElement​(Token.Character characterToken,
                                      Element el)
        Inserts the provided character token into the provided element.
      • getStack

        java.util.ArrayList<Element> getStack()
      • onStack

        boolean onStack​(Element el)
      • onStack

        boolean onStack​(java.lang.String elName)
        Checks if there is an HTML element with the given name on the stack.
      • onStack

        private static boolean onStack​(java.util.ArrayList<Element> queue,
                                       Element element)
      • getFromStack

        Element getFromStack​(java.lang.String elName)
        Gets the nearest (lowest) HTML element with the given name from the stack.
      • removeFromStack

        boolean removeFromStack​(Element el)
      • popStackToClose

        Element popStackToClose​(java.lang.String elName)
        Pops the stack until the given HTML element is removed.
      • popStackToCloseAnyNamespace

        Element popStackToCloseAnyNamespace​(java.lang.String elName)
        Pops the stack until an element with the supplied name is removed, irrespective of namespace.
      • popStackToClose

        void popStackToClose​(java.lang.String... elNames)
        Pops the stack until one of the given HTML elements is removed.
      • clearStackToTableContext

        void clearStackToTableContext()
      • clearStackToTableBodyContext

        void clearStackToTableBodyContext()
      • clearStackToTableRowContext

        void clearStackToTableRowContext()
      • clearStackToContext

        private void clearStackToContext​(java.lang.String... nodeNames)
        Removes elements from the stack until one of the supplied HTML elements is removed.
      • insertOnStackAfter

        void insertOnStackAfter​(Element after,
                                Element in)
      • replaceInQueue

        private static void replaceInQueue​(java.util.ArrayList<Element> queue,
                                           Element out,
                                           Element in)
      • resetInsertionMode

        boolean resetInsertionMode()
        Reset the insertion mode, by searching up the stack for an appropriate insertion mode. The stack search depth is limited to maxQueueDepth.
        Returns:
        true if the insertion mode was actually changed.
      • resetBody

        void resetBody()
        Places the body back onto the stack and moves to InBody, for cases in AfterBody / AfterAfterBody when more content comes
      • inSpecificScope

        private boolean inSpecificScope​(java.lang.String targetName,
                                        java.lang.String[] baseTypes,
                                        java.lang.String[] extraTypes)
      • inSpecificScope

        private boolean inSpecificScope​(java.lang.String[] targetNames,
                                        java.lang.String[] baseTypes,
                                        java.lang.String[] extraTypes)
      • inScope

        boolean inScope​(java.lang.String[] targetNames)
      • inScope

        boolean inScope​(java.lang.String targetName)
      • inScope

        boolean inScope​(java.lang.String targetName,
                        java.lang.String[] extras)
      • inListItemScope

        boolean inListItemScope​(java.lang.String targetName)
      • inButtonScope

        boolean inButtonScope​(java.lang.String targetName)
      • inTableScope

        boolean inTableScope​(java.lang.String targetName)
      • inSelectScope

        boolean inSelectScope​(java.lang.String targetName)
      • onStackNot

        boolean onStackNot​(java.lang.String[] allowedTags)
        Tests if there is some element on the stack that is not in the provided set.
      • setHeadElement

        void setHeadElement​(Element headElement)
      • getHeadElement

        Element getHeadElement()
      • isFosterInserts

        boolean isFosterInserts()
      • setFosterInserts

        void setFosterInserts​(boolean fosterInserts)
      • setFormElement

        void setFormElement​(FormElement formElement)
      • resetPendingTableCharacters

        void resetPendingTableCharacters()
      • getPendingTableCharacters

        java.util.List<Token.Character> getPendingTableCharacters()
      • addPendingTableCharacters

        void addPendingTableCharacters​(Token.Character c)
      • generateImpliedEndTags

        void generateImpliedEndTags​(java.lang.String excludeTag)
        13.2.6.3 Closing elements that have implied end tags When the steps below require the UA to generate implied end tags, then, while the current node is a dd element, a dt element, an li element, an optgroup element, an option element, a p element, an rb element, an rp element, an rt element, or an rtc element, the UA must pop the current node off the stack of open elements. If a step requires the UA to generate implied end tags but lists an element to exclude from the process, then the UA must perform the above steps as if that element was not in the above list. When the steps below require the UA to generate all implied end tags thoroughly, then, while the current node is a caption element, a colgroup element, a dd element, a dt element, an li element, an optgroup element, an option element, a p element, an rb element, an rp element, an rt element, an rtc element, a tbody element, a td element, a tfoot element, a th element, a thead element, or a tr element, the UA must pop the current node off the stack of open elements.
        Parameters:
        excludeTag - If a step requires the UA to generate implied end tags but lists an element to exclude from the process, then the UA must perform the above steps as if that element was not in the above list.
      • generateImpliedEndTags

        void generateImpliedEndTags()
      • generateImpliedEndTags

        void generateImpliedEndTags​(boolean thorough)
        Pops HTML elements off the stack according to the implied end tag rules
        Parameters:
        thorough - if we are thorough (includes table elements etc) or not
      • closeElement

        void closeElement​(java.lang.String name)
      • isSpecial

        static boolean isSpecial​(Element el)
      • lastFormattingElement

        Element lastFormattingElement()
      • positionOfElement

        int positionOfElement​(Element el)
      • removeLastFormattingElement

        Element removeLastFormattingElement()
      • pushActiveFormattingElements

        void pushActiveFormattingElements​(Element in)
      • pushWithBookmark

        void pushWithBookmark​(Element in,
                              int bookmark)
      • checkActiveFormattingElements

        void checkActiveFormattingElements​(Element in)
      • isSameFormattingElement

        private static boolean isSameFormattingElement​(Element a,
                                                       Element b)
      • reconstructFormattingElements

        void reconstructFormattingElements()
      • clearFormattingElementsToLastMarker

        void clearFormattingElementsToLastMarker()
      • removeFromActiveFormattingElements

        void removeFromActiveFormattingElements​(Element el)
      • isInActiveFormattingElements

        boolean isInActiveFormattingElements​(Element el)
      • getActiveFormattingElement

        Element getActiveFormattingElement​(java.lang.String nodeName)
      • replaceActiveFormattingElement

        void replaceActiveFormattingElement​(Element out,
                                            Element in)
      • insertMarkerToFormattingElements

        void insertMarkerToFormattingElements()
      • insertInFosterParent

        void insertInFosterParent​(Node in)
      • templateModeSize

        int templateModeSize()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isContentForTagData

        protected boolean isContentForTagData​(java.lang.String normalName)
        Description copied from class: TreeBuilder
        (An internal method, visible for Element. For HTML parse, signals that script and style text should be treated as Data Nodes).
        Overrides:
        isContentForTagData in class TreeBuilder