1. /*
  2. * Copyright (c) 2000 World Wide Web Consortium,
  3. * (Massachusetts Institute of Technology, Institut National de
  4. * Recherche en Informatique et en Automatique, Keio University). All
  5. * Rights Reserved. This program is distributed under the W3C's Software
  6. * Intellectual Property License. This program is distributed in the
  7. * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  8. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  9. * PURPOSE.
  10. * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  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/2000/REC-DOM-Level-2-Core-20001113'>Document Object Model (DOM) Level 2 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. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  38. * @exception DOMException
  39. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  40. * fit in a <code>DOMString</code> variable on the implementation
  41. * platform.
  42. */
  43. public String getData()
  44. throws DOMException;
  45. /**
  46. * The character data of the node that implements this interface. The DOM
  47. * implementation may not put arbitrary limits on the amount of data
  48. * that may be stored in a <code>CharacterData</code> node. However,
  49. * implementation limits may mean that the entirety of a node's data may
  50. * not fit into a single <code>DOMString</code>. In such cases, the user
  51. * may call <code>substringData</code> to retrieve the data in
  52. * appropriately sized pieces.
  53. * @exception DOMException
  54. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  55. * @exception DOMException
  56. * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
  57. * fit in a <code>DOMString</code> variable on the implementation
  58. * platform.
  59. */
  60. public void setData(String data)
  61. throws DOMException;
  62. /**
  63. * The number of 16-bit units that are available through <code>data</code>
  64. * and the <code>substringData</code> method below. This may have the
  65. * value zero, i.e., <code>CharacterData</code> nodes may be empty.
  66. */
  67. public int getLength();
  68. /**
  69. * Extracts a range of data from the node.
  70. * @param offset Start offset of substring to extract.
  71. * @param count The number of 16-bit units to extract.
  72. * @return The specified substring. If the sum of <code>offset</code> and
  73. * <code>count</code> exceeds the <code>length</code>, then all 16-bit
  74. * units to the end of the data are returned.
  75. * @exception DOMException
  76. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  77. * negative or greater than the number of 16-bit units in
  78. * <code>data</code>, or if the specified <code>count</code> is
  79. * negative.
  80. * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
  81. * not fit into a <code>DOMString</code>.
  82. */
  83. public String substringData(int offset,
  84. int count)
  85. throws DOMException;
  86. /**
  87. * Append the string to the end of the character data of the node. Upon
  88. * success, <code>data</code> provides access to the concatenation of
  89. * <code>data</code> and the <code>DOMString</code> specified.
  90. * @param arg The <code>DOMString</code> to append.
  91. * @exception DOMException
  92. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  93. */
  94. public void appendData(String arg)
  95. throws DOMException;
  96. /**
  97. * Insert a string at the specified 16-bit unit offset.
  98. * @param offset The character offset at which to insert.
  99. * @param arg The <code>DOMString</code> to insert.
  100. * @exception DOMException
  101. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  102. * negative or greater than the number of 16-bit units in
  103. * <code>data</code>.
  104. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  105. */
  106. public void insertData(int offset,
  107. String arg)
  108. throws DOMException;
  109. /**
  110. * Remove a range of 16-bit units from the node. Upon success,
  111. * <code>data</code> and <code>length</code> reflect the change.
  112. * @param offset The offset from which to start removing.
  113. * @param count The number of 16-bit units to delete. If the sum of
  114. * <code>offset</code> and <code>count</code> exceeds
  115. * <code>length</code> then all 16-bit units from <code>offset</code>
  116. * to the end of the data are deleted.
  117. * @exception DOMException
  118. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  119. * negative or greater than the number of 16-bit units in
  120. * <code>data</code>, or if the specified <code>count</code> is
  121. * negative.
  122. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  123. */
  124. public void deleteData(int offset,
  125. int count)
  126. throws DOMException;
  127. /**
  128. * Replace the characters starting at the specified 16-bit unit offset
  129. * with the specified string.
  130. * @param offset The offset from which to start replacing.
  131. * @param count The number of 16-bit units to replace. If the sum of
  132. * <code>offset</code> and <code>count</code> exceeds
  133. * <code>length</code>, then all 16-bit units to the end of the data
  134. * are replaced; (i.e., the effect is the same as a <code>remove</code>
  135. * method call with the same range, followed by an <code>append</code>
  136. * method invocation).
  137. * @param arg The <code>DOMString</code> with which the range must be
  138. * replaced.
  139. * @exception DOMException
  140. * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
  141. * negative or greater than the number of 16-bit units in
  142. * <code>data</code>, or if the specified <code>count</code> is
  143. * negative.
  144. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  145. */
  146. public void replaceData(int offset,
  147. int count,
  148. String arg)
  149. throws DOMException;
  150. }