Class Node
java.lang.Object
jodd.lagarto.dom.Node
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
CData, Comment, Document, DocumentType, Element, Text, XmlDeclaration
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNode(Document document, Node.NodeType nodeType, String nodeName) Creates new node. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends child node.voidAppends several child nodes at once.voidappendTextContent(Appendable appendable) Appends the text content to anAppendable(StringBuilder,CharBuffer...).protected voidchangeOwnerDocument(Node node, Document ownerDocument) Changes owner document for given node and all its children.booleancheck()Checks the health of child nodes.abstract Nodeclone()protected <T extends Node>
TcloneTo(T dest) Copies all non-final values to the empty cloned object.voidRemoves this node from DOM tree.Node[]filterChildNodes(Predicate<Node> nodePredicate) Filters child nodes.findChildNodeWithName(String name) Finds the first child node with given node name.getAttribute(int index) Returns attribute at given index ornullif index not found.getAttribute(String name) Returns attribute value.protected AttributegetAttributeInstance(String name) intReturns total number of attributes.getChild(int index) Returns a child node at given index ornullif child doesn't exist for that index.getChild(int... indexes) Returns a child node with given hierarchy.getChildElement(int index) Returns a child element node at given index.Element[]Returns an array of all children elements.intReturns number of child elements.intgetChildElementsCount(String elementName) Returns number of child elements with given name.Node[]Returns an array of all children nodes.intReturns number of all child nodes.Returns CSS path to this node from document root.Returns first child ornullif no children exist.Returns first child element node ornullif no element children exist.getFirstChildElement(String elementName) Returns first child element with given name ornullif no such children exist.getHtml()Generates HTML.Generates inner HTML.Returns last child ornullif no children exist.Returns last child element node ornullif no such child node exist.getLastChildElement(String elementName) Returns last child element with given name ornullif no such child node exist.Returns this node's next sibling of any type ornullif this is the last sibling.Returns this node's next element.Returns this node's next element with the same name.Returns nodes name ornullif name is not available.Returns nodes raw name - exactly as it was given in the input.Returnsnode type.Returns node value ornullif value is not available.Returns owner document, root node for this DOM tree.Returns parent node ornullif no parent exist.Returns this node's previous sibling of any type ornullif this is the first sibling.Returns this node's previous sibling of element type ornullif this is the first sibling.Returns this node's previous sibling element with the same name.intintGet the list index of this node in its node sibling list.intReturns the text content of this node and its descendants.booleanhasAttribute(String name) Returnstrueif node contains an attribute.booleanReturnstrueif node has attributes.booleanReturnstrueif node has child nodes.protected intprotected voidInitializes attributes when needed.protected voidInitializes list of child elements.protected voidinitChildNodes(Node newNode) Initializes child nodes list when needed.protected voidInitializes siblings elements of the same name.voidinsertAfter(Node[] newChilds, Node refChild) Inserts several child nodes after referent node.voidinsertAfter(Node newChild, Node refChild) Inserts node after provided node.voidinsertBefore(Node[] newChilds, Node refChild) Inserts several child nodes before provided node.voidinsertBefore(Node newChild, Node refChild) Inserts node before provided node.voidinsertChild(Node[] nodes, int index) Inserts several nodes at ones.voidinsertChild(Node node, int index) Inserts node at given index.booleanisAttributeContaining(String name, String word) Returnstrueif attribute containing some word.protected voidReindex children nodes.protected voidreindexChildrenOnAdd(int addedCount) Optimized variant ofreindexChildren()for addition.voidRemoves all child nodes.booleanremoveAttribute(String name) removeChild(int index) Removes child node at given index.voidremoveChild(Node childNode) Removes child node.voidsetAttribute(String name) Sets attribute that doesn't need a value.voidsetAttribute(String name, String value) Sets attribute value.voidsetNodeValue(String value) Sets node value.voidvisit(NodeVisitor nodeVisitor) Visits the DOM tree.voidvisitChildren(NodeVisitor nodeVisitor) Visits children nodes.protected abstract voidvisitNode(NodeVisitor nodeVisitor) Visits single node.
-
Field Details
-
nodeName
-
nodeRawName
-
nodeType
-
ownerDocument
-
nodeValue
-
attributes
-
parentNode
-
childNodes
-
childElementNodesCount
protected int childElementNodesCount -
childElementNodes
-
siblingIndex
protected int siblingIndex -
siblingElementIndex
protected int siblingElementIndex -
siblingNameIndex
protected int siblingNameIndex
-
-
Constructor Details
-
Node
Creates new node.
-
-
Method Details
-
cloneTo
Copies all non-final values to the empty cloned object. Cache-related values are not copied. -
clone
-
getNodeType
Returnsnode type. -
getNodeName
Returns nodes name ornullif name is not available. -
getNodeRawName
Returns nodes raw name - exactly as it was given in the input. -
getNodeValue
Returns node value ornullif value is not available. -
setNodeValue
Sets node value. -
getOwnerDocument
Returns owner document, root node for this DOM tree. -
detachFromParent
public void detachFromParent()Removes this node from DOM tree. -
addChild
Appends child node. Don't use this node in the loop, since it might be slow due toreindexChildren(). -
addChild
Appends several child nodes at once. Reindex is done only once, after all children are added. -
insertChild
Inserts node at given index. -
insertChild
Inserts several nodes at ones. Reindex is done onl once, after all children are added. -
insertBefore
-
insertBefore
-
insertAfter
-
insertAfter
-
removeChild
Removes child node at given index. Returns removed node ornullif index is invalid. -
removeChild
Removes child node. It works only with direct children, i.e. if provided child node is not a child nothing happens. -
removeAllChilds
public void removeAllChilds()Removes all child nodes. Each child node will be detached from this parent. -
getParentNode
Returns parent node ornullif no parent exist. -
hasAttributes
public boolean hasAttributes()Returnstrueif node has attributes. -
getAttributesCount
public int getAttributesCount()Returns total number of attributes. -
getAttribute
Returns attribute at given index ornullif index not found. -
hasAttribute
Returnstrueif node contains an attribute. -
getAttribute
-
getAttributeInstance
-
indexOfAttributeInstance
-
removeAttribute
-
setAttribute
-
setAttribute
Sets attribute that doesn't need a value. -
isAttributeContaining
-
hasChildNodes
public boolean hasChildNodes()Returnstrueif node has child nodes. -
getChildNodesCount
public int getChildNodesCount()Returns number of all child nodes. -
getChildElementsCount
public int getChildElementsCount()Returns number of child elements. -
getChildElementsCount
Returns number of child elements with given name. -
getChildNodes
Returns an array of all children nodes. Returns an empty array if there are no children. -
findChildNodeWithName
-
filterChildNodes
-
getChildElements
Returns an array of all children elements. -
getChild
Returns a child node at given index ornullif child doesn't exist for that index. -
getChild
Returns a child node with given hierarchy. Just a shortcut for successive calls ofgetChild(int). -
getChildElement
Returns a child element node at given index. If index is out of bounds,nullis returned. -
getFirstChild
Returns first child ornullif no children exist. -
getFirstChildElement
Returns first child element node ornullif no element children exist. -
getFirstChildElement
-
getLastChild
Returns last child ornullif no children exist. -
getLastChildElement
Returns last child element node ornullif no such child node exist. -
getLastChildElement
-
check
public boolean check()Checks the health of child nodes. Useful during complex tree manipulation, to check if everything is OK. Not optimized for speed, should be used just for testing purposes. -
reindexChildren
protected void reindexChildren()Reindex children nodes. Must be called on every children addition/removal. IterateschildNodeslist and:- calculates three different sibling indexes,
- calculates total child element node count,
- resets child element nodes array (will be init lazy later by @{#initChildElementNodes}.
-
reindexChildrenOnAdd
protected void reindexChildrenOnAdd(int addedCount) Optimized variant ofreindexChildren()for addition. Only added children are optimized. -
initChildElementNodes
protected void initChildElementNodes()Initializes list of child elements. -
initSiblingNames
protected void initSiblingNames()Initializes siblings elements of the same name. -
initAttributes
protected void initAttributes()Initializes attributes when needed. -
initChildNodes
Initializes child nodes list when needed. Also fix owner document for new node, if needed. -
changeOwnerDocument
-
getSiblingIndex
public int getSiblingIndex()Get the list index of this node in its node sibling list. For example, if this is the first node sibling, returns 0. Index address all nodes, i.e. of all node types. -
getSiblingElementIndex
public int getSiblingElementIndex() -
getSiblingNameIndex
public int getSiblingNameIndex() -
getNextSibling
Returns this node's next sibling of any type ornullif this is the last sibling. -
getNextSiblingElement
Returns this node's next element. -
getNextSiblingName
Returns this node's next element with the same name. -
getPreviousSibling
Returns this node's previous sibling of any type ornullif this is the first sibling. -
getPreviousSiblingElement
Returns this node's previous sibling of element type ornullif this is the first sibling. -
getPreviousSiblingName
Returns this node's previous sibling element with the same name. -
getTextContent
-
appendTextContent
Appends the text content to anAppendable(StringBuilder,CharBuffer...). This way we can reuse theAppendableinstance during the creation of text content and have better performances. -
getHtml
Generates HTML. -
getInnerHtml
Generates inner HTML. -
visit
Visits the DOM tree. -
visitChildren
Visits children nodes. -
visitNode
Visits single node. Implementations just needs to call the correct visitor callback function. -
getCssPath
Returns CSS path to this node from document root.
-