KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > TextImpl


1 package org.enhydra.xml;
2
3 import org.w3c.dom.DOMException JavaDoc;
4 import org.w3c.dom.Node JavaDoc;
5 import org.w3c.dom.Text JavaDoc;
6
7 /**
8  * @author Tweety
9  *
10  * A class representing a node in a meta-data tree, which implements
11  * the <a HREF="../../../../api/org/w3c/dom/Element.html">
12  *
13  * <p> Namespaces are ignored in this implementation. The terms "tag
14  * name" and "node name" are always considered to be synonymous.
15  *
16  * @version 1.0
17  */

18 public class TextImpl extends CharacterDataImpl implements Text JavaDoc {
19
20
21     /**
22      * Constructs a <code>TextImpl</code> from the given node.
23      *
24      * @param node, as a <code>TextImpl</code>.
25      */

26     public TextImpl(TextImpl node) {
27         super((NodeImpl)node);
28     }
29     
30     
31     /**
32      * Constructs a <code>TextImpl</code> from the given node value.
33      *
34      * @param value, as a <code>String</code>.
35      */

36     public TextImpl(String JavaDoc value) {
37         nodeValue = value;
38         type = Node.TEXT_NODE;
39     }
40
41
42     /**
43      * Constructs a <code>TextImpl</code> from a given node,
44      * as a <code>Node</code>
45      *
46      * @param node, as <code>Node</code>.
47      */

48     public TextImpl(Node JavaDoc node) {
49         super(node);
50     }
51
52     
53     /**
54      * Returns the node type.
55      *
56      * @return the <code>TEXT_NODE</code> node type.
57      */

58     public short getNodeType() {
59         return Node.TEXT_NODE;
60     }
61
62     /**
63      * Returns the name ("#text") associated with this node.
64      *
65      * @return the name, as a <code>String</code>.
66      */

67     public String JavaDoc getNodeName() {
68         return "#text";
69     }
70     
71     
72     /**
73      * Returns the trimed node value associated with this node.
74      *
75      * @return the node value, as a <code>String</code>.
76      */

77     public String JavaDoc getNodeValue() throws DOMException JavaDoc {
78         return nodeValue.trim();
79     }
80     
81     
82     /**
83      * Method beginToString for this class writes the value
84      * of this node (text).
85      *
86      * @param sb string buffer to add resulting string.
87      * @param indent used in formating the output.
88      */

89     protected void beginToString(StringBuffer JavaDoc sb, Indent indent) {
90         sb.append(this.nodeValue.trim());
91     }
92     
93     /**
94      * Method endToString does nothing.
95      */

96     protected void endToString(StringBuffer JavaDoc sb, Indent indent) {
97     }
98     
99     
100     /**
101      * @see org.w3c.dom.Text#splitText(int)
102      *
103      * Break a text node into two sibling nodes. (Note that if the
104      * current node has no parent, they won't wind up as "siblings" --
105      * they'll both be orphans.)
106      *
107      * @param offset The offset at which to split. If offset is at the
108      * end of the available data, the second node will be empty.
109      *
110      * @returns A reference to the new node (containing data after the
111      * offset point). The original node will contain data up to that
112      * point.
113      *
114      * @throws DOMException(INDEX_SIZE_ERR) if offset is <0 or >length.
115      *
116      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
117      */

118     public Text JavaDoc splitText(int offset)
119         throws DOMException JavaDoc {
120
121         if (offset < 0 || offset > nodeValue.length() ) {
122             throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "Index out of bounds");
123         }
124             
125         // split text into two separate nodes
126
TextImpl newText = new TextImpl(nodeValue.substring(offset));
127         nodeValue = nodeValue.substring(0, offset);
128
129         // insert new text node
130
Node JavaDoc parentNode = getParentNode();
131         if (parentNode != null) {
132             parentNode.insertBefore(newText, nextSibling);
133         }
134
135         return newText;
136
137     }
138
139
140     /* (non-Javadoc)
141      * @see org.w3c.dom.Text#isElementContentWhitespace()
142      */

143     public boolean isElementContentWhitespace() {
144         // TODO Auto-generated method stub
145
return false;
146     }
147
148
149     /* (non-Javadoc)
150      * @see org.w3c.dom.Text#getWholeText()
151      */

152     public String JavaDoc getWholeText() {
153         // TODO Auto-generated method stub
154
return null;
155     }
156
157
158     /* (non-Javadoc)
159      * @see org.w3c.dom.Text#replaceWholeText(java.lang.String)
160      */

161     public Text JavaDoc replaceWholeText(String JavaDoc arg0) throws DOMException JavaDoc {
162         // TODO Auto-generated method stub
163
return null;
164     }
165
166 }
167
Popular Tags