001: /*
002: Copyright (C) 2003 Together
003:
004: This library is free software; you can redistribute it and/or
005: modify it under the terms of the GNU Lesser General Public
006: License as published by the Free Software Foundation; either
007: version 2.1 of the License, or (at your option) any later version.
008:
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013:
014: You should have received a copy of the GNU Lesser General Public
015: License along with this library; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.enhydra.xml;
020:
021: import org.w3c.dom.DOMException;
022: import org.w3c.dom.Document;
023: import org.w3c.dom.NamedNodeMap;
024: import org.w3c.dom.Node;
025: import org.w3c.dom.NodeList;
026: import org.w3c.dom.Text;
027: import org.w3c.dom.UserDataHandler;
028:
029: /**
030: * @author Tweety
031: *
032: * A class representing a node in a meta-data tree, which implements
033: * the <a href="../../../../api/org/w3c/dom/Element.html">
034: *
035: * <p> Namespaces are ignored in this implementation. The terms "tag
036: * name" and "node name" are always considered to be synonymous.
037: *
038: * @version 1.0
039: */
040: public class TextImpl extends CharacterDataImpl implements Text {
041:
042: /**
043: * Constructs a <code>TextImpl</code> from the given node.
044: *
045: * @param node , as a <code>TextImpl</code>.
046: */
047: public TextImpl(TextImpl node) {
048: super ((NodeImpl) node);
049: }
050:
051: /**
052: * Constructs a <code>TextImpl</code> from the given node value.
053: *
054: * @param value , as a <code>String</code>.
055: */
056: public TextImpl(String value) {
057: nodeValue = value;
058: type = Node.TEXT_NODE;
059: }
060:
061: /**
062: * Constructs a <code>TextImpl</code> from a given node,
063: * as a <code>Node</code>
064: *
065: * @param node , as <code>Node</code>.
066: */
067: public TextImpl(Node node) {
068: super (node);
069: }
070:
071: /**
072: * Returns the node type.
073: *
074: * @return the <code>TEXT_NODE</code> node type.
075: */
076: public short getNodeType() {
077: return Node.TEXT_NODE;
078: }
079:
080: /**
081: * Returns the name ("#text") associated with this node.
082: *
083: * @return the name, as a <code>String</code>.
084: */
085: public String getNodeName() {
086: return "#text";
087: }
088:
089: /**
090: * Returns the trimed node value associated with this node.
091: *
092: * @return the node value, as a <code>String</code>.
093: * @throws DOMException
094: */
095: public String getNodeValue() throws DOMException {
096: // String nodeVal = nodeValue.trim().replaceAll("&","&");
097: String nodeVal = nodeValue.trim();
098: return nodeVal;
099: }
100:
101: /**
102: * Method beginToString for this class writes the value
103: * of this node (text).It should replace all special characters with their escape entitys.
104: *
105: * @param sb string buffer to add resulting string.
106: * @param indent used in formating the output.
107: */
108: protected void beginToString(StringBuffer sb, Indent indent) {
109: String nodeVal = nodeValue.trim();
110: nodeVal = Utils.replaceAll(nodeVal, "&", "&");
111: sb.append(nodeVal);
112: }
113:
114: /**
115: * Method endToString does nothing.
116: * @param sb is StringBuffer
117: * @param indent is indentation
118: */
119: protected void endToString(StringBuffer sb, Indent indent) {
120: }
121:
122: /**
123: * @see org.w3c.dom.Text#splitText(int)
124: *
125: * Break a text node into two sibling nodes. (Note that if the
126: * current node has no parent, they won't wind up as "siblings" --
127: * they'll both be orphans.)
128: *
129: * @param offset The offset at which to split. If offset is at the
130: * end of the available data, the second node will be empty.
131: *
132: * @return A reference to the new node (containing data after the
133: * offset point). The original node will contain data up to that
134: * point.
135: *
136: * @throws DOMException(INDEX_SIZE_ERR) if offset is <0 or >length.
137: *
138: * @throws DOMException (NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
139: */
140: public Text splitText(int offset) throws DOMException {
141:
142: if (offset < 0 || offset > nodeValue.length()) {
143: throw new DOMException(DOMException.INDEX_SIZE_ERR,
144: "Index out of bounds");
145: }
146:
147: // split text into two separate nodes
148: TextImpl newText = new TextImpl(nodeValue.substring(offset));
149: nodeValue = nodeValue.substring(0, offset);
150:
151: // insert new text node
152: Node parentNode = getParentNode();
153: if (parentNode != null) {
154: parentNode.insertBefore(newText, nextSibling);
155: }
156:
157: return newText;
158:
159: }
160:
161: /* METHODS FROM INTERFACE IN JDK1.5 */
162:
163: public String getWholeText() {
164: // TODO Auto-generated method stub
165: return null;
166: }
167:
168: public boolean isElementContentWhitespace() {
169: // TODO Auto-generated method stub
170: return false;
171: }
172:
173: public Text replaceWholeText(String content) throws DOMException {
174: // TODO Auto-generated method stub
175: return null;
176: }
177:
178: public void appendData(String arg) {
179: // TODO Auto-generated method stub
180: super .appendData(arg);
181: }
182:
183: public void deleteData(int offset, int count) throws DOMException {
184: // TODO Auto-generated method stub
185: super .deleteData(offset, count);
186: }
187:
188: public String getData() throws DOMException {
189: // TODO Auto-generated method stub
190: return super .getData();
191: }
192:
193: public String getNamespaceURI() {
194: // TODO Auto-generated method stub
195: return super .getNamespaceURI();
196: }
197:
198: public void insertData(int offset, String arg) throws DOMException {
199: // TODO Auto-generated method stub
200: super .insertData(offset, arg);
201: }
202:
203: public void replaceData(int offset, int count, String arg)
204: throws DOMException {
205: // TODO Auto-generated method stub
206: super .replaceData(offset, count, arg);
207: }
208:
209: public void setData(String data) throws DOMException {
210: // TODO Auto-generated method stub
211: super .setData(data);
212: }
213:
214: public String substringData(int offset, int count)
215: throws DOMException {
216: // TODO Auto-generated method stub
217: return super .substringData(offset, count);
218: }
219:
220: public Node appendChild(Node newChild) {
221: // TODO Auto-generated method stub
222: return super .appendChild(newChild);
223: }
224:
225: protected void checkNode(Node node) throws DOMException {
226: // TODO Auto-generated method stub
227: super .checkNode(node);
228: }
229:
230: public Node cloneNode(boolean deep) {
231: // TODO Auto-generated method stub
232: return super .cloneNode(deep);
233: }
234:
235: public short compareDocumentPosition(Node other)
236: throws DOMException {
237: // TODO Auto-generated method stub
238: return super .compareDocumentPosition(other);
239: }
240:
241: public NamedNodeMap getAttributes() {
242: // TODO Auto-generated method stub
243: return super .getAttributes();
244: }
245:
246: public String getBaseURI() {
247: // TODO Auto-generated method stub
248: return super .getBaseURI();
249: }
250:
251: public NodeList getChildNodes() {
252: // TODO Auto-generated method stub
253: return super .getChildNodes();
254: }
255:
256: public Object getFeature(String feature, String version) {
257: // TODO Auto-generated method stub
258: return super .getFeature(feature, version);
259: }
260:
261: public Node getFirstChild() {
262: // TODO Auto-generated method stub
263: return super .getFirstChild();
264: }
265:
266: public Node getLastChild() {
267: // TODO Auto-generated method stub
268: return super .getLastChild();
269: }
270:
271: public int getLength() {
272: // TODO Auto-generated method stub
273: return super .getLength();
274: }
275:
276: public String getLocalName() {
277: // TODO Auto-generated method stub
278: return super .getLocalName();
279: }
280:
281: public Node getNextSibling() {
282: // TODO Auto-generated method stub
283: return super .getNextSibling();
284: }
285:
286: public Document getOwnerDocument() {
287: // TODO Auto-generated method stub
288: return super .getOwnerDocument();
289: }
290:
291: public Node getParentNode() {
292: // TODO Auto-generated method stub
293: return super .getParentNode();
294: }
295:
296: public String getPrefix() {
297: // TODO Auto-generated method stub
298: return super .getPrefix();
299: }
300:
301: public Node getPreviousSibling() {
302: // TODO Auto-generated method stub
303: return super .getPreviousSibling();
304: }
305:
306: public String getTextContent() throws DOMException {
307: // TODO Auto-generated method stub
308: return super .getTextContent();
309: }
310:
311: public Object getUserData(String key) {
312: // TODO Auto-generated method stub
313: return super .getUserData(key);
314: }
315:
316: public boolean hasAttributes() {
317: // TODO Auto-generated method stub
318: return super .hasAttributes();
319: }
320:
321: public boolean hasChildNodes() {
322: // TODO Auto-generated method stub
323: return super .hasChildNodes();
324: }
325:
326: protected void initNodeImplChildren(Node node) {
327: // TODO Auto-generated method stub
328: super .initNodeImplChildren(node);
329: }
330:
331: public Node insertBefore(Node newChild, Node refChild) {
332: // TODO Auto-generated method stub
333: return super .insertBefore(newChild, refChild);
334: }
335:
336: public boolean isDefaultNamespace(String namespaceURI) {
337: // TODO Auto-generated method stub
338: return super .isDefaultNamespace(namespaceURI);
339: }
340:
341: public boolean isEqualNode(Node arg) {
342: // TODO Auto-generated method stub
343: return super .isEqualNode(arg);
344: }
345:
346: public boolean isSameNode(Node other) {
347: // TODO Auto-generated method stub
348: return super .isSameNode(other);
349: }
350:
351: public boolean isSupported(String feature, String version) {
352: // TODO Auto-generated method stub
353: return super .isSupported(feature, version);
354: }
355:
356: public Node item(int index) {
357: // TODO Auto-generated method stub
358: return super .item(index);
359: }
360:
361: public String lookupNamespaceURI(String prefix) {
362: // TODO Auto-generated method stub
363: return super .lookupNamespaceURI(prefix);
364: }
365:
366: public String lookupPrefix(String namespaceURI) {
367: // TODO Auto-generated method stub
368: return super .lookupPrefix(namespaceURI);
369: }
370:
371: protected Node newCommentInstance(Node node) {
372: // TODO Auto-generated method stub
373: return super .newCommentInstance(node);
374: }
375:
376: protected Node newDefaultInstance(Node node) {
377: // TODO Auto-generated method stub
378: return super .newDefaultInstance(node);
379: }
380:
381: protected Node newElementInstance(Node node) {
382: // TODO Auto-generated method stub
383: return super .newElementInstance(node);
384: }
385:
386: protected Node newTextInstance(Node node) {
387: // TODO Auto-generated method stub
388: return super .newTextInstance(node);
389: }
390:
391: public void normalize() {
392: // TODO Auto-generated method stub
393: super .normalize();
394: }
395:
396: public Node removeChild(Node oldChild) {
397: // TODO Auto-generated method stub
398: return super .removeChild(oldChild);
399: }
400:
401: public Node replaceChild(Node newChild, Node oldChild) {
402: // TODO Auto-generated method stub
403: return super .replaceChild(newChild, oldChild);
404: }
405:
406: public void setNodeValue(String nodeValue) {
407: // TODO Auto-generated method stub
408: super .setNodeValue(nodeValue);
409: }
410:
411: public void setPrefix(String prefix) {
412: // TODO Auto-generated method stub
413: super .setPrefix(prefix);
414: }
415:
416: public void setTextContent(String textContent) throws DOMException {
417: // TODO Auto-generated method stub
418: super .setTextContent(textContent);
419: }
420:
421: public Object setUserData(String key, Object data,
422: UserDataHandler handler) {
423: // TODO Auto-generated method stub
424: return super .setUserData(key, data, handler);
425: }
426:
427: public String toString() {
428: // TODO Auto-generated method stub
429: return super .toString();
430: }
431:
432: public String toString(String tab) {
433: // TODO Auto-generated method stub
434: return super.toString(tab);
435: }
436: }
|