Package org.jsoup.parser
Class TreeBuilder
java.lang.Object
org.jsoup.parser.TreeBuilder
- Direct Known Subclasses:
HtmlTreeBuilder,XmlTreeBuilder
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) String(package private) Token(package private) Documentprivate final Token.EndTag(package private) NodeVisitorprotected Parser(package private) CharacterReader(package private) ParseSettingsprivate Token.StartTag(package private) TagSet(package private) Tokeniser(package private) boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void(package private) ElementGet the current element (last on the stack).(package private) booleancurrentElementIs(String normalName) Checks if the Current Element's normal name equals the supplied name, in the HTML namespace.(package private) booleancurrentElementIs(String normalName, String namespace) Checks if the Current Element's normal name equals the supplied name, in the specified namespace.(package private) intDefault maximum depth for parsers using this tree builder.(package private) StringGets the default namespace for this TreeBuilder(package private) abstract ParseSettings(package private) TagSet(package private) final voidEnsures the stack respectsParser.getMaxDepth()by closing the deepest open elements until there is room for a new insertion.(package private) voidIf the parser is tracking errors, add an error at the current position.(package private) voidIf the parser is tracking errors, add an error at the current position.(package private) voidinitialiseParse(Reader input, String baseUri, Parser parser) (package private) voidinitialiseParseFragment(Element context) (package private) abstract TreeBuilderCreate a new copy of this TreeBuilder(package private) voidnodeListener(NodeVisitor nodeListener) Set the node listener, which will then get callbacks for node insert and removals.(package private) voidonNodeClosed(Node node) Called by implementing TreeBuilders when a node is explicitly closed.(package private) voidonNodeInserted(Node node) Called by implementing TreeBuilders when a node has been inserted.(package private) voidonStackPrunedForDepth(Element element) Hook for the HTML Tree Builder that needs to clean up when an element is removed due to the depth limit(package private) DocumentparseFragment(Reader inputFragment, Element context, String baseUri, Parser parser) (package private) Elementpop()Removes the last Element from the stack, hits onNodeClosed, and then returns it.(package private) abstract boolean(package private) booleanprocessEndTag(String name) (package private) booleanprocessStartTag(String name) (package private) booleanprocessStartTag(String name, Attributes attrs) (package private) final voidAdds the specified Element to the end of the stack, and hits onNodeInserted.(package private) void(package private) boolean(package private) TagtagFor(String tagName, String normalName, String namespace, ParseSettings settings) (package private) Tag(package private) voidtrackNodePosition(Node node, boolean isStart)
-
Field Details
-
parser
-
reader
CharacterReader reader -
tokeniser
Tokeniser tokeniser -
doc
Document doc -
stack
-
baseUri
String baseUri -
currentToken
Token currentToken -
settings
ParseSettings settings -
tagSet
TagSet tagSet -
nodeListener
NodeVisitor nodeListener -
start
-
end
-
trackSourceRange
boolean trackSourceRange
-
-
Constructor Details
-
TreeBuilder
TreeBuilder()
-
-
Method Details
-
defaultSettings
-
initialiseParse
-
completeParse
void completeParse() -
parse
-
parseFragment
-
initialiseParseFragment
-
completeParseFragment
-
nodeListener
Set the node listener, which will then get callbacks for node insert and removals. -
newInstance
Create a new copy of this TreeBuilder- Returns:
- copy, ready for a new parse
-
runParser
void runParser() -
stepParser
boolean stepParser() -
process
-
processStartTag
-
processStartTag
-
processEndTag
-
pop
Element pop()Removes the last Element from the stack, hits onNodeClosed, and then returns it.- Returns:
-
push
Adds the specified Element to the end of the stack, and hits onNodeInserted.- Parameters:
element-
-
enforceStackDepthLimit
final void enforceStackDepthLimit()Ensures the stack respectsParser.getMaxDepth()by closing the deepest open elements until there is room for a new insertion. -
onStackPrunedForDepth
Hook for the HTML Tree Builder that needs to clean up when an element is removed due to the depth limit -
defaultMaxDepth
int defaultMaxDepth()Default maximum depth for parsers using this tree builder. -
currentElement
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
Checks if the Current Element's normal name equals the supplied name, in the HTML namespace.- Parameters:
normalName- name to check- Returns:
- true if there is a current element on the stack, and its name equals the supplied
-
currentElementIs
Checks if the Current Element's normal name equals the supplied name, in the specified namespace.- Parameters:
normalName- name to checknamespace- the namespace- Returns:
- true if there is a current element on the stack, and its name equals the supplied
-
error
If the parser is tracking errors, add an error at the current position.- Parameters:
msg- error message
-
error
If the parser is tracking errors, add an error at the current position.- Parameters:
msg- error message templateargs- template arguments
-
tagFor
-
tagFor
-
defaultNamespace
String defaultNamespace()Gets the default namespace for this TreeBuilder- Returns:
- the default namespace
-
defaultTagSet
TagSet defaultTagSet() -
onNodeInserted
Called by implementing TreeBuilders when a node has been inserted. This implementation includes optionally tracking the source range of the node. @param node the node that was just inserted -
onNodeClosed
Called by implementing TreeBuilders when a node is explicitly closed. This implementation includes optionally tracking the closing source range of the node. @param node the node being closed -
trackNodePosition
-