1:
37:
38: package ;
39:
40: import ;
41: import ;
42:
43:
49: public class DomText
50: extends DomCharacterData
51: implements Text
52: {
53:
54:
55:
56:
57:
65: protected DomText(DomDocument owner, String value)
66: {
67: super(TEXT_NODE, owner, value);
68: }
69:
70: protected DomText(DomDocument owner, char[] buf, int off, int len)
71: {
72: super(TEXT_NODE, owner, buf, off, len);
73: }
74:
75:
76: DomText(short nodeType, DomDocument owner, String value)
77: {
78: super(nodeType, owner, value);
79: }
80:
81: DomText(short nodeType, DomDocument owner, char[] buf, int off, int len)
82: {
83: super(nodeType, owner, buf, off, len);
84: }
85:
86:
90:
91: public String getNodeName()
92: {
93: return "#text";
94: }
95:
96:
101: public Text splitText(int offset)
102: {
103: if (isReadonly())
104: {
105: throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);
106: }
107: try
108: {
109: String text = getNodeValue();
110: String before = text.substring(0, offset);
111: String after = text.substring(offset);
112: Text next;
113:
114: if (getNodeType() == TEXT_NODE)
115: {
116: next = owner.createTextNode(after);
117: }
118: else
119: {
120: next = owner.createCDATASection(after);
121: }
122:
123: if (this.next != null)
124: {
125: parent.insertBefore(next, this.next);
126: }
127: else
128: {
129: parent.appendChild(next);
130: }
131: setNodeValue(before);
132: return next;
133:
134: }
135: catch (IndexOutOfBoundsException x)
136: {
137: throw new DomDOMException(DOMException.INDEX_SIZE_ERR);
138: }
139: }
140:
141:
142:
143: public boolean isElementContentWhitespace()
144: {
145: if (parent != null)
146: {
147: DomDoctype doctype = (DomDoctype) owner.getDoctype();
148: if (doctype != null)
149: {
150: DTDElementTypeInfo info =
151: doctype.getElementTypeInfo(parent.getNodeName());
152: if (info != null)
153: {
154: if (info.model == null && info.model.indexOf("#PCDATA") != -1)
155: {
156: return false;
157: }
158: return getNodeValue().trim().length() == 0;
159: }
160: }
161: }
162: return false;
163: }
164:
165: public String getWholeText()
166: {
167: DomNode ref = this;
168: DomNode ctx;
169: for (ctx = previous; ctx != null &&
170: (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE);
171: ctx = ctx.previous)
172: {
173: ref = ctx;
174: }
175: StringBuffer buf = new StringBuffer(ref.getNodeValue());
176: for (ctx = ref.next; ctx != null &&
177: (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE);
178: ctx = ctx.next)
179: {
180: buf.append(ctx.getNodeValue());
181: }
182: return buf.toString ();
183: }
184:
185: public Text replaceWholeText(String content)
186: throws DOMException
187: {
188: boolean isEmpty = (content == null || content.length () == 0);
189: if (!isEmpty)
190: {
191: setNodeValue(content);
192: }
193:
194: DomNode ref = this;
195: DomNode ctx;
196: for (ctx = previous; ctx != null &&
197: (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE);
198: ctx = ctx.previous)
199: {
200: ref = ctx;
201: }
202: ctx = ref.next;
203: if ((isEmpty || ref != this) && parent != null)
204: {
205: parent.removeChild(ref);
206: }
207: for (; ctx != null &&
208: (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE);
209: ctx = ref)
210: {
211: ref = ctx.next;
212: if ((isEmpty || ctx != this) && parent != null)
213: {
214: parent.removeChild(ctx);
215: }
216: }
217: return (isEmpty) ? null : this;
218: }
219:
220: }