1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.dom4j.dom; |
9 |
| |
10 |
| import org.dom4j.Element; |
11 |
| import org.dom4j.Text; |
12 |
| import org.dom4j.tree.DefaultText; |
13 |
| |
14 |
| import org.w3c.dom.DOMException; |
15 |
| import org.w3c.dom.Document; |
16 |
| import org.w3c.dom.NamedNodeMap; |
17 |
| import org.w3c.dom.NodeList; |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class DOMText extends DefaultText implements org.w3c.dom.Text { |
28 |
307
| public DOMText(String text) {
|
29 |
307
| super(text);
|
30 |
| } |
31 |
| |
32 |
0
| public DOMText(Element parent, String text) {
|
33 |
0
| super(parent, text);
|
34 |
| } |
35 |
| |
36 |
| |
37 |
| |
38 |
0
| public boolean supports(String feature, String version) {
|
39 |
0
| return DOMNodeHelper.supports(this, feature, version);
|
40 |
| } |
41 |
| |
42 |
0
| public String getNamespaceURI() {
|
43 |
0
| return DOMNodeHelper.getNamespaceURI(this);
|
44 |
| } |
45 |
| |
46 |
0
| public String getPrefix() {
|
47 |
0
| return DOMNodeHelper.getPrefix(this);
|
48 |
| } |
49 |
| |
50 |
0
| public void setPrefix(String prefix) throws DOMException {
|
51 |
0
| DOMNodeHelper.setPrefix(this, prefix);
|
52 |
| } |
53 |
| |
54 |
0
| public String getLocalName() {
|
55 |
0
| return DOMNodeHelper.getLocalName(this);
|
56 |
| } |
57 |
| |
58 |
0
| public String getNodeName() {
|
59 |
0
| return "#text";
|
60 |
| } |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
73
| public String getNodeValue() throws DOMException {
|
66 |
73
| return DOMNodeHelper.getNodeValue(this);
|
67 |
| } |
68 |
| |
69 |
0
| public void setNodeValue(String nodeValue) throws DOMException {
|
70 |
0
| DOMNodeHelper.setNodeValue(this, nodeValue);
|
71 |
| } |
72 |
| |
73 |
15
| public org.w3c.dom.Node getParentNode() {
|
74 |
15
| return DOMNodeHelper.getParentNode(this);
|
75 |
| } |
76 |
| |
77 |
0
| public NodeList getChildNodes() {
|
78 |
0
| return DOMNodeHelper.getChildNodes(this);
|
79 |
| } |
80 |
| |
81 |
0
| public org.w3c.dom.Node getFirstChild() {
|
82 |
0
| return DOMNodeHelper.getFirstChild(this);
|
83 |
| } |
84 |
| |
85 |
0
| public org.w3c.dom.Node getLastChild() {
|
86 |
0
| return DOMNodeHelper.getLastChild(this);
|
87 |
| } |
88 |
| |
89 |
0
| public org.w3c.dom.Node getPreviousSibling() {
|
90 |
0
| return DOMNodeHelper.getPreviousSibling(this);
|
91 |
| } |
92 |
| |
93 |
0
| public org.w3c.dom.Node getNextSibling() {
|
94 |
0
| return DOMNodeHelper.getNextSibling(this);
|
95 |
| } |
96 |
| |
97 |
0
| public NamedNodeMap getAttributes() {
|
98 |
0
| return null;
|
99 |
| } |
100 |
| |
101 |
0
| public Document getOwnerDocument() {
|
102 |
0
| return DOMNodeHelper.getOwnerDocument(this);
|
103 |
| } |
104 |
| |
105 |
0
| public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
|
106 |
| org.w3c.dom.Node refChild) throws DOMException { |
107 |
0
| checkNewChildNode(newChild);
|
108 |
| |
109 |
0
| return DOMNodeHelper.insertBefore(this, newChild, refChild);
|
110 |
| } |
111 |
| |
112 |
0
| public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
|
113 |
| org.w3c.dom.Node oldChild) throws DOMException { |
114 |
0
| checkNewChildNode(newChild);
|
115 |
| |
116 |
0
| return DOMNodeHelper.replaceChild(this, newChild, oldChild);
|
117 |
| } |
118 |
| |
119 |
0
| public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
|
120 |
| throws DOMException { |
121 |
0
| return DOMNodeHelper.removeChild(this, oldChild);
|
122 |
| } |
123 |
| |
124 |
0
| public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
|
125 |
| throws DOMException { |
126 |
0
| checkNewChildNode(newChild);
|
127 |
| |
128 |
0
| return DOMNodeHelper.appendChild(this, newChild);
|
129 |
| } |
130 |
| |
131 |
0
| private void checkNewChildNode(org.w3c.dom.Node newChild)
|
132 |
| throws DOMException { |
133 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
|
134 |
| "Text nodes cannot have children"); |
135 |
| } |
136 |
| |
137 |
0
| public boolean hasChildNodes() {
|
138 |
0
| return DOMNodeHelper.hasChildNodes(this);
|
139 |
| } |
140 |
| |
141 |
0
| public org.w3c.dom.Node cloneNode(boolean deep) {
|
142 |
0
| return DOMNodeHelper.cloneNode(this, deep);
|
143 |
| } |
144 |
| |
145 |
0
| public void normalize() {
|
146 |
0
| DOMNodeHelper.normalize(this);
|
147 |
| } |
148 |
| |
149 |
0
| public boolean isSupported(String feature, String version) {
|
150 |
0
| return DOMNodeHelper.isSupported(this, feature, version);
|
151 |
| } |
152 |
| |
153 |
0
| public boolean hasAttributes() {
|
154 |
0
| return DOMNodeHelper.hasAttributes(this);
|
155 |
| } |
156 |
| |
157 |
| |
158 |
| |
159 |
0
| public String getData() throws DOMException {
|
160 |
0
| return DOMNodeHelper.getData(this);
|
161 |
| } |
162 |
| |
163 |
0
| public void setData(String data) throws DOMException {
|
164 |
0
| DOMNodeHelper.setData(this, data);
|
165 |
| } |
166 |
| |
167 |
0
| public int getLength() {
|
168 |
0
| return DOMNodeHelper.getLength(this);
|
169 |
| } |
170 |
| |
171 |
0
| public String substringData(int offset, int count) throws DOMException {
|
172 |
0
| return DOMNodeHelper.substringData(this, offset, count);
|
173 |
| } |
174 |
| |
175 |
0
| public void appendData(String arg) throws DOMException {
|
176 |
0
| DOMNodeHelper.appendData(this, arg);
|
177 |
| } |
178 |
| |
179 |
0
| public void insertData(int offset, String arg) throws DOMException {
|
180 |
0
| DOMNodeHelper.insertData(this, offset, arg);
|
181 |
| } |
182 |
| |
183 |
0
| public void deleteData(int offset, int count) throws DOMException {
|
184 |
0
| DOMNodeHelper.deleteData(this, offset, count);
|
185 |
| } |
186 |
| |
187 |
0
| public void replaceData(int offset, int count, String arg)
|
188 |
| throws DOMException { |
189 |
0
| DOMNodeHelper.replaceData(this, offset, count, arg);
|
190 |
| } |
191 |
| |
192 |
| |
193 |
| |
194 |
0
| public org.w3c.dom.Text splitText(int offset) throws DOMException {
|
195 |
0
| if (isReadOnly()) {
|
196 |
0
| throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
|
197 |
| "CharacterData node is read only: " + this); |
198 |
| } else { |
199 |
0
| String text = getText();
|
200 |
0
| int length = (text != null) ? text.length() : 0;
|
201 |
| |
202 |
0
| if ((offset < 0) || (offset >= length)) {
|
203 |
0
| throw new DOMException(DOMException.INDEX_SIZE_ERR,
|
204 |
| "No text at offset: " + offset); |
205 |
| } else { |
206 |
0
| String start = text.substring(0, offset);
|
207 |
0
| String rest = text.substring(offset);
|
208 |
0
| setText(start);
|
209 |
| |
210 |
0
| Element parent = getParent();
|
211 |
0
| Text newText = createText(rest);
|
212 |
| |
213 |
0
| if (parent != null) {
|
214 |
0
| parent.add(newText);
|
215 |
| } |
216 |
| |
217 |
0
| return DOMNodeHelper.asDOMText(newText);
|
218 |
| } |
219 |
| } |
220 |
| } |
221 |
| |
222 |
| |
223 |
| |
224 |
0
| protected Text createText(String text) {
|
225 |
0
| return new DOMText(text);
|
226 |
| } |
227 |
| } |
228 |
| |
229 |
| |
230 |
| |
231 |
| |
232 |
| |
233 |
| |
234 |
| |
235 |
| |
236 |
| |
237 |
| |
238 |
| |
239 |
| |
240 |
| |
241 |
| |
242 |
| |
243 |
| |
244 |
| |
245 |
| |
246 |
| |
247 |
| |
248 |
| |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
| |
254 |
| |
255 |
| |
256 |
| |
257 |
| |
258 |
| |
259 |
| |
260 |
| |
261 |
| |
262 |
| |
263 |
| |
264 |
| |