001/*
002 * Copyright (c) 2004 World Wide Web Consortium,
003 *
004 * (Massachusetts Institute of Technology, European Research Consortium for
005 * Informatics and Mathematics, Keio University). All Rights Reserved. This
006 * work is distributed under the W3C(r) Software License [1] in the hope that
007 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
008 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
009 *
010 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
011 */
012
013package org.w3c.dom;
014
015/**
016 * The <code>CharacterData</code> interface extends Node with a set of 
017 * attributes and methods for accessing character data in the DOM. For 
018 * clarity this set is defined here rather than on each object that uses 
019 * these attributes and methods. No DOM objects correspond directly to 
020 * <code>CharacterData</code>, though <code>Text</code> and others do 
021 * inherit the interface from it. All <code>offsets</code> in this interface 
022 * start from <code>0</code>.
023 * <p>As explained in the <code>DOMString</code> interface, text strings in 
024 * the DOM are represented in UTF-16, i.e. as a sequence of 16-bit units. In 
025 * the following, the term 16-bit units is used whenever necessary to 
026 * indicate that indexing on CharacterData is done in 16-bit units.
027 * <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>.
028 */
029public interface CharacterData extends Node {
030    /**
031     * The character data of the node that implements this interface. The DOM 
032     * implementation may not put arbitrary limits on the amount of data 
033     * that may be stored in a <code>CharacterData</code> node. However, 
034     * implementation limits may mean that the entirety of a node's data may 
035     * not fit into a single <code>DOMString</code>. In such cases, the user 
036     * may call <code>substringData</code> to retrieve the data in 
037     * appropriately sized pieces.
038     * @exception DOMException
039     *   DOMSTRING_SIZE_ERR: Raised when it would return more characters than 
040     *   fit in a <code>DOMString</code> variable on the implementation 
041     *   platform.
042     */
043    public String getData()
044                            throws DOMException;
045    /**
046     * The character data of the node that implements this interface. The DOM 
047     * implementation may not put arbitrary limits on the amount of data 
048     * that may be stored in a <code>CharacterData</code> node. However, 
049     * implementation limits may mean that the entirety of a node's data may 
050     * not fit into a single <code>DOMString</code>. In such cases, the user 
051     * may call <code>substringData</code> to retrieve the data in 
052     * appropriately sized pieces.
053     * @exception DOMException
054     *   NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
055     */
056    public void setData(String data)
057                            throws DOMException;
058
059    /**
060     * The number of 16-bit units that are available through <code>data</code> 
061     * and the <code>substringData</code> method below. This may have the 
062     * value zero, i.e., <code>CharacterData</code> nodes may be empty.
063     */
064    public int getLength();
065
066    /**
067     * Extracts a range of data from the node.
068     * @param offset Start offset of substring to extract.
069     * @param count The number of 16-bit units to extract.
070     * @return The specified substring. If the sum of <code>offset</code> and 
071     *   <code>count</code> exceeds the <code>length</code>, then all 16-bit 
072     *   units to the end of the data are returned.
073     * @exception DOMException
074     *   INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is 
075     *   negative or greater than the number of 16-bit units in 
076     *   <code>data</code>, or if the specified <code>count</code> is 
077     *   negative.
078     *   <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does 
079     *   not fit into a <code>DOMString</code>.
080     */
081    public String substringData(int offset, 
082                                int count)
083                                throws DOMException;
084
085    /**
086     * Append the string to the end of the character data of the node. Upon 
087     * success, <code>data</code> provides access to the concatenation of 
088     * <code>data</code> and the <code>DOMString</code> specified.
089     * @param arg The <code>DOMString</code> to append.
090     * @exception DOMException
091     *   NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
092     */
093    public void appendData(String arg)
094                           throws DOMException;
095
096    /**
097     * Insert a string at the specified 16-bit unit offset.
098     * @param offset The character offset at which to insert.
099     * @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    /**
111     * Remove a range of 16-bit units from the node. Upon success, 
112     * <code>data</code> and <code>length</code> reflect the change.
113     * @param offset The offset from which to start removing.
114     * @param count The number of 16-bit units to delete. If the sum of 
115     *   <code>offset</code> and <code>count</code> exceeds 
116     *   <code>length</code> then all 16-bit units from <code>offset</code> 
117     *   to the end of the data are deleted.
118     * @exception DOMException
119     *   INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is 
120     *   negative or greater than the number of 16-bit units in 
121     *   <code>data</code>, or if the specified <code>count</code> is 
122     *   negative.
123     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
124     */
125    public void deleteData(int offset, 
126                           int count)
127                           throws DOMException;
128
129    /**
130     * Replace the characters starting at the specified 16-bit unit offset 
131     * with the specified string.
132     * @param offset The offset from which to start replacing.
133     * @param count The number of 16-bit units to replace. If the sum of 
134     *   <code>offset</code> and <code>count</code> exceeds 
135     *   <code>length</code>, then all 16-bit units to the end of the data 
136     *   are replaced; (i.e., the effect is the same as a <code>remove</code>
137     *    method call with the same range, followed by an <code>append</code>
138     *    method invocation).
139     * @param arg The <code>DOMString</code> with which the range must be 
140     *   replaced.
141     * @exception DOMException
142     *   INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is 
143     *   negative or greater than the number of 16-bit units in 
144     *   <code>data</code>, or if the specified <code>count</code> is 
145     *   negative.
146     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
147     */
148    public void replaceData(int offset, 
149                            int count, 
150                            String arg)
151                            throws DOMException;
152
153}