org.apache.crimson.tree
Class TextNode

java.lang.Object
  extended byorg.apache.crimson.tree.NodeBase
      extended byorg.apache.crimson.tree.DataNode
          extended byorg.apache.crimson.tree.TextNode
All Implemented Interfaces:
org.w3c.dom.CharacterData, org.w3c.dom.Node, NodeEx, org.w3c.dom.NodeList, org.w3c.dom.Text, XmlWritable
Direct Known Subclasses:
CDataNode

public class TextNode
extends DataNode
implements org.w3c.dom.Text

Node representing XML text.

Subclasses should not currently attempt to modify the representation of content, but may add new methods to support more sophisticated access or manipulation of that content.

Author:
David Brownell

Nested Class Summary
(package private) static class DataNode.NodeListImpl
           
 
Field Summary
(package private) static DataNode.NodeListImpl childNodes
           
(package private)  char[] data
           
(package private)  XmlDocument ownerDocument
           
(package private)  boolean readonly
           
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
TextNode()
          Constructs a text object with no text and unattached to any document.
TextNode(char[] buf, int offset, int len)
          Constructs text object by copying text from the input buffer.
TextNode(String s)
          Constructs a text object by copying text from the string.
 
Method Summary
 org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
          DOM: Throws a HIERARCHY_REQUEST_ERR DOMException.
 void appendData(String newData)
          DOM: Appends the string to the existing stored data.
 org.w3c.dom.Node cloneNode(boolean deep)
          DOM: returns a new text node with the same contents as this one.
 void deleteData(int offset, int count)
          DOM: Removes a range of characters from the text.
 org.w3c.dom.NamedNodeMap getAttributes()
          DOM: returns null.
 org.w3c.dom.NodeList getChildNodes()
          DOM: Returns the children of this node.
 String getData()
          DOM: Returns the text data as a string.
 org.w3c.dom.Node getFirstChild()
          DOM: Returns null.
 int getIndexOf(org.w3c.dom.Node maybeChild)
          Returns the index of the node in the list of children, such that item() will return that child.
 String getInheritedAttribute(String name)
          Returns the value of a given attribute, tracing up through ancestors if needed.
 String getLanguage()
          Returns the language id (value of xml:lang attribute) applicable to this node, if known.
 org.w3c.dom.Node getLastChild()
          DOM: returns null.
 int getLength()
          DOM: Returns the length of the node's data.
 String getLocalName()
          DOM2: returns null.
(package private)  String getMessage(String messageId)
           
(package private)  String getMessage(String messageId, Object[] parameters)
           
 String getNamespaceURI()
          DOM2: returns null.
 org.w3c.dom.Node getNextSibling()
          DOM: Returns the node immediately following this node in a breadth first traversal of the tree, or null if there is no such sibling.
 String getNodeName()
          DOM: Returns the string "#text".
 short getNodeType()
          DOM: Returns the TEXT_NODE node type constant.
 String getNodeValue()
          DOM: Returns the node's character data.
 org.w3c.dom.Document getOwnerDocument()
          DOM: Returns the document to which this node belongs.
(package private)  ParentNode getParentImpl()
           
 org.w3c.dom.Node getParentNode()
          DOM: Returns the node's parent.
 String getPrefix()
          DOM2: returns null.
 org.w3c.dom.Node getPreviousSibling()
          DOM: Returns the node immediately preceding this node in a breadth first traversal of the tree, or null if there is no such sibling.
 char[] getText()
          Returns the text of the node.
 boolean hasAttributes()
          Returns whether this node (if it is an element) has any attributes.
 boolean hasChildNodes()
          DOM: Returns false.
 org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
          DOM: Throws a HIERARCHY_REQUEST_ERR DOMException.
 void insertData(int offset, String newData)
          DOM: Inserts the given data into the existing stored data at the specified offset.
 boolean isReadonly()
          Method to allow easy determination of whether a node is read only.
 boolean isSupported(String feature, String version)
          DOM2:
 org.w3c.dom.Node item(int i)
          DOM: Returns null.
 void joinNextText()
          Combines this text node with its next sibling to create a single text node.
 void normalize()
          DOM2: noop.
 org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
          DOM: Throws a HIERARCHY_REQUEST_ERR DOMException.
 org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
          DOM: Throws a HIERARCHY_REQUEST_ERR DOMException.
 void replaceData(int offset, int count, String arg)
          DOM: Replaces count characters starting at the specified offset in the data with the characters from the specified arg.
 void setData(String data)
          DOM: Assigns the text data.
 void setNodeValue(String value)
          DOM: Assigns the node's character data.
