jet.webreport.util
Class JNode

java.lang.Object
  extended by jet.webreport.util.JNode
All Implemented Interfaces:
java.io.Serializable

public final class JNode
extends java.lang.Object
implements java.io.Serializable

JNode is a lightweight tree structure.

See Also:
Serialized Form

Field Summary
static java.lang.String ATT_PREFIX
           
static java.lang.String HIDE_SURFIX
           
static java.lang.String MAP_SURFIX
           
static java.lang.String NODE_DESC
           
static java.lang.String NODE_ID
           
static java.lang.String NODE_NAME
           
static java.lang.String NODE_PATH
           
static java.lang.String NODE_TYPE
           
static java.lang.String NODE_VALU
           
static java.lang.String TAG_SURFIX
           
static java.lang.String TYPE_ROOT
           
 
Constructor Summary
JNode(java.lang.String type)
          Creates a new JNode instance by the specified type.
JNode(java.lang.String type, java.lang.String name, java.lang.String value, java.lang.String desc)
          Creates a new JNode instance by the specified type.
 
Method Summary
 void addChild(int index, JNode node)
          Inserts the specified node at the specified position in this node.
 void addChild(JNode node)
          Appends the specified node to the end of this node.
 void clear()
          Removes all of the children nodes from this node.
static JNode clone(JNode o)
          Initializes a newly created JNode object so that it represents the same as the argument; in other words, the newly created JNode is a copy of the argument JNode.
 java.lang.String getAttribute(java.lang.String name)
          Returns an attribute of the node with the specified attribute name.
 java.util.Iterator getAttributeNames()
          Returns all attribute names in an Iterator.
 JNode getChild(int index)
          Returns the child node at the specified position in this node.
 JNode getChild(java.lang.String name)
          Returns the child node with the specified node name in this node.
 java.lang.String[] getChildNames()
          Returns all children nodes' names in a string array.
 java.util.Iterator getChildren()
          Returns all children JNode in Iterator.
 java.lang.String getDescription()
          Gets the description attribute of this node.
 java.lang.String getID()
          Returns the id of the node path.
 java.lang.String getName()
          Returns the name of the node.
 JNode getParent()
          Returns the parent node of the node.
 java.lang.String getPath()
          Returns the path of the node in the node tree.
static java.lang.String getPathID(java.lang.String path)
          Returns the path id of the node.
 java.lang.String getText()
          Returns the text string attached to the node.
 java.lang.String getType()
          Returns the type of the node.
 java.lang.String getValue()
          Returns the value attribute of this node.
 int hashCode()
          Returns a hash code for this node.
The hash code is @see getName() String object.
 int indexOfChild(java.lang.String name)
          Returns the index of the first occurrence of the specified child node in this node, or -1 if this node does not contain a child node.
 boolean isRoot()
          Tests whether the node type is "root".
 JNode removeChild(int index)
          Removes the child node at the specified position in this node.
 JNode removeChild(java.lang.String name)
          Removes the child node with the specified node name in this node.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets an attribute of the node with the specified attribute name.
 void setDescription(java.lang.String desc)
          Sets the description attribute of this node.
 void setName(java.lang.String name)
          Sets the name attribute of this node with specified name.
 void setPathPrefix(java.lang.String prefix)
          Sets the path prefix of the node.
 void setText(java.lang.String text)
          Sets the text string attached to the node.
 void setValue(java.lang.String value)
          Sets the value attribute of this node with specified value.
 int size()
          Returns the children size of the node.
static org.w3c.dom.Document toDocument(JNode jnode, java.util.Properties props)
          Transfers a JNode to a W3C Document.
 java.lang.String toXML(java.util.Properties props)
          Exports the node to XML string.
static java.lang.StringBuffer writeXML(JNode jnode, java.util.Properties props)
          Exports a JNode to XML in a StringBuffer.
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_SURFIX

public static final transient java.lang.String TAG_SURFIX
See Also:
Constant Field Values

ATT_PREFIX

public static final transient java.lang.String ATT_PREFIX
See Also:
Constant Field Values

MAP_SURFIX

public static final transient java.lang.String MAP_SURFIX
See Also:
Constant Field Values

HIDE_SURFIX

public static final transient java.lang.String HIDE_SURFIX
See Also:
Constant Field Values

NODE_TYPE

public static final transient java.lang.String NODE_TYPE
See Also:
Constant Field Values

NODE_NAME

public static final transient java.lang.String NODE_NAME
See Also:
Constant Field Values

NODE_VALU

public static final transient java.lang.String NODE_VALU
See Also:
Constant Field Values

NODE_DESC

public static final transient java.lang.String NODE_DESC
See Also:
Constant Field Values

NODE_PATH

public static final transient java.lang.String NODE_PATH
See Also:
Constant Field Values

NODE_ID

public static final transient java.lang.String NODE_ID
See Also:
Constant Field Values

TYPE_ROOT

public static final transient java.lang.String TYPE_ROOT
See Also:
Constant Field Values
Constructor Detail

JNode

public JNode(java.lang.String type)
Creates a new JNode instance by the specified type.

Parameters:
type - the node type, which starts with TYPE_, and is defined in JNode, ResourceTreeBuilder, or TOCTreeBuilder, such as
JNode.TYPE_ROOT,
ResourceTreeBuilder.TYPE_DATASOURCE,
TOCTreeBuilder.TYPE_TOCNODE.

JNode

public JNode(java.lang.String type,
             java.lang.String name,
             java.lang.String value,
             java.lang.String desc)
Creates a new JNode instance by the specified type.

