public class StructuredNode extends Object
StructuredInput
.
This is basically a XML node which can be queried using xpath.
Modifier | Constructor and Description |
---|---|
protected |
StructuredNode(Node root)
Wraps the given node
|
Modifier and Type | Method and Description |
---|---|
<N extends Node> |
as(Class<N> type)
Returns the underlying node casted to the given type.
|
List<StructuredNode> |
getChildren()
Returns a list of all children of this DOM node.
|
Node |
getNode()
Returns the underlying W3C Node.
|
String |
getNodeName()
Returns the current nodes name.
|
<N extends Node> |
is(Class<N> type)
Determines if the underlying node is actually an instance of the given class.
|
boolean |
isEmpty(String path)
Checks whether a node is not reachable or has empty content via the given
XPath.
|
boolean |
isFilled(String path)
Checks whether a node or non-empty content is reachable via the given
XPath.
|
static StructuredNode |
of(Node node)
Wraps the given W3C node into a structured node.
|
StructuredNode |
queryNode(String xpath)
Returns a given node at the relative path.
|
List<StructuredNode> |
queryNodeList(String xpath)
Returns a list of nodes at the relative path.
|
String |
queryString(String path)
Returns the property at the given relative path as string.
|
Value |
queryValue(String path)
Queries a
Value by evaluating the given xpath. |
String |
queryXMLString(String path)
Queries a string via the given XPath.
|
String |
toString() |
void |
visit(Consumer<StructuredNode> nodeHandler,
Consumer<Node> textNodeHandler)
Iterates through the sub-tree and invokes the appropriate handler for each child node.
|
void |
visitNodes(Consumer<StructuredNode> nodeHandler)
Iterates through the sub-tree and invokes the given handler for each child node.
|
void |
visitTexts(Consumer<Node> textNodeHandler)
Iterates through the sub-tree and invokes the given handler for each text node.
|
protected StructuredNode(Node root)
root
- the node to wrap@Nonnull public static StructuredNode of(@Nonnull Node node)
node
- the node to wrap@Nonnull public String getNodeName()
@Nonnull public Node getNode()
public <N extends Node> boolean is(Class<N> type)
N
- the node type to check fortype
- the class to check forpublic <N extends Node> N as(Class<N> type)
Used is(Class)
to check if the node actually is an instance of the target class. Otherwise a
ClassCastException will be thrown.
N
- the node type to cast totype
- the target class for the castClassCastException
- if the underlying node isn't an instance of the given class.@Nonnull public List<StructuredNode> getChildren()
@Nullable public StructuredNode queryNode(String xpath)
xpath
- the xpath used to retrieve the resulting nodeIllegalArgumentException
- if an invalid xpath was given@Nonnull public List<StructuredNode> queryNodeList(String xpath)
xpath
- the xpath used to retrieve the resulting nodesIllegalArgumentException
- if an invalid xpath was given@Nullable public String queryString(String path)
path
- the xpath used to retrieve propertyIllegalArgumentException
- if an invalid xpath was given@Nonnull public Value queryValue(String path)
Value
by evaluating the given xpath.path
- the xpath used to retrieve propertyIllegalArgumentException
- if an invalid xpath was given@Nullable public String queryXMLString(String path)
path
- the xpath used to retrieve the xml sub treeIllegalArgumentException
- if an invalid xpath was givenpublic boolean isFilled(String path)
path
- the xpath to be checkedIllegalArgumentException
- if an invalid xpath was givenpublic boolean isEmpty(String path)
path
- the xpath to be checkedIllegalArgumentException
- if an invalid xpath was givenpublic void visitNodes(Consumer<StructuredNode> nodeHandler)
nodeHandler
- the handler invoked for each child elementpublic void visitTexts(Consumer<Node> textNodeHandler)
textNodeHandler
- the handler invoked for each text nodepublic void visit(@Nullable Consumer<StructuredNode> nodeHandler, @Nullable Consumer<Node> textNodeHandler)
nodeHandler
- the handler invoked for each element nodetextNodeHandler
- the handler invoked for each text nodeCopyright © 2018. All rights reserved.