public class TreeNode extends Object
Simplified implementation of a Node from a Document Object Model (DOM)
parse of an XML document. This class is used to represent a DOM tree
so that the XML parser's implementation of org.w3c.dom need
not be visible to the remainder of Jasper.
WARNING - Construction of a new tree, or modifications to an existing one, are not thread-safe and such accesses must be synchronized.
| Modifier and Type | Field and Description |
|---|---|
protected HashMap |
attributes
The attributes of this node, keyed by attribute name,
Instantiated only if required.
|
protected String |
body
The body text associated with this node (if any).
|
protected ArrayList |
children
The children of this node, instantiated only if required.
|
protected String |
name
The name of this node.
|
protected TreeNode |
parent
The parent node of this node.
|
| Constructor and Description |
|---|
TreeNode(String name)
Construct a new node with no parent.
|
TreeNode(String name,
TreeNode parent)
Construct a new node with the specified parent.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAttribute(String name,
String value)
Add an attribute to this node, replacing any existing attribute
with the same name.
|
void |
addChild(TreeNode node)
Add a new child node to this node.
|
String |
findAttribute(String name) |
Iterator |
findAttributes() |
TreeNode |
findChild(String name) |
Iterator |
findChildren() |
Iterator |
findChildren(String name) |
String |
getBody() |
String |
getName() |
void |
removeAttribute(String name)
Remove any existing value for the specified attribute name.
|
void |
removeNode(TreeNode node)
Remove a child node from this node, if it is one.
|
void |
setBody(String body)
Set the body text associated with this node (if any).
|
String |
toString() |
protected void |
toString(StringBuffer sb,
int indent,
TreeNode node)
Append to the specified StringBuffer a character representation of
this node, with the specified amount of indentation.
|
protected HashMap attributes
protected String body
protected ArrayList children
protected String name
protected TreeNode parent
public TreeNode(String name)
name - The name of this nodepublic void addAttribute(String name, String value)
name - The attribute name to addvalue - The new attribute valuepublic void addChild(TreeNode node)
node - The new child nodepublic String findAttribute(String name)
name - Name of the requested attributenull otherwise.public Iterator findAttributes()
public TreeNode findChild(String name)
name - Name of the desired child elementnull.public Iterator findChildren()
public Iterator findChildren(String name)
name - Name used to select childrenpublic String getBody()
public String getName()
public void removeAttribute(String name)
name - The attribute name to removepublic void removeNode(TreeNode node)
node - The child node to removepublic void setBody(String body)
body - The body text (if any)public String toString()
protected void toString(StringBuffer sb, int indent, TreeNode node)
sb - The StringBuffer to append toindent - Number of characters of indentationnode - The TreeNode to be printedCopyright © 2000–2023 Apache Software Foundation. All rights reserved.