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>CharacterData</code> interface extends Node with a set of
  15. * attributes and methods for accessing character data in the DOM. For
  16. * clarity this set is defined here rather than on each object that uses
  17. * these attributes and methods. No DOM objects correspond directly to
  18. * <code>CharacterData</code>, though <code>Text</code> and others do
  19. * inherit the interface from it. All <code>offsets</code> in this interface
  20. * start from <code>0</code>.
  21. * <p>As explained in the <code>DOMString</code> interface, text strings in
  22. * the DOM are represented in UTF-16, i.e. as a sequence of 16-bit units. In
  23. * the following, the term 16-bit units is used whenever necessary to
  24. * indicate that indexing on CharacterData is done in 16-bit units.
  25. * <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>.
  26. */
  27. public interface CharacterData extends Node {
  28. /**
  29. * The character data of the node that implements this interface. The DOM
  30. * implementation may not put arbitrary limits on the amount of data
  31. * that may be stored in a <code>CharacterData</code> node. However,
  32. * implementation limits may mean that the entirety of a node's data may
  33. * not fit into a single <code>DOMString</code>. In such cases, the user
  34. * may call <code>substringData</code> to retrieve the data in
  35. * appropriately sized pieces.
  36. * @exception DOMException
  37. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  38. * fit in a <code>DOMString</code> variable on the implementation
  39. * platform.
  40. */
  41. public String getData()
  42. throws DOMException;
  43. /**
  44. * The character data of the node that implements this interface. The DOM
  45. * implementation may not put arbitrary limits on the amount of data
  46. * that may be stored in a <code>CharacterData</code> node. However,
  47. * implementation limits may mean that the entirety of a node's data may
  48. * not fit into a single <code>DOMString</code>. In such cases, the user
  49. * may call <code>substringData</code> to retrieve the data in
  50. * appropriately sized pieces.
  51. * @exception DOMException
  52. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  53. */
  54. public void setData(String data)
  55. throws DOMException;
  56. /**
  57. * The number of 16-bit units that are available through <code>data</code>
  58. * and the <code>substringData</code> method below. This may have the
  59. * value zero, i.e., <code>CharacterData</code> nodes may be empty.
  60. */
  61. public int getLength();
  62. /**
  63. * Extracts a range of data from the node.
  64. * @param offset Start offset of substring to extract.
  65. * @param count The number of 16-bit units to extract.
  66. * @return The specified substring. If the sum of <code>offset</code> and
  67. * <code>count</code> exceeds the <code>length</code>, then all 16-bit
  68. * units to the end of the data are returned.
  69. * @exception DOMException
  70. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  71. * negative or greater than the number of 16-bit units in
  72. * <code>data</code>, or if the specified <code>count</code> is
  73. * negative.
  74. * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
  75. * not fit into a <code>DOMString</code>.
  76. */
  77. public String substringData(int offset,
  78. int count)
  79. throws DOMException;
  80. /**
  81. * Append the string to the end of the character data of the node. Upon
  82. * success, <code>data</code> provides access to the concatenation of
  83. * <code>data</code> and the <code>DOMString</code> specified.
  84. * @param arg The <code>DOMString</code> to append.
  85. * @exception DOMException
  86. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  87. */
  88. public void appendData(String arg)
  89. throws DOMException;
  90. /**
  91. * Insert a string at the specified 16-bit unit offset.
  92. * @param offset The character offset at which to insert.
  93. * @param arg The <code>DOMString</code> to insert.
  94. * @exception DOMException
  95. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  96. * negative or greater than the number of 16-bit units in
  97. * <code>data</code>.
  98. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  99. */
  100. public void insertData(int offset,
  101. String arg)
  102. throws DOMException;
  103. /**
  104. * Remove a range of 16-bit units from the node. Upon success,
  105. * <code>data</code> and <code>length</code> reflect the change.
  106. * @param offset The offset from which to start removing.
  107. * @param count The number of 16-bit units to delete. If the sum of
  108. * <code>offset</code> and <code>count</code> exceeds
  109. * <code>length</code> then all 16-bit units from <code>offset</code>
  110. * to the end of the data are deleted.
  111. * @exception DOMException
  112. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  113. * negative or greater than the number of 16-bit units in
  114. * <code>data</code>, or if the specified <code>count</code> is
  115. * negative.
  116. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  117. */
  118. public void deleteData(int offset,
  119. int count)
  120. throws DOMException;
  121. /**
  122. * Replace the characters starting at the specified 16-bit unit offset
  123. * with the specified string.
  124. * @param offset The offset from which to start replacing.
  125. * @param count The number of 16-bit units to replace. If the sum of
  126. * <code>offset</code> and <code>count</code> exceeds
  127. * <code>length</code>, then all 16-bit units to the end of the data
  128. * are replaced; (i.e., the effect is the same as a <code>remove</code>
  129. * method call with the same range, followed by an <code>append</code>
  130. * method invocation).
  131. * @param arg The <code>DOMString</code> with which the range must be
  132. * replaced.
  133. * @exception DOMException
  134. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  135. * negative or greater than the number of 16-bit units in
  136. * <code>data</code>, or if the specified <code>count</code> is
  137. * negative.
  138. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  139. */
  140. public void replaceData(int offset,
  141. int count,
  142. String arg)
  143. throws DOMException;
  144. }