jodd.lagarto.dom
Class Node

java.lang.Object
  extended by jodd.lagarto.dom.Node
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
CData, Comment, Document, DocumentType, Element, Text, XmlDeclaration

public abstract class Node
extends java.lang.Object
implements java.lang.Cloneable

DOM node.


Nested Class Summary
static class Node.NodeType
          Node types.
 
Field Summary
protected  java.util.List<Attribute> attributes
           
protected  boolean caseSensitive
           
protected  Node[] childElementNodes
           
protected  int childElementNodesCount
           
protected  java.util.List<Node> childNodes
           
protected  int deepLevel
           
protected  java.lang.String nodeName
           
protected  Node.NodeType nodeType
           
protected  java.lang.String nodeValue
           
protected  Node parentNode
           
protected  int siblingElementIndex
           
protected  int siblingIndex
           
protected  int siblingNameIndex
           
 
Constructor Summary
protected Node(Node.NodeType nodeType, java.lang.String nodeName, boolean caseSensitive)
           
 
Method Summary
 void appendChild(Node... nodes)
          Appends several child nodes at once.
 void appendChild(Node node)
          Appends child node.
abstract  Node clone()
           
protected
<T extends Node>
T
cloneTo(T dest)
          Copies all non-final values to the empty cloned object.
 void detachFromParent()
          Removes this node from DOM tree.
 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 index)
          Returns a child node at given index or null if child doesn't exist for that index.
 Node getChildElement(int index)
          Returns a child element node at given index.
 Node[] 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.
 int getDeepLevel()
          Returns deep level.
 Node getFirstChild()
          Returns first child or null if no children exist.
 Node getFirstChildElement()
          Returns first child element node or null if no element children exist.
 Node 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.
 Node getLastChildElement()
          Returns last child element node or null if no such child node exist.
 Node 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 node name or null if name is not available.
 Node.NodeType getNodeType()
          Returns node type.
 java.lang.String getNodeValue()
          Returns node value or null if value is not available.
 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()
          Initializes child nodes list when needed.
protected  void initSiblingNames()
          Initializes siblings elements of the same name.
 void insertAfter(Node newChild, Node refChild)
          Inserts node after provided node.
 void insertBefore(Node newChild, Node refChild)
          Inserts node before provided node.
 void insertChild(Node node, int index)
          Inserts node at given index.
 boolean isAttributeIncluding(java.lang.String name, java.lang.String word)
          Returns true if attribute includes some word.
protected  void reindexChildren()
          Reindex children nodes.
 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 toHtml(java.lang.Appendable appendable)
          Generates HTML by appending it to the provided Appendable.
protected  void toInnerHtml(java.lang.Appendable appendable)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeName

protected final java.lang.String nodeName

nodeType

protected final Node.NodeType nodeType

caseSensitive

protected final boolean caseSensitive

nodeValue

protected java.lang.String nodeValue

parentNode

protected Node parentNode

attributes

protected java.util.List<Attribute> attributes

childNodes

protected java.util.List<Node> childNodes

childElementNodesCount

protected int childElementNodesCount

childElementNodes

protected Node[] childElementNodes

siblingIndex

protected int siblingIndex

siblingElementIndex

protected int siblingElementIndex

siblingNameIndex

protected int siblingNameIndex

deepLevel

protected int deepLevel
Constructor Detail

Node

protected Node(Node.NodeType nodeType,
               java.lang.String nodeName,
               boolean caseSensitive)
Method Detail

cloneTo

protected <T extends Node> T cloneTo(T dest)
Copies all non-final values to the empty cloned object. Cache-related values are not copied.


clone

public abstract Node clone()
Overrides:
clone in class java.lang.Object

getNodeType

public Node.NodeType getNodeType()
Returns node type.


getNodeName

public java.lang.String getNodeName()
Returns node name or null if name is not available.


getNodeValue

public java.lang.String getNodeValue()
Returns node value or null if value is not available.


setNodeValue

public void setNodeValue(java.lang.String value)
Sets node value.


detachFromParent

public void detachFromParent()
Removes this node from DOM tree.


appendChild

public void appendChild(Node node)
Appends child node.


appendChild

public void appendChild(Node... nodes)
Appends several child nodes at once.


insertChild

public void insertChild(Node node,
                        int index)
Inserts node at given index.


insertBefore