protected  void setOwnerDocument(XmlDocument doc)
           
(package private)  void setParentNode(ParentNode arg, int index)
           
 void setPrefix(String prefix)
          DOM2: throws DOMException.NAMESPACE_ERR Overridden by subclasses that support namespaces.
 void setReadonly(boolean deep)
          Sets the node to be readonly; applies recursively to the children of this node if the parameter is true.
 void setText(char[] buf)
          Assigns the text of the node.
 org.w3c.dom.Text splitText(int offset)
          DOM: Splits this text node into two, returning the part beginning at offset.
 String substringData(int offset, int count)
          DOM: Returns the specified substring of the data in this node.
 String toString()
          Returns the contents of this text as a String.
 void writeChildrenXml(XmlWriteContext context)
          Does nothing; this type of node has no children.
 void writeXml(XmlWriteContext context)
          Writes the text, escaping XML metacharacters as needed to let this text be parsed again without change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.CharacterData
appendData, deleteData, getData, getLength, insertData, replaceData, setData, substringData
 
Methods inherited from interface org.w3c.dom.Node
appendChild, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 

Field Detail

data

char[] data

childNodes

static DataNode.NodeListImpl childNodes

ownerDocument

XmlDocument ownerDocument

readonly

boolean readonly
Constructor Detail

TextNode

public TextNode()
Constructs a text object with no text and unattached to any document.


TextNode

public TextNode(char[] buf,
                int offset,
                int len)
Constructs text object by copying text from the input buffer.


TextNode

public TextNode(String s)
Constructs a text object by copying text from the string.

Method Detail

writeXml

public void writeXml(XmlWriteContext context)
              throws IOException
Writes the text, escaping XML metacharacters as needed to let this text be parsed again without change.

Specified by:
writeXml in interface XmlWritable
Throws:
IOException

joinNextText

public void joinNextText()
Combines this text node with its next sibling to create a single text node. If the next node is not text, nothing is done. This should be used with care, since large spans of text may not be efficient to represent.


getNodeType

public short getNodeType()
DOM: Returns the TEXT_NODE node type constant.

Specified by:
getNodeType in interface org.w3c.dom.Node

splitText

public org.w3c.dom.Text splitText(int offset)
                           throws org.w3c.dom.DOMException
DOM: Splits this text node into two, returning the part beginning at offset. The original node has that text removed, and the two nodes are siblings in the natural order.

Specified by:
splitText in interface org.w3c.dom.Text
Throws:
org.w3c.dom.DOMException

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
DOM: returns a new text node with the same contents as this one.

Specified by:
cloneNode in interface org.w3c.dom.Node

getNodeName

public String getNodeName()
DOM: Returns the string "#text".

Specified by:
getNodeName in interface org.w3c.dom.Node

getText

public char[] getText()
Returns the text of the node. This may be modified by the caller only if the length remains unchanged.


setText

public void setText(char[] buf)
Assigns the text of the node. The buffer is consumed; the caller should make copies accordingly.


toString

public String toString()
Returns the contents of this text as a String.

Overrides:
toString in class Object
Returns:
a string representation of the object.

getData

public String getData()
DOM: Returns the text data as a string.

Specified by:
getData in interface org.w3c.dom.CharacterData

setData

public void setData(String data)
DOM: Assigns the text data.

Specified by:
setData in interface org.w3c.dom.CharacterData

getLength

public int getLength()
DOM: Returns the length of the node's data.

Specified by:
getLength in interface org.w3c.dom.CharacterData
Overrides:
getLength in class NodeBase

substringData

public String substringData(int offset,
                            int count)
                     throws org.w3c.dom.DOMException
DOM: Returns the specified substring of the data in this node.

