com.japisoft.fastparser.node
Class SimpleNode

java.lang.Object
  |
  +--com.japisoft.fastparser.node.SimpleNode
All Implemented Interfaces:
MutableNode, ViewableNode
Direct Known Subclasses:
NodeImpl

public class SimpleNode
extends java.lang.Object
implements MutableNode, ViewableNode

Simple node.

Since:
1.0
Version:
1.2
Author:
(c) 2002 JAPISoft

Field Summary
static int COMMENT_NODE
           
static int TAG_NODE
           
static int TEXT_NODE
           
 
Constructor Summary
SimpleNode(int type, java.lang.String content)
           
SimpleNode(SimpleNode parent, int type, java.lang.String content)
           
 
Method Summary
 void addChildNode(SimpleNode node)
          Insert a new node
 void addNameSpaceDeclaration(java.lang.String prefix, java.lang.String uri)
          Add a declaration for nameSpace
 void addNode(MutableNode node)
          Reset the children
 SimpleNode childAt(int index)
           
 int childCount()
           
 int childNodeIndex(SimpleNode node)
           
 SimpleNode clone(boolean deep)
          Clone the current node, include subchild if deep is true
 java.util.Enumeration getAllChild()
          Get all child
 java.lang.String getAttribute(java.lang.String qname)
           
 java.lang.String getAttribute(java.lang.String qname, java.lang.String defaultValue)
           
 java.lang.String getContent()
           
 java.lang.String getDefaultNamespace()
          Return the default namespace declaration
 Document getDocument()
           
 int getLine()
           
 java.util.Enumeration getNameSpaceDeclaration()
           
 java.lang.String getNameSpaceDeclarationURI(java.lang.String prefix)
           
 java.util.Enumeration getNamespaceDeclared()
           
 java.lang.String getNameSpacePrefix()
           
 java.lang.String getNameSpaceURI()
           
 java.util.Enumeration getNodeByCriteria(ValidCriteria criteria, boolean deep)
          Sample of criteria : new OrCriteria( new NodeNameCriteria( "aa" ), new NodeNameCriteria( "bb" ) ) for returning 'aa' or 'bb' node.
 java.util.Enumeration getNodeByName(java.lang.String name, boolean deep)
           
 java.lang.String getNodeContent()
           
 SimpleNode getNodeForXPathLocation(java.lang.String xpath, boolean resolveAlways)
          This feature is limited to a subset of the XPath set : /tag1[ location ]/tag2...
 SimpleNode getSimpleParent()
           
 int getType()
           
 java.lang.String getViewAttribute(java.lang.String name)
           
 java.util.Enumeration getViewAttributes()
           
 ViewableNode getViewChildAt(int i)
           
 int getViewChildCount()
           
 java.lang.String getViewContent()
           
 java.lang.String getXPathLocation()
           
 java.lang.String getXPathLocation(SimpleNode node)
           
 boolean hasAttribute(java.lang.String qname)
           
 void insertChildNode(int index, SimpleNode node)
          Insert a childnode at the index location
 boolean isComment()
           
 boolean isLeaf()
           
 boolean isNamespaceDeclared(java.lang.String prefix)
          Check if this namespace prefix is declared in this node
 boolean isRoot()
           
 boolean isTag()
           
 boolean isText()
           
 boolean isViewComment()
           
 boolean isViewLeaf()
           
 boolean isViewText()
           
 void removeChildNode(SimpleNode node)
          Remove the following node
 void removeNameSpaceDeclaration(java.lang.String prefix)
          Remove a nameSpace prefix declaration
 void setAttribute(java.lang.String qname, java.lang.String value)
          Set the attribute value.
 void setContent(java.lang.String content)
          Update the node content, for tag this is the tag name, for text this is the content, for comment this is the content
 void setDefaultNamespace(java.lang.String namespaceURI)
          Reset the default namespace
 void setDocument(Document doc)
          Owner document for this node
 void setLine(int line)
          Set the node line location
 void setNameSpace(java.lang.String name, java.lang.String nameSpaceURI)
          Set the namespace
 void setNodeAttribute(java.lang.String name, java.lang.String value)
          Reset the node attribute
 void setNodeContent(java.lang.String content)
          Reset the node content
 void setNodeParent(MutableNode node)
          Reset the node parent
 void setSimpleParent(SimpleNode node)
          reset the parent node
 void setType(int type)
          Update the node type, this is TEXT_NODE, TAG_NODE or COMMENT_NODE
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEXT_NODE