public void insertBefore(Node newChild,
                         Node refChild)
Inserts node before provided node.


insertAfter

public void insertAfter(Node newChild,
                        Node refChild)
Inserts node after provided node.


removeChild

public Node removeChild(int index)
Removes child node at given index. Returns removed node or null if index is invalid.


removeChild

public void removeChild(Node childNode)
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.


getParentNode

public Node getParentNode()
Returns parent node or null if no parent exist.


hasAttributes

public boolean hasAttributes()
Returns true if node has attributes.


getAttributesCount

public int getAttributesCount()
Returns total number of attributes.


getAttribute

public Attribute getAttribute(int index)
Returns attribute at given index or null if index not found.


hasAttribute

public boolean hasAttribute(java.lang.String name)
Returns true if node contains an attribute.


getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns attribute value. Returns null when attribute doesn't exist or when attribute exist but doesn't specify a value.


getAttributeInstance

protected Attribute getAttributeInstance(java.lang.String name)

indexOfAttributeInstance

protected int indexOfAttributeInstance(java.lang.String name)

removeAttribute

public boolean removeAttribute(java.lang.String name)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Sets attribute value. Value may be null.


setAttribute

public void setAttribute(java.lang.String name)
Sets attribute that doesn't need a value.


isAttributeIncluding

public boolean isAttributeIncluding(java.lang.String name,
                                    java.lang.String word)
Returns true if attribute includes some word.


hasChildNodes

public boolean hasChildNodes()
Returns true if node has child nodes.


getChildNodesCount

public int getChildNodesCount()
Returns number of all child nodes.


getChildElementsCount

public int getChildElementsCount()
Returns number of child elements.


getChildElementsCount

public int getChildElementsCount(java.lang.String elementName)
Returns number of child elements with given name.


getChildNodes

public Node[] getChildNodes()
Returns an array of all children nodes. Returns an empty array if there are no children.


getChildElements

public Node[] getChildElements()
Returns an array of all children elements.


getChild

public Node getChild(int index)
Returns a child node at given index or null if child doesn't exist for that index.


getChildElement

public Node getChildElement(int index)
Returns a child element node at given index.


getFirstChild

public Node getFirstChild()
Returns first child or null if no children exist.


getFirstChildElement

public Node getFirstChildElement()
Returns first child element node or null if no element children exist.


getFirstChildElement

public Node getFirstChildElement(java.lang.String elementName)
Returns first child element with given name or null if no such children exist.


getLastChild

public Node getLastChild()
Returns last child or null if no children exist.


getLastChildElement

public Node getLastChildElement()
Returns last child element node or null if no such child node exist.


getLastChildElement

public Node getLastChildElement(java.lang.String elementName)
Returns last child element with given name or null if no such child node exist.


reindexChildren

protected void reindexChildren()
Reindex children nodes. Must be called on every children addition/removal.


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

protected void initChildNodes()
Initializes child nodes list when needed.


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

public Node getNextSibling()
Returns this node's next sibling of any type or null if this is the last sibling.


getNextSiblingElement

public Node getNextSiblingElement()
Returns this node's next element.


getNextSiblingName

public Node getNextSiblingName()
Returns this node's next element with the same name.


getPreviousSibling

public Node getPreviousSibling()
Returns this node's previous sibling of any type or null if this is the first sibling.


getPreviousSiblingElement

public Node getPreviousSiblingElement()
Returns this node's previous sibling of element type or null if this is the first sibling.


getPreviousSiblingName

public Node getPreviousSiblingName()
Returns this node's previous sibling element with the same name.


getTextContent

public java.lang.String getTextContent()
Returns the text content of this node and its descendants.


getHtml

public java.lang.String getHtml()
Generates HTML.


getInnerHtml

public java.lang.String getInnerHtml()
Generates inner HTML.


toHtml

public void toHtml(java.lang.Appendable appendable)
            throws java.io.IOException
Generates HTML by appending it to the provided Appendable.

Throws:
java.io.IOException

toInnerHtml

protected void toInnerHtml(java.lang.Appendable appendable)
                    throws java.io.IOException
Throws:
java.io.IOException

getDeepLevel

public int getDeepLevel()
Returns deep level.


getCssPath

public java.lang.String getCssPath()
Returns CSS path to this node from document root.



Copyright © 2003-2011 Jodd Team