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