Specified by:
substringData in interface org.w3c.dom.CharacterData
Throws:
org.w3c.dom.DOMException

appendData

public void appendData(String newData)
DOM: Appends the string to the existing stored data.

Specified by:
appendData in interface org.w3c.dom.CharacterData

insertData

public void insertData(int offset,
                       String newData)
                throws org.w3c.dom.DOMException
DOM: Inserts the given data into the existing stored data at the specified offset.

Specified by:
insertData in interface org.w3c.dom.CharacterData
Throws:
org.w3c.dom.DOMException

deleteData

public void deleteData(int offset,
                       int count)
                throws org.w3c.dom.DOMException
DOM: Removes a range of characters from the text.

Specified by:
deleteData in interface org.w3c.dom.CharacterData
Throws:
org.w3c.dom.DOMException

replaceData

public void replaceData(int offset,
                        int count,
                        String arg)
                 throws org.w3c.dom.DOMException
DOM: Replaces count characters starting at the specified offset in the data with the characters from the specified arg.

Specified by:
replaceData in interface org.w3c.dom.CharacterData
Throws:
org.w3c.dom.DOMException

getChildNodes

public org.w3c.dom.NodeList getChildNodes()
DOM: Returns the children of this node.

Specified by:
getChildNodes in interface org.w3c.dom.Node
Overrides:
getChildNodes in class NodeBase

getNodeValue

public String getNodeValue()
DOM: Returns the node's character data.

Specified by:
getNodeValue in interface org.w3c.dom.Node
Overrides:
getNodeValue in class NodeBase

setNodeValue

public void setNodeValue(String value)
DOM: Assigns the node's character data.

Specified by:
setNodeValue in interface org.w3c.dom.Node
Overrides:
setNodeValue in class NodeBase

getParentImpl

ParentNode getParentImpl()

isReadonly

public boolean isReadonly()
Description copied from interface: NodeEx
Method to allow easy determination of whether a node is read only.

Specified by:
isReadonly in interface NodeEx
Returns:
true if the node is read only

setReadonly

public void setReadonly(boolean deep)
Description copied from interface: NodeEx
Sets the node to be readonly; applies recursively to the children of this node if the parameter is true.

Specified by:
setReadonly in interface NodeEx
Parameters:
deep - If true recursively set the nodes in the subtree under the current node to be read only. If false then set only the current node to be readonly

getLanguage

public String getLanguage()
Returns the language id (value of xml:lang attribute) applicable to this node, if known. Traces up through ancestors as needed.

Specified by:
getLanguage in interface NodeEx
Returns:
the value of the xml:lang attribute, or null if no such attribute is found.

getInheritedAttribute

public String getInheritedAttribute(String name)
Returns the value of a given attribute, tracing up through ancestors if needed. In the XML standard, two attributes are inherited: xml:lang and xml:space. This mechanism can also be involved with Cascading Style Sheets (CSS). The current version of XML Namespaces also uses inheritance.

Specified by:
getInheritedAttribute in interface NodeEx
Parameters:
name - identifies the attribute; colons may be included, but namespace prefixes are not interpreted
Returns:
the value of the inherited attribute, or null if no value was inherited.

writeChildrenXml

public void writeChildrenXml(XmlWriteContext context)
                      throws IOException
Does nothing; this type of node has no children.

Specified by:
writeChildrenXml in interface XmlWritable
Throws:
IOException

getParentNode

public org.w3c.dom.Node getParentNode()
DOM: Returns the node's parent. This will be null in cases such as newly created or removed nodes, and for attributes, fragments, and documents.

Specified by:
getParentNode in interface org.w3c.dom.Node

setParentNode

void setParentNode(ParentNode arg,
                   int index)
             throws org.w3c.dom.DOMException
Throws:
org.w3c.dom.DOMException

setOwnerDocument

protected void setOwnerDocument(XmlDocument doc)

getOwnerDocument

public org.w3c.dom.Document getOwnerDocument()
DOM: Returns the document to which this node belongs.

Specified by:
getOwnerDocument in interface org.w3c.dom.Node

hasChildNodes

public boolean hasChildNodes()
DOM: Returns false. Overridden by subclasses which support children.

