public abstract class Node
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
Node.NodeType
Node types.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.List<Attribute> |
attributes |
protected Element[] |
childElementNodes |
protected int |
childElementNodesCount |
protected java.util.List<Node> |
childNodes |
protected java.lang.String |
nodeName |
protected java.lang.String |
nodeRawName |
protected Node.NodeType |
nodeType |
protected java.lang.String |
nodeValue |
protected Document |
ownerDocument |
protected Node |
parentNode |
protected int |
siblingElementIndex |
protected int |
siblingIndex |
protected int |
siblingNameIndex |
Modifier | Constructor and Description |
---|---|
protected |
Node(Document document,
Node.NodeType nodeType,
java.lang.String nodeName)
Creates new node.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Node... nodes)
Appends several child nodes at once.
|
void |
addChild(Node node)
Appends child node.
|
void |
appendTextContent(java.lang.Appendable appendable)
Appends the text content to an
Appendable
(StringBuilder , CharBuffer ...). |
protected void |
changeOwnerDocument(Node node,
Document ownerDocument)
Changes owner document for given node and all its children.
|
boolean |
check()
Checks the health of child nodes.
|
abstract Node |
clone() |
protected <T extends Node> |
cloneTo(T dest)
Copies all non-final values to the empty cloned object.
|
void |
detachFromParent()
Removes this node from DOM tree.
|
Node[] |
filterChildNodes(java.util.function.Predicate<Node> nodePredicate)
Filters child nodes.
|
Node |
findChildNodeWithName(java.lang.String name)
Finds the first child node with given node name.
|
Attribute |
getAttribute(int index)
Returns attribute at given index or
null if index not found. |
java.lang.String |
getAttribute(java.lang.String name)
Returns attribute value.
|
protected Attribute |
getAttributeInstance(java.lang.String name) |
int |
getAttributesCount()
Returns total number of attributes.
|
Node |
getChild(int... indexes)
Returns a child node with given hierarchy.
|
Node |
getChild(int index)
Returns a child node at given index or
null
if child doesn't exist for that index. |
Element |
getChildElement(int index)
Returns a child element node at given index.
|
Element[] |
getChildElements()
Returns an array of all children elements.
|
int |
getChildElementsCount()
Returns number of child elements.
|
int |
getChildElementsCount(java.lang.String elementName)
Returns number of child elements with given name.
|
Node[] |
getChildNodes()
Returns an array of all children nodes.
|
int |
getChildNodesCount()
Returns number of all child nodes.
|
java.lang.String |
getCssPath()
Returns CSS path to this node from document root.
|
Node |
getFirstChild()
Returns first child or
null if no children exist. |
Element |
getFirstChildElement()
Returns first child element node or
null if no element children exist. |
Element |
getFirstChildElement(java.lang.String elementName)
Returns first child element with given name or
null if no such children exist. |
java.lang.String |
getHtml()
Generates HTML.
|
java.lang.String |
getInnerHtml()
Generates inner HTML.
|
Node |
getLastChild()
Returns last child or
null if no children exist. |
Element |
getLastChildElement()
Returns last child element node or
null if no such child node exist. |
Element |
getLastChildElement(java.lang.String elementName)
Returns last child element with given name or
null if no such child node exist. |
Node |
getNextSibling()
Returns this node's next sibling of any type or
null if this is the last sibling. |
Node |
getNextSiblingElement()
Returns this node's next element.
|
Node |
getNextSiblingName()
Returns this node's next element with the same name.
|
java.lang.String |
getNodeName()
Returns nodes name or
null if name is not available. |
java.lang.String |
getNodeRawName()
Returns nodes raw name - exactly as it was given in the input.
|
Node.NodeType |
getNodeType()
Returns
node type . |
java.lang.String |
getNodeValue()
Returns node value or
null if value is not available. |
Document |
getOwnerDocument()
Returns owner document, root node for this DOM tree.
|
Node |
getParentNode()
Returns parent node or
null if no parent exist. |
Node |
getPreviousSibling()
Returns this node's previous sibling of any type
or
null if this is the first sibling. |
Node |
getPreviousSiblingElement()
Returns this node's previous sibling of element type
or
null if this is the first sibling. |
Node |
getPreviousSiblingName()
Returns this node's previous sibling element with the same name.
|
int |
getSiblingElementIndex() |
int |
getSiblingIndex()
Get the list index of this node in its node sibling list.
|
int |
getSiblingNameIndex() |
java.lang.String |
getTextContent()
Returns the text content of this node and its descendants.
|
boolean |
hasAttribute(java.lang.String name)
Returns
true if node contains an attribute. |
boolean |
hasAttributes()
Returns
true if node has attributes. |
boolean |
hasChildNodes()
Returns
true if node has child nodes. |
protected int |
indexOfAttributeInstance(java.lang.String name) |
protected void |
initAttributes()
Initializes attributes when needed.
|
protected void |
initChildElementNodes()
Initializes list of child elements.
|
protected void |
initChildNodes(Node newNode)
Initializes child nodes list when needed.
|
protected void |
initSiblingNames()
Initializes siblings elements of the same name.
|
void |
insertAfter(Node[] newChilds,
Node refChild)
Inserts several child nodes after referent node.
|
void |
insertAfter(Node newChild,
Node refChild)
Inserts node after provided node.
|
void |
insertBefore(Node[] newChilds,
Node refChild)
Inserts several child nodes before provided node.
|
void |
insertBefore(Node newChild,
Node refChild)
Inserts node before provided node.
|
void |
insertChild(Node[] nodes,
int index)
Inserts several nodes at ones.
|
void |
insertChild(Node node,
int index)
Inserts node at given index.
|
boolean |
isAttributeContaining(java.lang.String name,
java.lang.String word)
Returns
true if attribute containing some word. |
protected void |
reindexChildren()
Reindex children nodes.
|
protected void |
reindexChildrenOnAdd(int addedCount)
Optimized variant of
reindexChildren() for addition. |
void |
removeAllChilds()
Removes all child nodes.
|
boolean |
removeAttribute(java.lang.String name) |
Node |
removeChild(int index)
Removes child node at given index.
|
void |
removeChild(Node childNode)
Removes child node.
|
void |
setAttribute(java.lang.String name)
Sets attribute that doesn't need a value.
|
void |
setAttribute(java.lang.String name,
java.lang.String value)
Sets attribute value.
|
void |
setNodeValue(java.lang.String value)
Sets node value.
|
void |
visit(NodeVisitor nodeVisitor)
Visits the DOM tree.
|
protected void |
visitChildren(NodeVisitor nodeVisitor)
Visits children nodes.
|
protected abstract void |
visitNode(NodeVisitor nodeVisitor)
Visits single node.
|
protected final java.lang.String nodeName
protected final java.lang.String nodeRawName
protected final Node.NodeType nodeType
protected Document ownerDocument
protected java.lang.String nodeValue
protected java.util.List<Attribute> attributes
protected Node parentNode
protected java.util.List<Node> childNodes
protected int childElementNodesCount
protected Element[] childElementNodes
protected int siblingIndex
protected int siblingElementIndex
protected int siblingNameIndex
protected Node(Document document, Node.NodeType nodeType, java.lang.String nodeName)
protected <T extends Node> T cloneTo(T dest)
public abstract Node clone()
clone
in class java.lang.Object
public Node.NodeType getNodeType()
node type
.public java.lang.String getNodeName()
null
if name is not available.public java.lang.String getNodeRawName()
public java.lang.String getNodeValue()
null
if value is not available.public void setNodeValue(java.lang.String value)
public Document getOwnerDocument()
public void detachFromParent()
public void addChild(Node node)
reindexChildren()
.public void addChild(Node... nodes)
public void insertChild(Node node, int index)
public void insertChild(Node[] nodes, int index)
public void insertBefore(Node newChild, Node refChild)
public void insertBefore(Node[] newChilds, Node refChild)
public void insertAfter(Node[] newChilds, Node refChild)
public Node removeChild(int index)
null
if index is invalid.public void removeChild(Node childNode)
public void removeAllChilds()
public Node getParentNode()
null
if no parent exist.public boolean hasAttributes()
true
if node has attributes.public int getAttributesCount()
public Attribute getAttribute(int index)
null
if index not found.public boolean hasAttribute(java.lang.String name)
true
if node contains an attribute.public java.lang.String getAttribute(java.lang.String name)
null
when
attribute doesn't exist or when attribute exist but doesn't
specify a value.protected Attribute getAttributeInstance(java.lang.String name)
protected int indexOfAttributeInstance(java.lang.String name)
public boolean removeAttribute(java.lang.String name)
public void setAttribute(java.lang.String name, java.lang.String value)
null
.public void setAttribute(java.lang.String name)
public boolean isAttributeContaining(java.lang.String name, java.lang.String word)
true
if attribute containing some word.public boolean hasChildNodes()
true
if node has child nodes.public int getChildNodesCount()
public int getChildElementsCount()
public int getChildElementsCount(java.lang.String elementName)
public Node[] getChildNodes()
public Node findChildNodeWithName(java.lang.String name)
public Node[] filterChildNodes(java.util.function.Predicate<Node> nodePredicate)
public Element[] getChildElements()
public Node getChild(int index)
null
if child doesn't exist for that index.public Node getChild(int... indexes)
getChild(int)
.public Element getChildElement(int index)
null
is returned.public Node getFirstChild()
null
if no children exist.public Element getFirstChildElement()
null
if no element children exist.public Element getFirstChildElement(java.lang.String elementName)
null
if no such children exist.public Node getLastChild()
null
if no children exist.public Element getLastChildElement()
null
if no such child node exist.public Element getLastChildElement(java.lang.String elementName)
null
if no such child node exist.public boolean check()
protected void reindexChildren()
childNodes
list and:
protected void reindexChildrenOnAdd(int addedCount)
reindexChildren()
for addition.
Only added children are optimized.protected void initChildElementNodes()
protected void initSiblingNames()
protected void initAttributes()
protected void initChildNodes(Node newNode)
protected void changeOwnerDocument(Node node, Document ownerDocument)
public int getSiblingIndex()
public int getSiblingElementIndex()
public int getSiblingNameIndex()
public Node getNextSibling()
null
if this is the last sibling.public Node getNextSiblingElement()
public Node getNextSiblingName()
public Node getPreviousSibling()
null
if this is the first sibling.public Node getPreviousSiblingElement()
null
if this is the first sibling.public Node getPreviousSiblingName()
public java.lang.String getTextContent()
appendTextContent(Appendable)
public void appendTextContent(java.lang.Appendable appendable)
Appendable
(StringBuilder
, CharBuffer
...).
This way we can reuse the Appendable
instance
during the creation of text content and have better performances.public java.lang.String getHtml()
public java.lang.String getInnerHtml()
public void visit(NodeVisitor nodeVisitor)
protected void visitChildren(NodeVisitor nodeVisitor)
protected abstract void visitNode(NodeVisitor nodeVisitor)
public java.lang.String getCssPath()
Copyright © 2003-present Jodd Team