Class TreeBuilder

java.lang.Object
org.jsoup.parser.TreeBuilder
Direct Known Subclasses:
HtmlTreeBuilder, XmlTreeBuilder

abstract class TreeBuilder extends Object
  • Field Details

  • Constructor Details

    • TreeBuilder

      TreeBuilder()
  • Method Details

    • defaultSettings

      abstract ParseSettings defaultSettings()
    • initialiseParse

      @ParametersAreNonnullByDefault protected void initialiseParse(Reader input, String baseUri, Parser parser)
    • parse

      @ParametersAreNonnullByDefault Document parse(Reader input, String baseUri, Parser parser)
    • newInstance

      abstract TreeBuilder newInstance()
      Create a new copy of this TreeBuilder
      Returns:
      copy, ready for a new parse
    • parseFragment

      abstract List<Node> parseFragment(String inputFragment, Element context, String baseUri, Parser parser)
    • runParser

      protected void runParser()
    • process

      protected abstract boolean process(Token token)
    • processStartTag

      protected boolean processStartTag(String name)
    • processStartTag

      public boolean processStartTag(String name, Attributes attrs)
    • processEndTag

      protected boolean processEndTag(String name)
    • currentElement

      protected Element currentElement()
      Get the current element (last on the stack). If all items have been removed, returns the document instead (which might not actually be on the stack; use stack.size() == 0 to test if required.
      Returns:
      the last element on the stack, if any; or the root document
    • currentElementIs

      protected boolean currentElementIs(String normalName)
      Checks if the Current Element's normal name equals the supplied name.
      Parameters:
      normalName - name to check
      Returns:
      true if there is a current element on the stack, and its name equals the supplied
    • error

      protected void error(String msg)
      If the parser is tracking errors, add an error at the current position.
      Parameters:
      msg - error message
    • error

      protected void error(String msg, Object... args)
      If the parser is tracking errors, add an error at the current position.
      Parameters:
      msg - error message template
      args - template arguments
    • isContentForTagData

      protected boolean isContentForTagData(String normalName)
      (An internal method, visible for Element. For HTML parse, signals that script and style text should be treated as Data Nodes).
    • tagFor

      protected Tag tagFor(String tagName, ParseSettings settings)
    • onNodeInserted

      protected void onNodeInserted(Node node, @Nullable Token token)
      Called by implementing TreeBuilders when a node has been inserted. This implementation includes optionally tracking the source range of the node.
      Parameters:
      node - the node that was just inserted
      token - the (optional) token that created this node
    • onNodeClosed

      protected void onNodeClosed(Node node, Token token)
      Called by implementing TreeBuilders when a node is explicitly closed. This implementation includes optionally tracking the closing source range of the node.
      Parameters:
      node - the node being closed
      token - the end-tag token that closed this node
    • trackNodePosition

      private void trackNodePosition(Node node, @Nullable Token token, boolean start)