001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.tax.dom;
043:
044: import org.w3c.dom.*;
045: import org.netbeans.tax.*;
046:
047: /**
048: *
049: * @author Petr Kuzel
050: */
051: class TextImpl extends NodeImpl implements Text {
052:
053: private final TreeText peer;
054:
055: /** Creates a new instance of AttrImpl */
056: public TextImpl(TreeText peer) {
057: this .peer = peer;
058: }
059:
060: /** Append the string to the end of the character data of the node. Upon
061: * success, <code>data</code> provides access to the concatenation of
062: * <code>data</code> and the <code>DOMString</code> specified.
063: * @param arg The <code>DOMString</code> to append.
064: * @exception DOMException
065: * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
066: *
067: */
068: public void appendData(String arg) throws DOMException {
069: throw new ROException();
070: }
071:
072: /** Remove a range of 16-bit units from the node. Upon success,
073: * <code>data</code> and <code>length</code> reflect the change.
074: * @param offset The offset from which to start removing.
075: * @param count The number of 16-bit units to delete. If the sum of
076: * <code>offset</code> and <code>count</code> exceeds
077: * <code>length</code> then all 16-bit units from <code>offset</code>
078: * to the end of the data are deleted.
079: * @exception DOMException
080: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
081: * negative or greater than the number of 16-bit units in
082: * <code>data</code>, or if the specified <code>count</code> is
083: * negative.
084: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
085: *
086: */
087: public void deleteData(int offset, int count) throws DOMException {
088: throw new ROException();
089: }
090:
091: /** The character data of the node that implements this interface. The DOM
092: * implementation may not put arbitrary limits on the amount of data
093: * that may be stored in a <code>CharacterData</code> node. However,
094: * implementation limits may mean that the entirety of a node's data may
095: * not fit into a single <code>DOMString</code>. In such cases, the user
096: * may call <code>substringData</code> to retrieve the data in
097: * appropriately sized pieces.
098: * @exception DOMException
099: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
100: * @exception DOMException
101: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
102: * fit in a <code>DOMString</code> variable on the implementation
103: * platform.
104: *
105: */
106: public String getData() throws DOMException {
107: return peer.getData();
108: }
109:
110: /** The number of 16-bit units that are available through <code>data</code>
111: * and the <code>substringData</code> method below. This may have the
112: * value zero, i.e., <code>CharacterData</code> nodes may be empty.
113: *
114: */
115: public int getLength() {
116: return peer.getLength();
117: }
118:
119: /** The name of this node, depending on its type; see the table above.
120: *
121: */
122: public String getNodeName() {
123: return "#text";
124: }
125:
126: /** A code representing the type of the underlying object, as defined above.
127: *
128: */
129: public short getNodeType() {
130: return Node.TEXT_NODE;
131: }
132:
133: /** The value of this node, depending on its type; see the table above.
134: * When it is defined to be <code>null</code>, setting it has no effect.
135: * @exception DOMException
136: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
137: * @exception DOMException
138: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
139: * fit in a <code>DOMString</code> variable on the implementation
140: * platform.
141: *
142: */
143: public String getNodeValue() throws DOMException {
144: return getData();
145: }
146:
147: /** The parent of this node. All nodes, except <code>Attr</code>,
148: * <code>Document</code>, <code>DocumentFragment</code>,
149: * <code>Entity</code>, and <code>Notation</code> may have a parent.
150: * However, if a node has just been created and not yet added to the
151: * tree, or if it has been removed from the tree, this is
152: * <code>null</code>.
153: *
154: */
155: public Node getParentNode() {
156:
157: TreeParentNode parent = peer.getParentNode();
158: if (parent instanceof TreeElement) {
159: return Wrapper.wrap((TreeElement) parent);
160: } else if (parent instanceof TreeDocumentRoot) {
161: return Wrapper.wrap((TreeDocumentRoot) parent);
162: }
163: return null;
164: }
165:
166: /** Insert a string at the specified 16-bit unit offset.
167: * @param offset The character offset at which to insert.
168: * @param arg The <code>DOMString</code> to insert.
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>.
173: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
174: *
175: */
176: public void insertData(int offset, String arg) throws DOMException {
177: throw new ROException();
178: }
179:
180: /** Replace the characters starting at the specified 16-bit unit offset
181: * with the specified string.
182: * @param offset The offset from which to start replacing.
183: * @param count The number of 16-bit units to replace. If the sum of
184: * <code>offset</code> and <code>count</code> exceeds
185: * <code>length</code>, then all 16-bit units to the end of the data
186: * are replaced; (i.e., the effect is the same as a <code>remove</code>
187: * method call with the same range, followed by an <code>append</code>
188: * method invocation).
189: * @param arg The <code>DOMString</code> with which the range must be
190: * replaced.
191: * @exception DOMException
192: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
193: * negative or greater than the number of 16-bit units in
194: * <code>data</code>, or if the specified <code>count</code> is
195: * negative.
196: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
197: *
198: */
199: public void replaceData(int offset, int count, String arg)
200: throws DOMException {
201: throw new ROException();
202: }
203:
204: /** The character data of the node that implements this interface. The DOM
205: * implementation may not put arbitrary limits on the amount of data
206: * that may be stored in a <code>CharacterData</code> node. However,
207: * implementation limits may mean that the entirety of a node's data may
208: * not fit into a single <code>DOMString</code>. In such cases, the user
209: * may call <code>substringData</code> to retrieve the data in
210: * appropriately sized pieces.
211: * @exception DOMException
212: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
213: * @exception DOMException
214: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
215: * fit in a <code>DOMString</code> variable on the implementation
216: * platform.
217: *
218: */
219: public void setData(String data) throws DOMException {
220: throw new ROException();
221: }
222:
223: /** Breaks this node into two nodes at the specified <code>offset</code>,
224: * keeping both in the tree as siblings. After being split, this node
225: * will contain all the content up to the <code>offset</code> point. A
226: * new node of the same type, which contains all the content at and
227: * after the <code>offset</code> point, is returned. If the original
228: * node had a parent node, the new node is inserted as the next sibling
229: * of the original node. When the <code>offset</code> is equal to the
230: * length of this node, the new node has no data.
231: * @param offset The 16-bit unit offset at which to split, starting from
232: * <code>0</code>.
233: * @return The new node, of the same type as this node.
234: * @exception DOMException
235: * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
236: * than the number of 16-bit units in <code>data</code>.
237: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
238: *
239: */
240: public Text splitText(int offset) throws DOMException {
241: throw new ROException();
242: }
243:
244: /** Extracts a range of data from the node.
245: * @param offset Start offset of substring to extract.
246: * @param count The number of 16-bit units to extract.
247: * @return The specified substring. If the sum of <code>offset</code> and
248: * <code>count</code> exceeds the <code>length</code>, then all 16-bit
249: * units to the end of the data are returned.
250: * @exception DOMException
251: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
252: * negative or greater than the number of 16-bit units in
253: * <code>data</code>, or if the specified <code>count</code> is
254: * negative.
255: * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
256: * not fit into a <code>DOMString</code>.
257: *
258: */
259: public String substringData(int offset, int count)
260: throws DOMException {
261: try {
262: return peer.substringData(offset, count);
263: } catch (InvalidArgumentException ex) {
264: throw new UOException();
265: }
266: }
267:
268: /** The node immediately preceding this node. If there is no such node,
269: * this returns <code>null</code>.
270: *
271: */
272: public Node getPreviousSibling() {
273: return Children.getPreviousSibling(peer);
274: }
275:
276: /** The node immediately following this node. If there is no such node,
277: * this returns <code>null</code>.
278: *
279: */
280: public Node getNextSibling() {
281: return Children.getNextSibling(peer);
282: }
283:
284: }
|