public static final int TEXT_NODE
See Also:
Constant Field Values

TAG_NODE

public static final int TAG_NODE
See Also:
Constant Field Values

COMMENT_NODE

public static final int COMMENT_NODE
See Also:
Constant Field Values
Constructor Detail

SimpleNode

public SimpleNode(int type,
                  java.lang.String content)
Parameters:
type - Node type : TEXT_NODE, TAG_NODE or COMMENT_NODE
content - the tag content

SimpleNode

public SimpleNode(SimpleNode parent,
                  int type,
                  java.lang.String content)
Parameters:
type - Node type : TEXT_NODE, TAG_NODE or COMMENT_NODE
content - the tag content
Method Detail

setLine

public void setLine(int line)
Set the node line location

Specified by:
setLine in interface MutableNode

getLine

public int getLine()
Returns:
the line location

addNameSpaceDeclaration

public void addNameSpaceDeclaration(java.lang.String prefix,
                                    java.lang.String uri)
Add a declaration for nameSpace

Specified by:
addNameSpaceDeclaration in interface MutableNode
Parameters:
prefix - NameSpace prefix
uri - NameSpace URI

removeNameSpaceDeclaration

public void removeNameSpaceDeclaration(java.lang.String prefix)
Remove a nameSpace prefix declaration

Specified by:
removeNameSpaceDeclaration in interface MutableNode

getNameSpaceDeclaration

public java.util.Enumeration getNameSpaceDeclaration()
Specified by:
getNameSpaceDeclaration in interface ViewableNode
Returns:
nameSpace prefix support

getNameSpaceDeclarationURI

public java.lang.String getNameSpaceDeclarationURI(java.lang.String prefix)
Specified by:
getNameSpaceDeclarationURI in interface ViewableNode
Returns:
a nameSpace declaration URI for this prefix

isNamespaceDeclared

public boolean isNamespaceDeclared(java.lang.String prefix)
Description copied from interface: MutableNode
Check if this namespace prefix is declared in this node

Specified by:
isNamespaceDeclared in interface MutableNode
Returns:
true if this prefix is delcared inside this node

getNamespaceDeclared

public java.util.Enumeration getNamespaceDeclared()
Specified by:
getNamespaceDeclared in interface MutableNode
Returns:
the list of namespaces declared

setNameSpace

public void setNameSpace(java.lang.String name,
                         java.lang.String nameSpaceURI)
Set the namespace

Specified by:
setNameSpace in interface MutableNode
Parameters:
name - Namespace prefix

getNameSpacePrefix

public java.lang.String getNameSpacePrefix()
Specified by:
getNameSpacePrefix in interface MutableNode
Returns:
the namespace prefix

getNameSpaceURI

public java.lang.String getNameSpaceURI()
Specified by:
getNameSpaceURI in interface MutableNode
Returns:
the namespace URI

setDefaultNamespace

public void setDefaultNamespace(java.lang.String namespaceURI)
Reset the default namespace

Specified by:
setDefaultNamespace in interface MutableNode

getDefaultNamespace

public java.lang.String getDefaultNamespace()
Description copied from interface: MutableNode
Return the default namespace declaration

Specified by:
getDefaultNamespace in interface MutableNode
Returns:
the default namespace

setDocument

public void setDocument(Document doc)
Owner document for this node


getDocument

public Document getDocument()
Returns:
the owner document

clone

public SimpleNode clone(boolean deep)
Clone the current node, include subchild if deep is true


setSimpleParent

public void setSimpleParent(SimpleNode node)
reset the parent node


getSimpleParent

public SimpleNode getSimpleParent()
Returns:
the parent node or null for the root node

isRoot

public boolean isRoot()
Returns:
true for the root node

setContent

public void setContent(java.lang.String content)
Update the node content, for tag this is the tag name, for text this is the content, for comment this is the content


getContent

public java.lang.String getContent()
Returns:
the node content

setType

public void setType(int type)
Update the node type, this is TEXT_NODE, TAG_NODE or COMMENT_NODE


getType

public int getType()
Returns:
the node type TEXT_NODE, TAG_NODE or COMMENT_NODE

isText

public boolean isText()
Returns:
true for text node