Specified by:
hasChildNodes in interface org.w3c.dom.Node

getFirstChild

public org.w3c.dom.Node getFirstChild()
DOM: Returns null. Overridden by subclasses which support children.

Specified by:
getFirstChild in interface org.w3c.dom.Node

item

public org.w3c.dom.Node item(int i)
DOM: Returns null. Overridden by subclasses which support children.

Specified by:
item in interface org.w3c.dom.NodeList

getLastChild

public org.w3c.dom.Node getLastChild()
DOM: returns null. Overridden by subclasses which support children.

Specified by:
getLastChild in interface org.w3c.dom.Node

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
                             throws org.w3c.dom.DOMException
DOM: Throws a HIERARCHY_REQUEST_ERR DOMException. Overridden by subclasses which support children.

Specified by:
appendChild in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException - thrown always.

insertBefore

public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node refChild)
                              throws org.w3c.dom.DOMException
DOM: Throws a HIERARCHY_REQUEST_ERR DOMException. Overridden by subclasses which support children.

Specified by:
insertBefore in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException - thrown always.

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node refChild)
                              throws org.w3c.dom.DOMException
DOM: Throws a HIERARCHY_REQUEST_ERR DOMException. Overridden by subclasses which support children.

Specified by:
replaceChild in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException - thrown always.

removeChild

public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
                             throws org.w3c.dom.DOMException
DOM: Throws a HIERARCHY_REQUEST_ERR DOMException. Overridden by subclasses which support children.

Specified by:
removeChild in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException - thrown always.

getNextSibling

public org.w3c.dom.Node getNextSibling()
DOM: Returns the node immediately following this node in a breadth first traversal of the tree, or null if there is no such sibling. In this implementation, sibling access from a node is slower than indexed access from its parent.

Specified by:
getNextSibling in interface org.w3c.dom.Node

getPreviousSibling

public org.w3c.dom.Node getPreviousSibling()
DOM: Returns the node immediately preceding this node in a breadth first traversal of the tree, or null if there is no such sibling. In this implementation, sibling access from a node is slower than indexed access from its parent.

Specified by:
getPreviousSibling in interface org.w3c.dom.Node

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()
DOM: returns null. Overridden by the ElementNode2 subclass.

Specified by:
getAttributes in interface org.w3c.dom.Node

normalize

public void normalize()
DOM2: noop.

Specified by:
normalize in interface org.w3c.dom.Node
Since:
DOM Level 2 Overridden by subclasses that need to support normalization.

isSupported

public boolean isSupported(String feature,
                           String version)
DOM2:

Specified by:
isSupported in interface org.w3c.dom.Node
Since:
DOM Level 2

getNamespaceURI

public String getNamespaceURI()
DOM2: returns null. Overridden by subclasses that support namespaces, ie. ElementNode2 and AttributeNode.

Specified by:
getNamespaceURI in interface org.w3c.dom.Node

getPrefix

public String getPrefix()
DOM2: returns null. Overridden by subclasses that support namespaces.

Specified by:
getPrefix in interface org.w3c.dom.Node

setPrefix

public void setPrefix(String prefix)
               throws org.w3c.dom.DOMException
DOM2: throws DOMException.NAMESPACE_ERR Overridden by subclasses that support namespaces.

Specified by:
setPrefix in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException

getLocalName

public String getLocalName()
DOM2: returns null. Overridden by subclasses that support namespaces.

Specified by:
getLocalName in interface org.w3c.dom.Node

hasAttributes

public boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes. Overridden by Element implementations

Specified by:
hasAttributes in interface org.w3c.dom.Node
Since:
DOM Level 2

getIndexOf

public int getIndexOf(org.w3c.dom.Node maybeChild)
Description copied from interface: NodeEx
Returns the index of the node in the list of children, such that item() will return that child.

Specified by:
getIndexOf in interface NodeEx
Parameters:
maybeChild - the node which may be a child of this one
Returns:
the index of the node in the set of children, or else -1 if that node is not a child of this node.

getMessage

String getMessage(String messageId)

getMessage

String getMessage(String messageId,
                  Object[] parameters)