KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tax > dom > TextImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.tax.dom;
21
22 import org.w3c.dom.*;
23 import org.netbeans.tax.*;
24
25 /**
26  *
27  * @author Petr Kuzel
28  */

29 class TextImpl extends NodeImpl implements Text {
30
31     private final TreeText peer;
32
33     /** Creates a new instance of AttrImpl */
34     public TextImpl(TreeText peer) {
35         this.peer = peer;
36     }
37
38     /** Append the string to the end of the character data of the node. Upon
39      * success, <code>data</code> provides access to the concatenation of
40      * <code>data</code> and the <code>DOMString</code> specified.
41      * @param arg The <code>DOMString</code> to append.
42      * @exception DOMException
43      * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
44      *
45      */

46     public void appendData(String JavaDoc arg) throws DOMException {
47         throw new ROException();
48     }
49     
50     /** Remove a range of 16-bit units from the node. Upon success,
51      * <code>data</code> and <code>length</code> reflect the change.
52      * @param offset The offset from which to start removing.
53      * @param count The number of 16-bit units to delete. If the sum of
54      * <code>offset</code> and <code>count</code> exceeds
55      * <code>length</code> then all 16-bit units from <code>offset</code>
56      * to the end of the data are deleted.
57      * @exception DOMException
58      * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
59      * negative or greater than the number of 16-bit units in
60      * <code>data</code>, or if the specified <code>count</code> is
61      * negative.
62      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
63      *
64      */

65     public void deleteData(int offset, int count) throws DOMException {
66         throw new ROException();
67     }
68     
69     /** The character data of the node that implements this interface. The DOM
70      * implementation may not put arbitrary limits on the amount of data
71      * that may be stored in a <code>CharacterData</code> node. However,
72      * implementation limits may mean that the entirety of a node's data may
73      * not fit into a single <code>DOMString</code>. In such cases, the user
74      * may call <code>substringData</code> to retrieve the data in
75      * appropriately sized pieces.
76      * @exception DOMException
77      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
78      * @exception DOMException
79      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
80      * fit in a <code>DOMString</code> variable on the implementation
81      * platform.
82      *
83      */

84     public String JavaDoc getData() throws DOMException {
85         return peer.getData();
86     }
87     
88     /** The number of 16-bit units that are available through <code>data</code>
89      * and the <code>substringData</code> method below. This may have the
90      * value zero, i.e., <code>CharacterData</code> nodes may be empty.
91      *
92      */

93     public int getLength() {
94         return peer.getLength();
95     }
96     
97     /** The name of this node, depending on its type; see the table above.
98      *
99      */

100     public String JavaDoc getNodeName() {
101         return "#text";
102     }
103     
104     /** A code representing the type of the underlying object, as defined above.
105      *
106      */

107     public short getNodeType() {
108         return Node.TEXT_NODE;
109     }
110     
111     /** The value of this node, depending on its type; see the table above.
112      * When it is defined to be <code>null</code>, setting it has no effect.
113      * @exception DOMException
114      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
115      * @exception DOMException
116      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
117      * fit in a <code>DOMString</code> variable on the implementation
118      * platform.
119      *
120      */

121     public String JavaDoc getNodeValue() throws DOMException {
122         return getData();
123     }
124     
125     /** The parent of this node. All nodes, except <code>Attr</code>,
126      * <code>Document</code>, <code>DocumentFragment</code>,
127      * <code>Entity</code>, and <code>Notation</code> may have a parent.
128      * However, if a node has just been created and not yet added to the
129      * tree, or if it has been removed from the tree, this is
130      * <code>null</code>.
131      *
132      */

133     public Node getParentNode() {
134         
135         TreeParentNode parent = peer.getParentNode();
136         if (parent instanceof TreeElement) {
137             return Wrapper.wrap((TreeElement) parent);
138         } else if (parent instanceof TreeDocumentRoot) {
139             return Wrapper.wrap((TreeDocumentRoot) parent);
140         }
141         return null;
142     }
143     
144     /** Insert a string at the specified 16-bit unit offset.
145      * @param offset The character offset at which to insert.
146      * @param arg The <code>DOMString</code> to insert.
147      * @exception DOMException
148      * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
149      * negative or greater than the number of 16-bit units in
150      * <code>data</code>.
151      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
152      *
153      */

154     public void insertData(int offset, String JavaDoc arg) throws DOMException {
155         throw new ROException();
156     }
157     
158     /** Replace the characters starting at the specified 16-bit unit offset
159      * with the specified string.
160      * @param offset The offset from which to start replacing.
161      * @param count The number of 16-bit units to replace. If the sum of
162      * <code>offset</code> and <code>count</code> exceeds
163      * <code>length</code>, then all 16-bit units to the end of the data
164      * are replaced; (i.e., the effect is the same as a <code>remove</code>
165      * method call with the same range, followed by an <code>append</code>
166      * method invocation).
167      * @param arg The <code>DOMString</code> with which the range must be
168      * replaced.
169      * @exception DOMException
170      * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
171      * negative or greater than the number of 16-bit units in
172      * <code>data</code>, or if the specified <code>count</code> is
173      * negative.
174      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
175      *
176      */

177     public void replaceData(int offset, int count, String JavaDoc arg) throws DOMException {
178         throw new ROException();
179     }
180     
181     /** The character data of the node that implements this interface. The DOM
182      * implementation may not put arbitrary limits on the amount of data
183      * that may be stored in a <code>CharacterData</code> node. However,
184      * implementation limits may mean that the entirety of a node's data may
185      * not fit into a single <code>DOMString</code>. In such cases, the user
186      * may call <code>substringData</code> to retrieve the data in
187      * appropriately sized pieces.
188      * @exception DOMException
189      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
190      * @exception DOMException
191      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
192      * fit in a <code>DOMString</code> variable on the implementation
193      * platform.
194      *
195      */

196     public void setData(String JavaDoc data) throws DOMException {
197         throw new ROException();
198     }
199     
200     /** Breaks this node into two nodes at the specified <code>offset</code>,
201      * keeping both in the tree as siblings. After being split, this node
202      * will contain all the content up to the <code>offset</code> point. A
203      * new node of the same type, which contains all the content at and
204      * after the <code>offset</code> point, is returned. If the original
205      * node had a parent node, the new node is inserted as the next sibling
206      * of the original node. When the <code>offset</code> is equal to the
207      * length of this node, the new node has no data.
208      * @param offset The 16-bit unit offset at which to split, starting from
209      * <code>0</code>.
210      * @return The new node, of the same type as this node.
211      * @exception DOMException
212      * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
213      * than the number of 16-bit units in <code>data</code>.
214      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
215      *
216      */

217     public Text splitText(int offset) throws DOMException {
218         throw new ROException();
219     }
220     
221     /** Extracts a range of data from the node.
222      * @param offset Start offset of substring to extract.
223      * @param count The number of 16-bit units to extract.
224      * @return The specified substring. If the sum of <code>offset</code> and
225      * <code>count</code> exceeds the <code>length</code>, then all 16-bit
226      * units to the end of the data are returned.
227      * @exception DOMException
228      * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
229      * negative or greater than the number of 16-bit units in
230      * <code>data</code>, or if the specified <code>count</code> is
231      * negative.
232      * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
233      * not fit into a <code>DOMString</code>.
234      *
235      */

236     public String JavaDoc substringData(int offset, int count) throws DOMException {
237         try {
238             return peer.substringData(offset, count);
239         } catch (InvalidArgumentException ex) {
240             throw new UOException();
241         }
242     }
243     
244     /** The node immediately preceding this node. If there is no such node,
245      * this returns <code>null</code>.
246      *
247      */

248     public Node getPreviousSibling() {
249         return Children.getPreviousSibling(peer);
250     }
251  
252     /** The node immediately following this node. If there is no such node,
253      * this returns <code>null</code>.
254      *
255      */

256     public Node getNextSibling() {
257         return Children.getNextSibling(peer);
258     }
259     
260 }
261
Popular Tags