isTag

public boolean isTag()
Returns:
true for tag node

isComment

public boolean isComment()
Returns:
true for comment node

insertChildNode

public void insertChildNode(int index,
                            SimpleNode node)
Insert a childnode at the index location


addChildNode

public void addChildNode(SimpleNode node)
Insert a new node


removeChildNode

public void removeChildNode(SimpleNode node)
Remove the following node


childNodeIndex

public int childNodeIndex(SimpleNode node)
Returns:
the child node index. -1 for unknown child

childCount

public int childCount()
Returns:
the children count

getAllChild

public java.util.Enumeration getAllChild()
Get all child


childAt

public SimpleNode childAt(int index)
Returns:
the children at the index position starting from 0

isLeaf

public boolean isLeaf()
Returns:
true for leaf node

setAttribute

public void setAttribute(java.lang.String qname,
                         java.lang.String value)
Set the attribute value. If value is null the attribute is removed

Parameters:
qname - Qualified name (namespace prefix + local name )
value - value for this attribute

getAttribute

public java.lang.String getAttribute(java.lang.String qname,
                                     java.lang.String defaultValue)
Returns:
an attribute value. defaultValue is returned for unknown attribute name

getNodeByName

public java.util.Enumeration getNodeByName(java.lang.String name,
                                           boolean deep)
Returns:
all nodes matching the following name

getNodeByCriteria

public java.util.Enumeration getNodeByCriteria(ValidCriteria criteria,
                                               boolean deep)
Sample of criteria : new OrCriteria( new NodeNameCriteria( "aa" ), new NodeNameCriteria( "bb" ) ) for returning 'aa' or 'bb' node.

Returns:
all nodes matching this criteria

getAttribute

public java.lang.String getAttribute(java.lang.String qname)
Returns:
an attribute value. null is returned for unknown attribute name

hasAttribute

public boolean hasAttribute(java.lang.String qname)
Returns:
true is the name attribute exists

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setNodeContent

public void setNodeContent(java.lang.String content)
Reset the node content

Specified by:
setNodeContent in interface MutableNode

getNodeContent

public java.lang.String getNodeContent()
Specified by:
getNodeContent in interface MutableNode
Returns:
the node content

setNodeParent

public void setNodeParent(MutableNode node)
Reset the node parent

Specified by:
setNodeParent in interface MutableNode

setNodeAttribute

public void setNodeAttribute(java.lang.String name,
                             java.lang.String value)
Reset the node attribute

Specified by:
setNodeAttribute in interface MutableNode

addNode

public void addNode(MutableNode node)
Reset the children

Specified by:
addNode in interface MutableNode

getViewAttributes

public java.util.Enumeration getViewAttributes()
Specified by:
getViewAttributes in interface ViewableNode
Returns:
the list of attributs or null

getViewAttribute

public java.lang.String getViewAttribute(java.lang.String name)
Specified by:
getViewAttribute in interface ViewableNode
Returns:
the attribute value for the name or null

getViewContent

public java.lang.String getViewContent()
Specified by:
getViewContent in interface ViewableNode
Returns:
the content of the node

isViewLeaf

public boolean isViewLeaf()
Specified by:
isViewLeaf in interface ViewableNode
Returns:
true is the node is a leaf

getViewChildCount

public int getViewChildCount()
Specified by:
getViewChildCount in interface ViewableNode
Returns:
the child count

getViewChildAt

public ViewableNode getViewChildAt(int i)
Specified by:
getViewChildAt in interface ViewableNode
Returns:
a child starting from 0

isViewText

public boolean isViewText()
Specified by:
isViewText in interface ViewableNode
Returns:
true for text node

isViewComment

public boolean isViewComment()
Specified by:
isViewComment in interface ViewableNode
Returns:
true for comment node

getNodeForXPathLocation

public SimpleNode getNodeForXPathLocation(java.lang.String xpath,
                                          boolean resolveAlways)
This feature is limited to a subset of the XPath set : /tag1[ location ]/tag2...

Returns:
a node for a single xpath location. 'resolveAlways' will help to return the best location even if a sub path is not available

getXPathLocation

public java.lang.String getXPathLocation()
Returns:
the XPath location for the current node

getXPathLocation

public java.lang.String getXPathLocation(SimpleNode node)
Returns:
the XPath location for the tied child node