Parameters:
type - the node type, which starts with TYPE_, and is defined in JNode, ResourceTreeBuilder, or TOCTreeBuilder, such as
JNode.TYPE_ROOT,
ResourceTreeBuilder.TYPE_DATASOURCE,
TOCTreeBuilder.TYPE_TOCNODE.
name - the node name.
value - the node value.
desc - the node description.
Method Detail

getParent

public JNode getParent()
Returns the parent node of the node.

Returns:
the parent node.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns an attribute of the node with the specified attribute name.

Parameters:
name - the attribute name.
Returns:
the attribute in String.

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Sets an attribute of the node with the specified attribute name.

Parameters:
name - the attribute name.
value - the attribute value.

getAttributeNames

public java.util.Iterator getAttributeNames()
Returns all attribute names in an Iterator.

Returns:
all attribute names.

getType

public java.lang.String getType()
Returns the type of the node.

Returns:
the type.

getName

public java.lang.String getName()
Returns the name of the node.

Returns:
the name.

setName

public void setName(java.lang.String name)
Sets the name attribute of this node with specified name.

Parameters:
name - the name.

getValue

public java.lang.String getValue()
Returns the value attribute of this node.

Returns:
the value

setValue

public void setValue(java.lang.String value)
Sets the value attribute of this node with specified value.

Parameters:
value - the value.

getDescription

public java.lang.String getDescription()
Gets the description attribute of this node.

Returns:
the description.

setDescription

public void setDescription(java.lang.String desc)
Sets the description attribute of this node.

Parameters:
desc - the description.

getText

public java.lang.String getText()
Returns the text string attached to the node.

Returns:
the text.

setText

public void setText(java.lang.String text)
Sets the text string attached to the node.

Parameters:
text - the text.

getPath

public java.lang.String getPath()
Returns the path of the node in the node tree.

Returns:
the path.

setPathPrefix

public void setPathPrefix(java.lang.String prefix)
Sets the path prefix of the node.

Parameters:
prefix - the path prefix.

getID

public java.lang.String getID()
Returns the id of the node path.

Returns:
the id.
See Also:
getPath(), getPathID(String)

getPathID

public static java.lang.String getPathID(java.lang.String path)
Returns the path id of the node.

Parameters:
path - the node path.
Returns:
the path id.

size

public int size()
Returns the children size of the node.

Returns:
the children size.

getChildren

public java.util.Iterator getChildren()
Returns all children JNode in Iterator.

Returns:
all children

addChild

public void addChild(JNode node)
Appends the specified node to the end of this node.

Parameters:
node - the node to be appended to this node.

addChild

public void addChild(int index,
                     JNode node)
Inserts the specified node at the specified position in this node. Shifts the node currently at that position (if any) and any subsequent node to the right (adds one to their indices).

Parameters:
index - index at which the specified node is to be inserted.
node - the node to be inserted.

getChild

public JNode getChild(int index)
Returns the child node at the specified position in this node.

Parameters:
index - index of the child node to return.
Returns:
JNode the child node at the specified position in this node.

getChild

public JNode getChild(java.lang.String name)
Returns the child node with the specified node name in this node.

Parameters:
name - the specified node name.
Returns:
JNode the child node at the specified position in this nod.

removeChild

public JNode removeChild(int index)
Removes the child node at the specified position in this node. Shifts any subsequent nodes to the left (subtracts one from their indices). Returns the child node that was removed from the node.

Parameters:
index - the index of the child node to be removed.
Returns:
the child node previously at the specified position.

removeChild

public JNode removeChild(java.lang.String name)
Removes the child node with the specified node name in this node.

Parameters:
name - the specified node name.
Returns:
the child node previously at the specified position.

indexOfChild

public int indexOfChild(java.lang.String name)
Returns the index of the first occurrence of the specified child node in this node, or -1 if this node does not contain a child node.

Parameters:
name - the specified node name to search for.
Returns:
the index of the first occurrence of the specified child node in this node, or -1 if this node does not contain a child node.

getChildNames

public java.lang.String[] getChildNames()
Returns all children nodes' names in a string array.

Returns:
the names of all children nodes.

isRoot

public boolean isRoot()
Tests whether the node type is "root".

Returns:
true if the node is root, otherwise false.

clear

public void clear()
Removes all of the children nodes from this node. And clears the attributes of this node.


hashCode

public int hashCode()
Returns a hash code for this node.
The hash code is @see getName() String object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this node.

clone

public static JNode clone(JNode o)
Initializes a newly created JNode object so that it represents the same as the argument; in other words, the newly created JNode is a copy of the argument JNode.

Parameters:
o - a JNode.

toXML

public java.lang.String toXML(java.util.Properties props)
Exports the node to XML string.

Parameters:
props - some output control parameters, for example,

"xml.encoding" for writing the Document to a file, if the default value is not "UTF-8".
"xml.indent" is used to control whether to indent according to the nodes hierarchy when output, if the default value is not "false".

Returns:
the node to XML string.

writeXML

public static java.lang.StringBuffer writeXML(JNode jnode,
                                              java.util.Properties props)
Exports a JNode to XML in a StringBuffer.

Parameters:
jnode - The JNode object.
props - some output control parameters, @see #toXML(Properties).
Returns:
the node to XML StringBuffer.

toDocument

public static org.w3c.dom.Document toDocument(JNode jnode,
                                              java.util.Properties props)
Transfers a JNode to a W3C Document.

Parameters:
jnode - The JNode object.
props - some output control parameters, @see #toXML(Properties).
Returns:
the node to Document.