Class TextImpl

All Implemented Interfaces:
Cloneable, CharacterData, EventTarget, Node, NodeList, Text
Direct Known Subclasses:
CDATASectionImpl

public class TextImpl extends CharacterDataImpl implements Text
Text nodes hold the non-markup, non-Entity content of an Element or Attribute.

When a document is first made available to the DOM, there is only one Text object for each block of adjacent plain-text. Users (ie, applications) may create multiple adjacent Texts during editing -- see Node.normalize() for discussion.

Note that CDATASection is a subclass of Text. This is conceptually valid, since they're really just two different ways of quoting characters when they're written out as part of an XML stream.

  • Constructor Details

  • Method Details

    • getNodeType

      public short getNodeType()
      A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface. A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface.
      Specified by:
      getNodeType in interface Node
      Specified by:
      getNodeType in class NodeImpl
    • getNodeName

      public String getNodeName()
      the name of this node.
      Specified by:
      getNodeName in interface Node
      Specified by:
      getNodeName in class NodeImpl
    • isElementContentWhitespace

      public boolean isElementContentWhitespace()
      DOM L3 Core CR - Experimental

      Returns 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 using Document.normalizeDocument().

      Specified by:
      isElementContentWhitespace in interface Text
    • getWholeText

      public String getWholeText()
      DOM Level 3 WD - Experimental. Returns all text of Text nodes logically-adjacent text nodes to this node, concatenated in document order.
      Specified by:
      getWholeText in interface Text
    • insertTextContent

      protected void insertTextContent(StringBuilder builder) throws DOMException
      internal method taking a StringBuffer in parameter and inserts the text content at the start of the buffer
      Parameters:
      builder - string buffer
      Throws:
      DOMException - on error
    • getWholeTextForward

      private boolean getWholeTextForward(Node node, StringBuilder builder, Node parent)
      Concatenates the text of all logically-adjacent text nodes to the right of this node
      Parameters:
      node - the node
      builder - the StringBuilder
      parent - the parent
      Returns:
      true - if execution was stopped because the type of node other than EntityRef, Text, CDATA is encountered, otherwise return false
    • getWholeTextBackward

      private boolean getWholeTextBackward(Node node, StringBuilder builder, Node parent)
      Concatenates the text of all logically-adjacent text nodes to the left of the node
      Parameters:
      node - the node
      builder - the StringBuilder
      parent - the parent
      Returns:
      true - if execution was stopped because the type of node other than EntityRef, Text, CDATA is encountered, otherwise return false
    • replaceWholeText

      public Text replaceWholeText(String content) throws DOMException
      Replaces 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.
      Specified by:
      replaceWholeText in interface Text
      Parameters:
      content - The content of the replacing Text node.
      Returns:
      text - The Text node created with the specified content.
      Throws:
      DOMException
    • canModifyPrev

      private boolean canModifyPrev(Node node)
      If any EntityReference to be removed has descendants that are not EntityReference, Text, or CDATASection nodes, the replaceWholeText method must fail before performing any modification of the document, raising a DOMException with the code NO_MODIFICATION_ALLOWED_ERR. Traverse previous siblings of the node to be replaced. If a previous sibling is an EntityReference node, get it's last child. If the last child was a Text or CDATASection node and its previous siblings are neither a replaceable EntityReference or Text or CDATASection nodes, return false. IF the last child was neither Text nor CDATASection nor a replaceable EntityReference Node, then return true. If the last child was a Text or CDATASection node any its previous sibling was not or was an EntityReference that did not contain only Text or CDATASection nodes, return false. Check this recursively for EntityReference nodes.
      Parameters:
      node - the node
      Returns:
      true - can replace text false - can't replace exception must be raised
    • canModifyNext

      private boolean canModifyNext(Node node)
      If any EntityReference to be removed has descendants that are not EntityReference, Text, or CDATASection nodes, the replaceWholeText method must fail before performing any modification of the document, raising a DOMException with the code NO_MODIFICATION_ALLOWED_ERR. Traverse previous siblings of the node to be replaced. If a previous sibling is an EntityReference node, get it's last child. If the first child was a Text or CDATASection node and its next siblings are neither a replaceable EntityReference or Text or CDATASection nodes, return false. IF the first child was neither Text nor CDATASection nor a replaceable EntityReference Node, then return true. If the first child was a Text or CDATASection node any its next sibling was not or was an EntityReference that did not contain only Text or CDATASection nodes, return false. Check this recursively for EntityReference nodes.
      Parameters:
      node - the node
      Returns:
      true - can replace text false - can't replace exception must be raised
    • hasTextOnlyChildren

      private boolean hasTextOnlyChildren(Node node)
      Check if an EntityReference node has Text Only child nodes
      Parameters:
      node - the node
      Returns:
      true - Contains text only children
    • splitText

      public Text splitText(int offset) throws DOMException
      Break a text node into two sibling nodes. (Note that if the current node has no parent, they won't wind up as "siblings" -- they'll both be orphans.)
      Specified by:
      splitText in interface Text
      Parameters:
      offset - The offset at which to split. If offset is at the end of the available data, the second node will be empty.
      Returns:
      A reference to the new node (containing data after the offset point). The original node will contain data up to that point.
      Throws:
      DOMException - INDEX_SIZE_ERR if offset is < 0 or > length.
      DOMException - NO_MODIFICATION_ALLOWED_ERR if node is read-only.
    • replaceData

      public void replaceData(String value)
    • removeData

      public String removeData()