1 /*
2 Copyright (C) 2003 Together
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 package org.enhydra.xml;
20
21 import org.w3c.dom.DOMException;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.NamedNodeMap;
24 import org.w3c.dom.Node;
25 import org.w3c.dom.NodeList;
26 import org.w3c.dom.Text;
27 import org.w3c.dom.UserDataHandler;
28
29 /***
30 * @author Tweety
31 *
32 * A class representing a node in a meta-data tree, which implements
33 * the <a href="../../../../api/org/w3c/dom/Element.html">
34 *
35 * <p> Namespaces are ignored in this implementation. The terms "tag
36 * name" and "node name" are always considered to be synonymous.
37 *
38 * @version 1.0
39 */
40 public class TextImpl extends CharacterDataImpl implements Text {
41
42
43 /***
44 * Constructs a <code>TextImpl</code> from the given node.
45 *
46 * @param node , as a <code>TextImpl</code>.
47 */
48 public TextImpl(TextImpl node) {
49 super((NodeImpl)node);
50 }
51
52
53 /***
54 * Constructs a <code>TextImpl</code> from the given node value.
55 *
56 * @param value , as a <code>String</code>.
57 */
58 public TextImpl(String value) {
59 nodeValue = value;
60 type = Node.TEXT_NODE;
61 }
62
63
64 /***
65 * Constructs a <code>TextImpl</code> from a given node,
66 * as a <code>Node</code>
67 *
68 * @param node , as <code>Node</code>.
69 */
70 public TextImpl(Node node) {
71 super(node);
72 }
73
74
75 /***
76 * Returns the node type.
77 *
78 * @return the <code>TEXT_NODE</code> node type.
79 */
80 public short getNodeType() {
81 return Node.TEXT_NODE;
82 }
83
84 /***
85 * Returns the name ("#text") associated with this node.
86 *
87 * @return the name, as a <code>String</code>.
88 */
89 public String getNodeName() {
90 return "#text";
91 }
92
93
94 /***
95 * Returns the trimed node value associated with this node.
96 *
97 * @return the node value, as a <code>String</code>.
98 * @throws DOMException
99 */
100 public String getNodeValue() throws DOMException {
101 // String nodeVal = nodeValue.trim().replaceAll("&","&");
102 String nodeVal = nodeValue.trim();
103 return nodeVal;
104 }
105
106
107 /***
108 * Method beginToString for this class writes the value
109 * of this node (text).It should replace all special characters with their escape entitys.
110 *
111 * @param sb string buffer to add resulting string.
112 * @param indent used in formating the output.
113 */
114 protected void beginToString(StringBuffer sb, Indent indent) {
115 String nodeVal = nodeValue.trim();
116 nodeVal = Utils.replaceAll(nodeVal, "&", "&");
117 sb.append(nodeVal);
118 }
119
120 /***
121 * Method endToString does nothing.
122 * @param sb is StringBuffer
123 * @param indent is indentation
124 */
125 protected void endToString(StringBuffer sb, Indent indent) {
126 }
127
128
129 /***
130 * @see org.w3c.dom.Text#splitText(int)
131 *
132 * Break a text node into two sibling nodes. (Note that if the
133 * current node has no parent, they won't wind up as "siblings" --
134 * they'll both be orphans.)
135 *
136 * @param offset The offset at which to split. If offset is at the
137 * end of the available data, the second node will be empty.
138 *
139 * @return A reference to the new node (containing data after the
140 * offset point). The original node will contain data up to that
141 * point.
142 *
143 * @throws DOMException(INDEX_SIZE_ERR) if offset is <0 or >length.
144 *
145 * @throws DOMException (NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
146 */
147 public Text splitText(int offset)
148 throws DOMException {
149
150 if (offset < 0 || offset > nodeValue.length() ) {
151 throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds");
152 }
153
154 // split text into two separate nodes
155 TextImpl newText = new TextImpl(nodeValue.substring(offset));
156 nodeValue = nodeValue.substring(0, offset);
157
158 // insert new text node
159 Node parentNode = getParentNode();
160 if (parentNode != null) {
161 parentNode.insertBefore(newText, nextSibling);
162 }
163
164 return newText;
165
166 }
167
168 /* METHODS FROM INTERFACE IN JDK1.5 */
169
170
171
172 public String getWholeText() {
173 // TODO Auto-generated method stub
174 return null;
175 }
176 public boolean isElementContentWhitespace() {
177 // TODO Auto-generated method stub
178 return false;
179 }
180 public Text replaceWholeText(String content) throws DOMException {
181 // TODO Auto-generated method stub
182 return null;
183 }
184 public void appendData(String arg) {
185 // TODO Auto-generated method stub
186 super.appendData(arg);
187 }
188 public void deleteData(int offset, int count) throws DOMException {
189 // TODO Auto-generated method stub
190 super.deleteData(offset, count);
191 }
192 public String getData() throws DOMException {
193 // TODO Auto-generated method stub
194 return super.getData();
195 }
196 public String getNamespaceURI() {
197 // TODO Auto-generated method stub
198 return super.getNamespaceURI();
199 }
200 public void insertData(int offset, String arg) throws DOMException {
201 // TODO Auto-generated method stub
202 super.insertData(offset, arg);
203 }
204 public void replaceData(int offset, int count, String arg)
205 throws DOMException {
206 // TODO Auto-generated method stub
207 super.replaceData(offset, count, arg);
208 }
209 public void setData(String data) throws DOMException {
210 // TODO Auto-generated method stub
211 super.setData(data);
212 }
213 public String substringData(int offset, int count) throws DOMException {
214 // TODO Auto-generated method stub
215 return super.substringData(offset, count);
216 }
217 public Node appendChild(Node newChild) {
218 // TODO Auto-generated method stub
219 return super.appendChild(newChild);
220 }
221 protected void checkNode(Node node) throws DOMException {
222 // TODO Auto-generated method stub
223 super.checkNode(node);
224 }
225 public Node cloneNode(boolean deep) {
226 // TODO Auto-generated method stub
227 return super.cloneNode(deep);
228 }
229 public short compareDocumentPosition(Node other) throws DOMException {
230 // TODO Auto-generated method stub
231 return super.compareDocumentPosition(other);
232 }
233 public NamedNodeMap getAttributes() {
234 // TODO Auto-generated method stub
235 return super.getAttributes();
236 }
237 public String getBaseURI() {
238 // TODO Auto-generated method stub
239 return super.getBaseURI();
240 }
241 public NodeList getChildNodes() {
242 // TODO Auto-generated method stub
243 return super.getChildNodes();
244 }
245 public Object getFeature(String feature, String version) {
246 // TODO Auto-generated method stub
247 return super.getFeature(feature, version);
248 }
249 public Node getFirstChild() {
250 // TODO Auto-generated method stub
251 return super.getFirstChild();
252 }
253 public Node getLastChild() {
254 // TODO Auto-generated method stub
255 return super.getLastChild();
256 }
257 public int getLength() {
258 // TODO Auto-generated method stub
259 return super.getLength();
260 }
261 public String getLocalName() {
262 // TODO Auto-generated method stub
263 return super.getLocalName();
264 }
265 public Node getNextSibling() {
266 // TODO Auto-generated method stub
267 return super.getNextSibling();
268 }
269 public Document getOwnerDocument() {
270 // TODO Auto-generated method stub
271 return super.getOwnerDocument();
272 }
273 public Node getParentNode() {
274 // TODO Auto-generated method stub
275 return super.getParentNode();
276 }
277 public String getPrefix() {
278 // TODO Auto-generated method stub
279 return super.getPrefix();
280 }
281 public Node getPreviousSibling() {
282 // TODO Auto-generated method stub
283 return super.getPreviousSibling();
284 }
285 public String getTextContent() throws DOMException {
286 // TODO Auto-generated method stub
287 return super.getTextContent();
288 }
289 public Object getUserData(String key) {
290 // TODO Auto-generated method stub
291 return super.getUserData(key);
292 }
293 public boolean hasAttributes() {
294 // TODO Auto-generated method stub
295 return super.hasAttributes();
296 }
297 public boolean hasChildNodes() {
298 // TODO Auto-generated method stub
299 return super.hasChildNodes();
300 }
301 protected void initNodeImplChildren(Node node) {
302 // TODO Auto-generated method stub
303 super.initNodeImplChildren(node);
304 }
305 public Node insertBefore(Node newChild, Node refChild) {
306 // TODO Auto-generated method stub
307 return super.insertBefore(newChild, refChild);
308 }
309 public boolean isDefaultNamespace(String namespaceURI) {
310 // TODO Auto-generated method stub
311 return super.isDefaultNamespace(namespaceURI);
312 }
313 public boolean isEqualNode(Node arg) {
314 // TODO Auto-generated method stub
315 return super.isEqualNode(arg);
316 }
317 public boolean isSameNode(Node other) {
318 // TODO Auto-generated method stub
319 return super.isSameNode(other);
320 }
321 public boolean isSupported(String feature, String version) {
322 // TODO Auto-generated method stub
323 return super.isSupported(feature, version);
324 }
325 public Node item(int index) {
326 // TODO Auto-generated method stub
327 return super.item(index);
328 }
329 public String lookupNamespaceURI(String prefix) {
330 // TODO Auto-generated method stub
331 return super.lookupNamespaceURI(prefix);
332 }
333 public String lookupPrefix(String namespaceURI) {
334 // TODO Auto-generated method stub
335 return super.lookupPrefix(namespaceURI);
336 }
337 protected Node newCommentInstance(Node node) {
338 // TODO Auto-generated method stub
339 return super.newCommentInstance(node);
340 }
341 protected Node newDefaultInstance(Node node) {
342 // TODO Auto-generated method stub
343 return super.newDefaultInstance(node);
344 }
345 protected Node newElementInstance(Node node) {
346 // TODO Auto-generated method stub
347 return super.newElementInstance(node);
348 }
349 protected Node newTextInstance(Node node) {
350 // TODO Auto-generated method stub
351 return super.newTextInstance(node);
352 }
353 public void normalize() {
354 // TODO Auto-generated method stub
355 super.normalize();
356 }
357 public Node removeChild(Node oldChild) {
358 // TODO Auto-generated method stub
359 return super.removeChild(oldChild);
360 }
361 public Node replaceChild(Node newChild, Node oldChild) {
362 // TODO Auto-generated method stub
363 return super.replaceChild(newChild, oldChild);
364 }
365 public void setNodeValue(String nodeValue) {
366 // TODO Auto-generated method stub
367 super.setNodeValue(nodeValue);
368 }
369 public void setPrefix(String prefix) {
370 // TODO Auto-generated method stub
371 super.setPrefix(prefix);
372 }
373 public void setTextContent(String textContent) throws DOMException {
374 // TODO Auto-generated method stub
375 super.setTextContent(textContent);
376 }
377 public Object setUserData(String key, Object data, UserDataHandler handler) {
378 // TODO Auto-generated method stub
379 return super.setUserData(key, data, handler);
380 }
381 public String toString() {
382 // TODO Auto-generated method stub
383 return super.toString();
384 }
385 public String toString(String tab) {
386 // TODO Auto-generated method stub
387 return super.toString(tab);
388 }
389 }
390
This page was automatically generated by Maven