|
Forge - Parent 1.2.3-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.forge.parser.xml.Node
public class Node
Node
is a data structure representing a container in a classic tree. May sometimes be synonymous with the
term "Element" in XML. It may contain a Map
of attributes (String
s), a reference to a List
of
child Node
s, and text data.
Constructor Summary | |
---|---|
Node(String name)
Creates a root Node |
|
Node(String name,
Node parent)
Creates a Node |
Method Summary | |
---|---|
Node |
attribute(String name,
Object value)
Add or override a named attribute. value will be converted to String using String.valueOf(value); |
Node |
attribute(String name,
String value)
Add or override a named attribute. |
Node |
createChild(Pattern... patterns)
|
Node |
createChild(String name)
Create a new Node with given name. |
List<Node> |
get(Pattern... patterns)
Get all children matching the specified query. |
List<Node> |
get(String name)
Get all children with a specific name. |
String |
getAttribute(String name)
Get a named attribute. |
Map<String,String> |
getAttributes()
Get all defined attributes for this Node in an immutable view |
List<Node> |
getChildren()
Get all the defined children for this node in an immutable view. |
String |
getName()
Get the Nodes name. |
Node |
getOrCreate(Pattern... patterns)
|
Node |
getOrCreate(String name)
Get or create a named child node. |
Node |
getParent()
Get the Nodes parent. |
Node |
getRoot()
Obtains the root Node for this reference |
Node |
getSingle(Pattern... patterns)
|
Node |
getSingle(String name)
Get a single child node. If multiple children are found with same name it is considered a IllegalArgumentException. |
String |
getText()
Get the Nodes text body. |
String |
getTextValueForPatternName(String name)
Get the text value of the element found at the given query name. |
List<String> |
getTextValuesForPatternName(String name)
Get the text values of all elements found at the given query name. |
boolean |
isComment()
Returns whether or not this Node represents a comment |
boolean |
isRoot()
Returns whether or not this Node is a root |
String |
removeAttribute(String name)
Remove a named attribute. |
boolean |
removeChild(Node child)
Remove a single child from this Node |
Node |
removeChild(String name)
Remove a single child from this Node |
List<Node> |
removeChildren(Pattern pattern,
Pattern... patterns)
Remove all child nodes found at the given Pattern s. |
List<Node> |
removeChildren(String name)
Remove all child nodes found at the given query. |
void |
setComment(boolean comment)
Marks this Node as a comment |
Node |
text(Object text)
Set the Nodes text body. text will be converted to String using String.valueOf(text); |
Node |
text(String text)
Set the Nodes text body. |
String |
toString()
|
String |
toString(boolean verbose)
Returns a multiline String format of this Node and all children |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Node(String name) throws IllegalArgumentException
Node
name
- The name of the node
IllegalArgumentException
public Node(String name, Node parent) throws IllegalArgumentException
Node
name
- The name of the nodeparent
- The parent node. Use null to denote a root.
IllegalArgumentException
- If the name is not specified or contains any space charactersMethod Detail |
---|
public Node attribute(String name, Object value)
name
- The attribute namevalue
- The given value
Node
attribute(String, String)
public Node attribute(String name, String value)
name
- The attribute namevalue
- The given value
Node
public String getAttribute(String name)
name
- The attribute name
public String removeAttribute(String name) throws IllegalArgumentException
name
- The attribute name
IllegalArgumentException
- If the name is not specifiedpublic Map<String,String> getAttributes()
public boolean isComment()
Node
represents a comment
public void setComment(boolean comment) throws IllegalArgumentException
Node
as a comment
comment
- Whether or not this is a comment
IllegalArgumentException
- If this node has childrenpublic Node getRoot()
Node
for this reference
public boolean isRoot()
Node
is a root
public Node createChild(String name) throws IllegalArgumentException
Node
with given name. Node
will have this as parent.
name
- The name of the Node
.
Node
IllegalArgumentException
- If the name is not specifiedpublic Node createChild(Pattern... patterns)
public Node getOrCreate(String name)
getSingle(String)
it is returned, else a new child node is created.
name
- The child node name.
IllegalArgumentException
- if multiple children with name exists.getSingle(String)
,
createChild(String)
public Node getOrCreate(Pattern... patterns)
public Node getSingle(String name)
name
- The child node name
IllegalArgumentException
- if multiple children with name exists.public Node getSingle(Pattern... patterns)
public List<Node> get(String name)
name
- The child node name.
public List<Node> get(Pattern... patterns)
query
- The query to use for finding relevant child nodes
public List<Node> removeChildren(String name) throws IllegalArgumentException
List
of removed children.
IllegalArgumentException
- If the specified name is not specifiedpublic List<Node> removeChildren(Pattern pattern, Pattern... patterns)
Pattern
s.
List
of removed children.
IllegalArgumentException
- If pattern is not specifiedpublic boolean removeChild(Node child)
Node
public Node removeChild(String name)
Node
IllegalArgumentException
- if multiple children with name exist.public Node text(Object text)
text
-
text(String)
public Node text(String text)
text
- The text content
public String getText()
public String getTextValueForPatternName(String name)
public List<String> getTextValuesForPatternName(String name)
public String getName()
public Node getParent()
public List<Node> getChildren()
public String toString()
toString
in class Object
Object.toString()
public String toString(boolean verbose)
String
format of this Node
and all children
verbose
-
|
Forge - Parent 1.2.3-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |