Package org.apache.harmony.xml.dom
Class TextImpl
- java.lang.Object
-
- org.apache.harmony.xml.dom.NodeImpl
-
- org.apache.harmony.xml.dom.LeafNodeImpl
-
- org.apache.harmony.xml.dom.CharacterDataImpl
-
- org.apache.harmony.xml.dom.TextImpl
-
- All Implemented Interfaces:
CharacterData,Node,Text
- Direct Known Subclasses:
CDATASectionImpl
public class TextImpl extends CharacterDataImpl implements Text
Provides a straightforward implementation of the corresponding W3C DOM interface. The class is used internally only, thus only notable members that are not in the original interface are documented (the W3C docs are quite extensive). Hope that's ok.Some of the fields may have package visibility, so other classes belonging to the DOM implementation can easily access them while maintaining the DOM tree structure.
-
-
Field Summary
-
Fields inherited from class org.apache.harmony.xml.dom.CharacterDataImpl
buffer
-
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
-
Constructor Summary
Constructors Constructor Description TextImpl(DocumentImpl document, String data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetNodeName()The name of this node, depending on its type; see the table above.shortgetNodeType()A code representing the type of the underlying object, as defined above.StringgetWholeText()Returns all text ofTextnodes logically-adjacent text nodes to this node, concatenated in document order.booleanisElementContentWhitespace()Returns whether this text node contains element content whitespace, often abusively called "ignorable whitespace".TextImplminimize()Tries to remove this node using itself and the previous node as context.TextreplaceWholeText(String content)Replaces the text of the current node and all logically-adjacent text nodes with the specified text.TextsplitText(int offset)Breaks this node into two nodes at the specifiedoffset, keeping both in the tree as siblings.-
Methods inherited from class org.apache.harmony.xml.dom.CharacterDataImpl
appendData, appendDataTo, deleteData, getData, getLength, getNodeValue, insertData, replaceData, setData, substringData
-
Methods inherited from class org.apache.harmony.xml.dom.LeafNodeImpl
getNextSibling, getParentNode, getPreviousSibling
-
Methods inherited from class org.apache.harmony.xml.dom.NodeImpl
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getOwnerDocument, getPrefix, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
-
-
-
-
Constructor Detail
-
TextImpl
public TextImpl(DocumentImpl document, String data)
-
-
Method Detail
-
getNodeName
public String getNodeName()
Description copied from interface:NodeThe name of this node, depending on its type; see the table above.- Specified by:
getNodeNamein interfaceNode- Overrides:
getNodeNamein classNodeImpl
-
getNodeType
public short getNodeType()
Description copied from interface:NodeA code representing the type of the underlying object, as defined above.- Specified by:
getNodeTypein interfaceNode- Specified by:
getNodeTypein classNodeImpl
-
splitText
public final Text splitText(int offset) throws DOMException
Description copied from interface:TextBreaks this node into two nodes at the specifiedoffset, keeping both in the tree as siblings. After being split, this node will contain all the content up to theoffsetpoint. A new node of the same type, which contains all the content at and after theoffsetpoint, is returned. If the original node had a parent node, the new node is inserted as the next sibling of the original node. When theoffsetis equal to the length of this node, the new node has no data.- Specified by:
splitTextin interfaceText- Parameters:
offset- The 16-bit unit offset at which to split, starting from0.- Returns:
- The new node, of the same type as this node.
- Throws:
DOMException- INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit units indata.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
-
isElementContentWhitespace
public final boolean isElementContentWhitespace()
Description copied from interface:TextReturns whether this text node contains element content whitespace, often abusively called "ignorable whitespace". The text node is determined to contain whitespace in element content during the load of the document or if validation occurs while usingDocument.normalizeDocument().- Specified by:
isElementContentWhitespacein interfaceText
-
getWholeText
public final String getWholeText()
Description copied from interface:TextReturns all text ofTextnodes logically-adjacent text nodes to this node, concatenated in document order.
For instance, in the example belowwholeTexton theTextnode that contains "bar" returns "barfoo", while on theTextnode that contains "foo" it returns "barfoo".- Specified by:
getWholeTextin interfaceText
-
replaceWholeText
public final Text replaceWholeText(String content) throws DOMException
Description copied from interface:TextReplaces the text of the current node and all logically-adjacent text nodes with the specified text. All logically-adjacent text nodes are removed including the current node unless it was the recipient of the replacement text.
This method returns the node which received the replacement text. The returned node is:null, when the replacement text is the empty string;- the current node, except when the current node is read-only;
- a new
Textnode of the same type (TextorCDATASection) as the current node inserted at the location of the replacement.
For instance, in the above example callingreplaceWholeTexton theTextnode that contains "bar" with "yo" in argument results in the following:
Where the nodes to be removed are read-only descendants of anEntityReference, theEntityReferencemust be removed instead of the read-only nodes. If anyEntityReferenceto be removed has descendants that are notEntityReference,Text, orCDATASectionnodes, thereplaceWholeTextmethod must fail before performing any modification of the document, raising aDOMExceptionwith the codeNO_MODIFICATION_ALLOWED_ERR.
For instance, in the example below callingreplaceWholeTexton theTextnode that contains "bar" fails, because theEntityReferencenode "ent" contains anElementnode which cannot be removed.- Specified by:
replaceWholeTextin interfaceText- Parameters:
content- The content of the replacingTextnode.- Returns:
- The
Textnode created with the specified content. - Throws:
DOMException- NO_MODIFICATION_ALLOWED_ERR: Raised if one of theTextnodes being replaced is readonly.
-
minimize
public final TextImpl minimize()
Tries to remove this node using itself and the previous node as context. If this node's text is empty, this node is removed and null is returned. If the previous node exists and is a text node, this node's text will be appended to that node's text and this node will be removed.Although this method alters the structure of the DOM tree, it does not alter the document's semantics.
- Returns:
- the node holding this node's text and the end of the operation. Can be null if this node contained the empty string.
-
-