nu.staldal.xmltree
Class Node

java.lang.Object
  extended by nu.staldal.xmltree.Node
All Implemented Interfaces:
java.io.Serializable, org.xml.sax.Locator
Direct Known Subclasses:
NodeWithChildren, ProcessingInstruction, Text

public abstract class Node
extends java.lang.Object
implements java.io.Serializable, org.xml.sax.Locator

Base class for a node in an XMLTree.

See Also:
Serialized Form

Field Summary
protected  NodeWithChildren parent
           
 
Constructor Summary
  Node()
          Default constructor.
protected Node(Node node)
          Copy constructor.
 
Method Summary
 java.net.URL getBaseURI()
          Returns the absolute base URI of this node.
 int getColumnNumber()
          Return the column number where this node ends.
 java.lang.String getInheritedAttribute(java.lang.String name)
          Return the value of an inherited attribute.
 int getLineNumber()
          Return the line number where this node ends.
 NodeWithChildren getParent()
          Get the parent of this node.
 boolean getPreserveSpace()
          Return the value of any xml:space attribute in force for this node.
 java.lang.String getPublicId()
          Return the public identifier for this node.
 java.lang.String getSystemId()
          Return the system identifier for this node.
 boolean isWhitespaceNode()
          Check if this node consist of whitespace only.
 java.lang.String lookupNamespacePrefix(java.lang.String URI)
          Lookup a prefix which has been mapped to a namespace URI.
 java.lang.String lookupNamespaceURI(java.lang.String prefix)
          Lookup the namespace URI which has been mapped to a prefix.
 void setColumn(int column)
           
 void setLine(int line)
           
 void setPublicId(java.lang.String publicId)
           
 void setSystemId(java.lang.String systemId)
           
abstract  void toSAX(org.xml.sax.ContentHandler sax)
          Serialize this node, and recursively the (sub)tree beneath, into SAX2 events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected NodeWithChildren parent
Constructor Detail

Node

public Node()
Default constructor.


Node

protected Node(Node node)
Copy constructor.

Parameters:
node - the node to copy
Method Detail

setPublicId

public void setPublicId(java.lang.String publicId)

setSystemId

public void setSystemId(java.lang.String systemId)

setLine

public void setLine(int line)

setColumn

public void setColumn(int column)

getParent

public NodeWithChildren getParent()
Get the parent of this node.

Returns:
the parent of this node, or null if this node has no parent.

toSAX

public abstract void toSAX(org.xml.sax.ContentHandler sax)
                    throws org.xml.sax.SAXException
Serialize this node, and recursively the (sub)tree beneath, into SAX2 events.

Parameters:
sax - the SAX2 ContentHander to fire events on.
Throws:
org.xml.sax.SAXException - if any of the ContentHandler methods throw it

getPublicId

public java.lang.String getPublicId()
Return the public identifier for this node. Useful for error reporting. The return value is the public identifier of the document entity or of the external parsed entity.

Specified by:
getPublicId in interface org.xml.sax.Locator
Returns:
A string containing the public identifier, or null if none is available.

getSystemId

public java.lang.String getSystemId()
Return the system identifier for this node. Useful for error reporting. The return value is the system identifier of the document entity or of the external parsed entity.

Specified by:
getSystemId in interface org.xml.sax.Locator
Returns:
A string containing the system identifier, or null if none is available.

getLineNumber

public int getLineNumber()
Return the line number where this node ends. Useful for error reporting. The return value is an approximation of the line number in the document entity or external parsed entity. The first line in the document is line 1.

Specified by:
getLineNumber in interface org.xml.sax.Locator
Returns:
The line number, or -1 if none is available.
See Also:
getColumnNumber()

getColumnNumber

public int getColumnNumber()
Return the column number where this node ends. Useful for error reporting. The return value is an approximation of the column number in the document entity or external parsed entity. The first column in each line is column 1.

Specified by:
getColumnNumber in interface org.xml.sax.Locator
Returns:
The column number, or -1 if none is available.
See Also:
getLineNumber()

lookupNamespaceURI

public java.lang.String lookupNamespaceURI(java.lang.String prefix)
Lookup the namespace URI which has been mapped to a prefix.

Parameters:
prefix - the prefix, may be the empty string which denotes the default namespace.
Returns:
the namespace URI, or null if the prefix is not mapped to any namespace URI, or the empty string of prefix is the empty string and there is no default namespace mapping.

lookupNamespacePrefix

public java.lang.String lookupNamespacePrefix(java.lang.String URI)
Lookup a prefix which has been mapped to a namespace URI.

Parameters:
URI - the namespace URI
Returns:
any of the prefixes which has been mapped to the namespace URI, or null if no prefix is mapped to the namespace URI.

getBaseURI

public java.net.URL getBaseURI()
Returns the absolute base URI of this node.

Returns:
the absolute base URI of this node, or null if unknown.

getPreserveSpace

public boolean getPreserveSpace()
Return the value of any xml:space attribute in force for this node.

Returns:
true if an xml:space="preserve" is in effect

getInheritedAttribute

public java.lang.String getInheritedAttribute(java.lang.String name)
Return the value of an inherited attribute. If the given attribute occurs on this node, return its value, otherwise recursivley search the parent of this node (return null if the root is reached without finding the attribute). Useful for e.g. xml:lang.

Parameters:
name - the attribute name
Returns:
null if no such attribute is found

isWhitespaceNode

public boolean isWhitespaceNode()
Check if this node consist of whitespace only.

Returns:
true if and only if this is a Text node which contains no other characters than whitespace.