com.japisoft.fastparser.node
Class SimpleNode

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

public class SimpleNode
extends java.lang.Object
implements com.japisoft.fastparser.node.MutableNode, com.japisoft.fastparser.node.ViewableNode

Simple node.

Since:
1.0
Version:
1.5
Author:
(c) 2002-2003 JAPISoft

Field Summary
static int COMMENT_NODE
           
static int DOCUMENT_NODE
           
static int TAG_NODE
           
static int TEXT_NODE
           
 
Constructor Summary
SimpleNode(int type, java.lang.String content)
           
SimpleNode(com.japisoft.fastparser.node.SimpleNode parent, int type, java.lang.String content)
           
SimpleNode(java.lang.String content)
          Create a tag node
 
Method Summary
 void addChildNode(com.japisoft.fastparser.node.SimpleNode node)
          Insert a new node
 void addNameSpaceDeclaration(java.lang.String prefix, java.lang.String uri)
          Add a declaration for nameSpace
 void addNode(com.japisoft.fastparser.node.MutableNode node)
          Reset the children
 com.japisoft.fastparser.node.SimpleNode childAt(int index)
           
 int childCount()
           
 int childNodeIndex(com.japisoft.fastparser.node.SimpleNode node)
           
 com.japisoft.fastparser.node.SimpleNode clone(boolean deep)
          Clone the current node, include subchild if deep is true
 java.lang.String closeDeclaration()
           
 java.util.Enumeration getAllChild()
          Get all child
 java.lang.Object getApplicationObject()
           
 java.lang.String getAttribute(java.lang.String qname)
           
 java.lang.String getAttribute(java.lang.String qname, java.lang.String defaultValue)
           
 java.lang.String getCachedXPathLocation()
           
 java.lang.String getContent()
           
 java.lang.String getDefaultNamespace()
           
 com.japisoft.fastparser.document.Document getDocument()
           
 java.lang.String getFirstAttributeValue()
           
 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(com.japisoft.fastparser.walker.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()
           
 com.japisoft.fastparser.node.SimpleNode getNodeForXPathLocation(java.lang.String xpath, boolean resolveAlways)
          This feature is limited to a subset of the XPath set : /tag1[ location ]/tag2...
 java.lang.String getQualifiedContent()
           
 java.lang.String getRawXML()
           
 com.japisoft.fastparser.node.SimpleNode getSimpleParent()
           
 int getStartingLine()
           
 int getStartingOffset()
           
 int getStoppingLine()
           
 int getStoppingOffset()
           
 int getType()
           
 java.lang.String getViewAttribute(java.lang.String name)
           
 java.lang.String getViewAttributeAt(int index)
           
 int getViewAttributeCount()
           
 java.util.Enumeration getViewAttributes()
           
 com.japisoft.fastparser.node.ViewableNode getViewChildAt(int i)
           
 int getViewChildCount()
           
 java.lang.String getViewContent()
           
 java.lang.String getXPathLocation()
           
 java.lang.String getXPathLocation(com.japisoft.fastparser.node.SimpleNode node)
           
 boolean hasAttribute(java.lang.String qname)
           
 void insertChildNode(int index, com.japisoft.fastparser.node.SimpleNode node)
          Insert a childnode at the index location
 boolean isClosedLeaf()
          Particular way to know the tag declaration is in the <A/> form rather than <A></A>
 boolean isComment()
           
 boolean isLeaf()
           
 boolean isNamespaceDeclared(java.lang.String prefix)
           
 boolean isRoot()
           
 boolean isTag()
           
 boolean isText()
           
 boolean isViewComment()
           
 boolean isViewLeaf()
           
 boolean isViewText()
           
 boolean matchContent(java.lang.String val)
           
 java.lang.String openDeclaration()
           
 void removeAllNameSpaceDeclaration()
          Remove all the nameSpace declaration
 void removeChildNode(com.japisoft.fastparser.node.SimpleNode node)
          Remove the following node
 void removeChildNodeAt(int index)
           
 void removeChildrenNodes()
          Remove all the children
 void removeNameSpaceDeclaration(java.lang.String prefix)
          Remove a nameSpace prefix declaration
 void replaceChildNode(com.japisoft.fastparser.node.SimpleNode oldNode, com.japisoft.fastparser.node.SimpleNode newNode)
          Replace this oldNode by this newOne
 void setApplicationObject(java.lang.Object obj)
          Store an application object in this node
 void setAttribute(java.lang.String qname, boolean value)
          Reset the attribute value
 void setAttribute(java.lang.String qname, double value)
          Reset the attribute value
 void setAttribute(java.lang.String qname, int value)
          Reset the attribute value
 void setAttribute(java.lang.String qname, java.lang.String value)
          Set the attribute value.
 void setClosedLeaf(boolean closedLeaf)
          Particular way to know the tag declaration is in the <A/> form rather than <A></A>
 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(com.japisoft.fastparser.document.Document doc)
          Owner document for this node
 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(com.japisoft.fastparser.node.MutableNode node)
          Reset the node parent
 void setSimpleParent(com.japisoft.fastparser.node.SimpleNode node)
          reset the parent node
 void setStartingLine(int line)
          Set the node line location
 void setStartingOffset(int i)
           
 void setStoppingLine(int i)
           
 void setStoppingOffset(int i)
           
 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

DOCUMENT_NODE

public static final int DOCUMENT_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(java.lang.String content)
Create a tag node


SimpleNode

public SimpleNode(com.japisoft.fastparser.node.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

getStartingOffset

public int getStartingOffset()
Specified by:
getStartingOffset in interface com.japisoft.fastparser.node.ViewableNode
Returns:
the current tag starting offset

getStoppingOffset

public int getStoppingOffset()
Specified by:
getStoppingOffset in interface com.japisoft.fastparser.node.ViewableNode
Returns:
the current tag stopping offset

setStartingOffset

public void setStartingOffset(int i)
Specified by:
setStartingOffset in interface com.japisoft.fastparser.node.MutableNode
Parameters:
i - the current tag starting offset

setStoppingOffset

public void setStoppingOffset(int i)
Specified by:
setStoppingOffset in interface com.japisoft.fastparser.node.MutableNode
Parameters:
i - the current tag stopping offset

setStartingLine

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

Specified by:
setStartingLine in interface com.japisoft.fastparser.node.MutableNode

getStartingLine

public int getStartingLine()
Specified by:
getStartingLine in interface com.japisoft.fastparser.node.ViewableNode
Returns:
the starting line location

getStoppingLine

public int getStoppingLine()
Specified by:
getStoppingLine in interface com.japisoft.fastparser.node.ViewableNode
Returns:
the stopping line

setStoppingLine

public void setStoppingLine(int i)
Specified by:
setStoppingLine in interface com.japisoft.fastparser.node.MutableNode
Parameters:
i - reset the stopping line

addNameSpaceDeclaration

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

Specified by:
addNameSpaceDeclaration in interface com.japisoft.fastparser.node.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 com.japisoft.fastparser.node.MutableNode

removeAllNameSpaceDeclaration

public void removeAllNameSpaceDeclaration()
Remove all the nameSpace declaration


getNameSpaceDeclaration

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

getNameSpaceDeclarationURI

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

isNamespaceDeclared

public boolean isNamespaceDeclared(java.lang.String prefix)
Specified by:
isNamespaceDeclared in interface com.japisoft.fastparser.node.MutableNode
Returns:
true if this prefix is delcared inside this node

getNamespaceDeclared

public java.util.Enumeration getNamespaceDeclared()
Specified by:
getNamespaceDeclared in interface com.japisoft.fastparser.node.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 com.japisoft.fastparser.node.MutableNode
Parameters:
name - Namespace prefix

getNameSpacePrefix

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

getNameSpaceURI

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

setDefaultNamespace

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

Specified by:
setDefaultNamespace in interface com.japisoft.fastparser.node.MutableNode

getDefaultNamespace

public java.lang.String getDefaultNamespace()
Specified by:
getDefaultNamespace in interface com.japisoft.fastparser.node.MutableNode
Returns:
the default namespace

setDocument

public void setDocument(com.japisoft.fastparser.document.Document doc)
Owner document for this node


getDocument

public com.japisoft.fastparser.document.Document getDocument()
Returns:
the owner document

clone

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


setSimpleParent

public void setSimpleParent(com.japisoft.fastparser.node.SimpleNode node)
reset the parent node


getSimpleParent

public com.japisoft.fastparser.node.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

matchContent

public boolean matchContent(java.lang.String val)

getQualifiedContent

public java.lang.String getQualifiedContent()
Returns:
the content with a namespace prefix if needed

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,
                            com.japisoft.fastparser.node.SimpleNode node)
Insert a childnode at the index location


replaceChildNode

public void replaceChildNode(com.japisoft.fastparser.node.SimpleNode oldNode,
                             com.japisoft.fastparser.node.SimpleNode newNode)
Replace this oldNode by this newOne


addChildNode

public void addChildNode(com.japisoft.fastparser.node.SimpleNode node)
Insert a new node


removeChildrenNodes

public void removeChildrenNodes()
Remove all the children


removeChildNode

public void removeChildNode(com.japisoft.fastparser.node.SimpleNode node)
Remove the following node


removeChildNodeAt

public void removeChildNodeAt(int index)

childNodeIndex

public int childNodeIndex(com.japisoft.fastparser.node.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 com.japisoft.fastparser.node.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

setAttribute

public void setAttribute(java.lang.String qname,
                         int value)
Reset the attribute value


setAttribute

public void setAttribute(java.lang.String qname,
                         double value)
Reset the attribute value


setAttribute

public void setAttribute(java.lang.String qname,
                         boolean value)
Reset the attribute value


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

getFirstAttributeValue

public java.lang.String getFirstAttributeValue()
Returns:
the first attribute value

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(com.japisoft.fastparser.walker.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 com.japisoft.fastparser.node.MutableNode

getNodeContent

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

setNodeParent

public void setNodeParent(com.japisoft.fastparser.node.MutableNode node)
Reset the node parent

Specified by:
setNodeParent in interface com.japisoft.fastparser.node.MutableNode

setNodeAttribute

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

Specified by:
setNodeAttribute in interface com.japisoft.fastparser.node.MutableNode

addNode

public void addNode(com.japisoft.fastparser.node.MutableNode node)
Reset the children

Specified by:
addNode in interface com.japisoft.fastparser.node.MutableNode

getViewAttributes

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

getViewAttributeAt

public java.lang.String getViewAttributeAt(int index)
Returns:
the attribute for this index

getViewAttributeCount

public int getViewAttributeCount()
Returns:
the number of attribute

getViewAttribute

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

getViewContent

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

isViewLeaf

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

getViewChildCount

public int getViewChildCount()
Specified by:
getViewChildCount in interface com.japisoft.fastparser.node.ViewableNode
Returns:
the child count

getViewChildAt

public com.japisoft.fastparser.node.ViewableNode getViewChildAt(int i)
Specified by:
getViewChildAt in interface com.japisoft.fastparser.node.ViewableNode
Returns:
a child starting from 0

isViewText

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

isViewComment

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

getNodeForXPathLocation

public com.japisoft.fastparser.node.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

getCachedXPathLocation

public java.lang.String getCachedXPathLocation()
Returns:
the current XPath location caching the last value. This is only useful for readonly document

getXPathLocation

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

getRawXML

public java.lang.String getRawXML()
Returns:
a raw text view of this XML node

openDeclaration

public java.lang.String openDeclaration()
Returns:
a string with the opening value. This is only for tag type

closeDeclaration

public java.lang.String closeDeclaration()
Returns:
a string with the closing value. This is only for tag type

setClosedLeaf

public void setClosedLeaf(boolean closedLeaf)
Particular way to know the tag declaration is in the <A/> form rather than <A></A>

Specified by:
setClosedLeaf in interface com.japisoft.fastparser.node.MutableNode

isClosedLeaf

public boolean isClosedLeaf()
Particular way to know the tag declaration is in the <A/> form rather than <A></A>


setApplicationObject

public void setApplicationObject(java.lang.Object obj)
Store an application object in this node


getApplicationObject

public java.lang.Object getApplicationObject()
Returns:
the current application object