1. /*
  2. * Copyright (c) 2004 World Wide Web Consortium,
  3. *
  4. * (Massachusetts Institute of Technology, European Research Consortium for
  5. * Informatics and Mathematics, Keio University). All Rights Reserved. This
  6. * work is distributed under the W3C(r) Software License [1] in the hope that
  7. * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  8. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *
  10. * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
  11. */
  12. package org.w3c.dom;
  13. /**
  14. * The <code>Text</code> interface inherits from <code>CharacterData</code>
  15. * and represents the textual content (termed <a href='http://www.w3.org/TR/2004/REC-xml-20040204#syntax'>character data</a> in XML) of an <code>Element</code> or <code>Attr</code>. If there is no
  16. * markup inside an element's content, the text is contained in a single
  17. * object implementing the <code>Text</code> interface that is the only
  18. * child of the element. If there is markup, it is parsed into the
  19. * information items (elements, comments, etc.) and <code>Text</code> nodes
  20. * that form the list of children of the element.
  21. * <p>When a document is first made available via the DOM, there is only one
  22. * <code>Text</code> node for each block of text. Users may create adjacent
  23. * <code>Text</code> nodes that represent the contents of a given element
  24. * without any intervening markup, but should be aware that there is no way
  25. * to represent the separations between these nodes in XML or HTML, so they
  26. * will not (in general) persist between DOM editing sessions. The
  27. * <code>Node.normalize()</code> method merges any such adjacent
  28. * <code>Text</code> objects into a single node for each block of text.
  29. * <p> No lexical check is done on the content of a <code>Text</code> node
  30. * and, depending on its position in the document, some characters must be
  31. * escaped during serialization using character references; e.g. the
  32. * characters "<&" if the textual content is part of an element or of
  33. * an attribute, the character sequence "]]>" when part of an element,
  34. * the quotation mark character " or the apostrophe character ' when part of
  35. * an attribute.
  36. * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>Document Object Model (DOM) Level 3 Core Specification</a>.
  37. */
  38. public interface Text extends CharacterData {
  39. /**
  40. * Breaks this node into two nodes at the specified <code>offset</code>,
  41. * keeping both in the tree as siblings. After being split, this node
  42. * will contain all the content up to the <code>offset</code> point. A
  43. * new node of the same type, which contains all the content at and
  44. * after the <code>offset</code> point, is returned. If the original
  45. * node had a parent node, the new node is inserted as the next sibling
  46. * of the original node. When the <code>offset</code> is equal to the
  47. * length of this node, the new node has no data.
  48. * @param offset The 16-bit unit offset at which to split, starting from
  49. * <code>0</code>.
  50. * @return The new node, of the same type as this node.
  51. * @exception DOMException
  52. * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
  53. * than the number of 16-bit units in <code>data</code>.
  54. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  55. */
  56. public Text splitText(int offset)
  57. throws DOMException;
  58. /**
  59. * Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>
  60. * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is
  61. * determined to contain whitespace in element content during the load
  62. * of the document or if validation occurs while using
  63. * <code>Document.normalizeDocument()</code>.
  64. * @since DOM Level 3
  65. */
  66. public boolean isElementContentWhitespace();
  67. /**
  68. * Returns all text of <code>Text</code> nodes logically-adjacent text
  69. * nodes to this node, concatenated in document order.
  70. * <br>For instance, in the example below <code>wholeText</code> on the
  71. * <code>Text</code> node that contains "bar" returns "barfoo", while on
  72. * the <code>Text</code> node that contains "foo" it returns "barfoo".
  73. * @since DOM Level 3
  74. */
  75. public String getWholeText();
  76. /**
  77. * Replaces the text of the current node and all logically-adjacent text
  78. * nodes with the specified text. All logically-adjacent text nodes are
  79. * removed including the current node unless it was the recipient of the
  80. * replacement text.
  81. * <br>This method returns the node which received the replacement text.
  82. * The returned node is:
  83. * <ul>
  84. * <li><code>null</code>, when the replacement text is
  85. * the empty string;
  86. * </li>
  87. * <li>the current node, except when the current node is
  88. * read-only;
  89. * </li>
  90. * <li> a new <code>Text</code> node of the same type (
  91. * <code>Text</code> or <code>CDATASection</code>) as the current node
  92. * inserted at the location of the replacement.
  93. * </li>
  94. * </ul>
  95. * <br>For instance, in the above example calling
  96. * <code>replaceWholeText</code> on the <code>Text</code> node that
  97. * contains "bar" with "yo" in argument results in the following:
  98. * <br>Where the nodes to be removed are read-only descendants of an
  99. * <code>EntityReference</code>, the <code>EntityReference</code> must
  100. * be removed instead of the read-only nodes. If any
  101. * <code>EntityReference</code> to be removed has descendants that are
  102. * not <code>EntityReference</code>, <code>Text</code>, or
  103. * <code>CDATASection</code> nodes, the <code>replaceWholeText</code>
  104. * method must fail before performing any modification of the document,
  105. * raising a <code>DOMException</code> with the code
  106. * <code>NO_MODIFICATION_ALLOWED_ERR</code>.
  107. * <br>For instance, in the example below calling
  108. * <code>replaceWholeText</code> on the <code>Text</code> node that
  109. * contains "bar" fails, because the <code>EntityReference</code> node
  110. * "ent" contains an <code>Element</code> node which cannot be removed.
  111. * @param content The content of the replacing <code>Text</code> node.
  112. * @return The <code>Text</code> node created with the specified content.
  113. * @exception DOMException
  114. * NO_MODIFICATION_ALLOWED_ERR: Raised if one of the <code>Text</code>
  115. * nodes being replaced is readonly.
  116. * @since DOM Level 3
  117. */
  118. public Text replaceWholeText(String content)
  119. throws DOMException;
  120. }