1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| package org.w3c.tidy; |
56 |
| |
57 |
| import org.w3c.dom.DOMException; |
58 |
| import org.w3c.dom.UserDataHandler; |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| public class DOMNodeImpl implements org.w3c.dom.Node |
69 |
| { |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| protected Node adaptee; |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
3
| protected DOMNodeImpl(Node adaptee)
|
81 |
| { |
82 |
3
| this.adaptee = adaptee;
|
83 |
| } |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
0
| public String getNodeValue()
|
89 |
| { |
90 |
0
| String value = "";
|
91 |
0
| if (adaptee.type == Node.TEXT_NODE
|
92 |
| || adaptee.type == Node.CDATA_TAG |
93 |
| || adaptee.type == Node.COMMENT_TAG |
94 |
| || adaptee.type == Node.PROC_INS_TAG) |
95 |
| { |
96 |
| |
97 |
0
| if (adaptee.textarray != null && adaptee.start < adaptee.end)
|
98 |
| { |
99 |
0
| value = TidyUtils.getString(adaptee.textarray, adaptee.start, adaptee.end - adaptee.start);
|
100 |
| } |
101 |
| } |
102 |
0
| return value;
|
103 |
| } |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
0
| public void setNodeValue(String nodeValue)
|
109 |
| { |
110 |
0
| if (adaptee.type == Node.TEXT_NODE
|
111 |
| || adaptee.type == Node.CDATA_TAG |
112 |
| || adaptee.type == Node.COMMENT_TAG |
113 |
| || adaptee.type == Node.PROC_INS_TAG) |
114 |
| { |
115 |
0
| byte[] textarray = TidyUtils.getBytes(nodeValue);
|
116 |
0
| adaptee.textarray = textarray;
|
117 |
0
| adaptee.start = 0;
|
118 |
0
| adaptee.end = textarray.length;
|
119 |
| } |
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
0
| public String getNodeName()
|
126 |
| { |
127 |
0
| return adaptee.element;
|
128 |
| } |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
0
| public short getNodeType()
|
134 |
| { |
135 |
0
| short result = -1;
|
136 |
0
| switch (adaptee.type)
|
137 |
| { |
138 |
0
| case Node.ROOT_NODE :
|
139 |
0
| result = org.w3c.dom.Node.DOCUMENT_NODE;
|
140 |
0
| break;
|
141 |
0
| case Node.DOCTYPE_TAG :
|
142 |
0
| result = org.w3c.dom.Node.DOCUMENT_TYPE_NODE;
|
143 |
0
| break;
|
144 |
0
| case Node.COMMENT_TAG :
|
145 |
0
| result = org.w3c.dom.Node.COMMENT_NODE;
|
146 |
0
| break;
|
147 |
0
| case Node.PROC_INS_TAG :
|
148 |
0
| result = org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE;
|
149 |
0
| break;
|
150 |
0
| case Node.TEXT_NODE :
|
151 |
0
| result = org.w3c.dom.Node.TEXT_NODE;
|
152 |
0
| break;
|
153 |
0
| case Node.CDATA_TAG :
|
154 |
0
| result = org.w3c.dom.Node.CDATA_SECTION_NODE;
|
155 |
0
| break;
|
156 |
0
| case Node.START_TAG :
|
157 |
0
| case Node.START_END_TAG :
|
158 |
0
| result = org.w3c.dom.Node.ELEMENT_NODE;
|
159 |
0
| break;
|
160 |
| } |
161 |
0
| return result;
|
162 |
| } |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
0
| public org.w3c.dom.Node getParentNode()
|
168 |
| { |
169 |
| |
170 |
0
| if (adaptee.parent != null)
|
171 |
| { |
172 |
0
| return adaptee.parent.getAdapter();
|
173 |
| } |
174 |
0
| return null;
|
175 |
| } |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
0
| public org.w3c.dom.NodeList getChildNodes()
|
181 |
| { |
182 |
0
| return new DOMNodeListImpl(adaptee);
|
183 |
| } |
184 |
| |
185 |
| |
186 |
| |
187 |
| |
188 |
0
| public org.w3c.dom.Node getFirstChild()
|
189 |
| { |
190 |
0
| if (adaptee.content != null)
|
191 |
| { |
192 |
0
| return adaptee.content.getAdapter();
|
193 |
| } |
194 |
0
| return null;
|
195 |
| } |
196 |
| |
197 |
| |
198 |
| |
199 |
| |
200 |
0
| public org.w3c.dom.Node getLastChild()
|
201 |
| { |
202 |
0
| if (adaptee.last != null)
|
203 |
| { |
204 |
0
| return adaptee.last.getAdapter();
|
205 |
| } |
206 |
0
| return null;
|
207 |
| } |
208 |
| |
209 |
| |
210 |
| |
211 |
| |
212 |
0
| public org.w3c.dom.Node getPreviousSibling()
|
213 |
| { |
214 |
0
| if (adaptee.prev != null)
|
215 |
| { |
216 |
0
| return adaptee.prev.getAdapter();
|
217 |
| } |
218 |
0
| return null;
|
219 |
| } |
220 |
| |
221 |
| |
222 |
| |
223 |
| |
224 |
0
| public org.w3c.dom.Node getNextSibling()
|
225 |
| { |
226 |
0
| if (adaptee.next != null)
|
227 |
| { |
228 |
0
| return adaptee.next.getAdapter();
|
229 |
| } |
230 |
0
| return null;
|
231 |
| } |
232 |
| |
233 |
| |
234 |
| |
235 |
| |
236 |
0
| public org.w3c.dom.NamedNodeMap getAttributes()
|
237 |
| { |
238 |
0
| return new DOMAttrMapImpl(adaptee.attributes);
|
239 |
| } |
240 |
| |
241 |
| |
242 |
| |
243 |
| |
244 |
0
| public org.w3c.dom.Document getOwnerDocument()
|
245 |
| { |
246 |
0
| Node node = this.adaptee;
|
247 |
0
| if (node != null && node.type == Node.ROOT_NODE)
|
248 |
| { |
249 |
0
| return null;
|
250 |
| } |
251 |
| |
252 |
0
| while (node != null && node.type != Node.ROOT_NODE)
|
253 |
| { |
254 |
0
| node = node.parent;
|
255 |
| } |
256 |
| |
257 |
0
| if (node != null)
|
258 |
| { |
259 |
0
| return (org.w3c.dom.Document) node.getAdapter();
|
260 |
| } |
261 |
0
| return null;
|
262 |
| } |
263 |
| |
264 |
| |
265 |
| |
266 |
| |
267 |
0
| public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
|
268 |
| { |
269 |
| |
270 |
| |
271 |
0
| if (newChild == null)
|
272 |
| { |
273 |
0
| return null;
|
274 |
| } |
275 |
0
| if (!(newChild instanceof DOMNodeImpl))
|
276 |
| { |
277 |
0
| throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "newChild not instanceof DOMNodeImpl");
|
278 |
| } |
279 |
0
| DOMNodeImpl newCh = (DOMNodeImpl) newChild;
|
280 |
| |
281 |
0
| if (this.adaptee.type == Node.ROOT_NODE)
|
282 |
| { |
283 |
0
| if (newCh.adaptee.type != Node.DOCTYPE_TAG && newCh.adaptee.type != Node.PROC_INS_TAG)
|
284 |
| { |
285 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
|
286 |
| } |
287 |
| } |
288 |
0
| else if (this.adaptee.type == Node.START_TAG)
|
289 |
| { |
290 |
0
| if (newCh.adaptee.type != Node.START_TAG
|
291 |
| && newCh.adaptee.type != Node.START_END_TAG |
292 |
| && newCh.adaptee.type != Node.COMMENT_TAG |
293 |
| && newCh.adaptee.type != Node.TEXT_NODE |
294 |
| && newCh.adaptee.type != Node.CDATA_TAG) |
295 |
| { |
296 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
|
297 |
| } |
298 |
| } |
299 |
0
| if (refChild == null)
|
300 |
| { |
301 |
0
| this.adaptee.insertNodeAtEnd(newCh.adaptee);
|
302 |
0
| if (this.adaptee.type == Node.START_END_TAG)
|
303 |
| { |
304 |
0
| this.adaptee.setType(Node.START_TAG);
|
305 |
| } |
306 |
| } |
307 |
| else |
308 |
| { |
309 |
0
| Node ref = this.adaptee.content;
|
310 |
0
| while (ref != null)
|
311 |
| { |
312 |
0
| if (ref.getAdapter() == refChild)
|
313 |
| { |
314 |
0
| break;
|
315 |
| } |
316 |
0
| ref = ref.next;
|
317 |
| } |
318 |
0
| if (ref == null)
|
319 |
| { |
320 |
0
| throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild not found");
|
321 |
| } |
322 |
0
| Node.insertNodeBeforeElement(ref, newCh.adaptee);
|
323 |
| } |
324 |
0
| return newChild;
|
325 |
| } |
326 |
| |
327 |
| |
328 |
| |
329 |
| |
330 |
0
| public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
|
331 |
| { |
332 |
| |
333 |
| |
334 |
0
| if (newChild == null)
|
335 |
| { |
336 |
0
| return null;
|
337 |
| } |
338 |
0
| if (!(newChild instanceof DOMNodeImpl))
|
339 |
| { |
340 |
0
| throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "newChild not instanceof DOMNodeImpl");
|
341 |
| } |
342 |
0
| DOMNodeImpl newCh = (DOMNodeImpl) newChild;
|
343 |
| |
344 |
0
| if (this.adaptee.type == Node.ROOT_NODE)
|
345 |
| { |
346 |
0
| if (newCh.adaptee.type != Node.DOCTYPE_TAG && newCh.adaptee.type != Node.PROC_INS_TAG)
|
347 |
| { |
348 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
|
349 |
| } |
350 |
| } |
351 |
0
| else if (this.adaptee.type == Node.START_TAG)
|
352 |
| { |
353 |
0
| if (newCh.adaptee.type != Node.START_TAG
|
354 |
| && newCh.adaptee.type != Node.START_END_TAG |
355 |
| && newCh.adaptee.type != Node.COMMENT_TAG |
356 |
| && newCh.adaptee.type != Node.TEXT_NODE |
357 |
| && newCh.adaptee.type != Node.CDATA_TAG) |
358 |
| { |
359 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
|
360 |
| } |
361 |
| } |
362 |
0
| if (oldChild == null)
|
363 |
| { |
364 |
0
| throw new DOMException(DOMException.NOT_FOUND_ERR, "oldChild not found");
|
365 |
| } |
366 |
| |
367 |
0
| Node n;
|
368 |
0
| Node ref = this.adaptee.content;
|
369 |
0
| while (ref != null)
|
370 |
| { |
371 |
0
| if (ref.getAdapter() == oldChild)
|
372 |
| { |
373 |
0
| break;
|
374 |
| } |
375 |
0
| ref = ref.next;
|
376 |
| } |
377 |
0
| if (ref == null)
|
378 |
| { |
379 |
0
| throw new DOMException(DOMException.NOT_FOUND_ERR, "oldChild not found");
|
380 |
| } |
381 |
0
| newCh.adaptee.next = ref.next;
|
382 |
0
| newCh.adaptee.prev = ref.prev;
|
383 |
0
| newCh.adaptee.last = ref.last;
|
384 |
0
| newCh.adaptee.parent = ref.parent;
|
385 |
0
| newCh.adaptee.content = ref.content;
|
386 |
0
| if (ref.parent != null)
|
387 |
| { |
388 |
0
| if (ref.parent.content == ref)
|
389 |
| { |
390 |
0
| ref.parent.content = newCh.adaptee;
|
391 |
| } |
392 |
0
| if (ref.parent.last == ref)
|
393 |
| { |
394 |
0
| ref.parent.last = newCh.adaptee;
|
395 |
| } |
396 |
| } |
397 |
0
| if (ref.prev != null)
|
398 |
| { |
399 |
0
| ref.prev.next = newCh.adaptee;
|
400 |
| } |
401 |
0
| if (ref.next != null)
|
402 |
| { |
403 |
0
| ref.next.prev = newCh.adaptee;
|
404 |
| } |
405 |
0
| for (n = ref.content; n != null; n = n.next)
|
406 |
| { |
407 |
0
| if (n.parent == ref)
|
408 |
| { |
409 |
0
| n.parent = newCh.adaptee;
|
410 |
| } |
411 |
| } |
412 |
| |
413 |
0
| return oldChild;
|
414 |
| } |
415 |
| |
416 |
| |
417 |
| |
418 |
| |
419 |
0
| public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
|
420 |
| { |
421 |
0
| if (oldChild == null)
|
422 |
| { |
423 |
0
| return null;
|
424 |
| } |
425 |
| |
426 |
0
| Node ref = this.adaptee.content;
|
427 |
0
| while (ref != null)
|
428 |
| { |
429 |
0
| if (ref.getAdapter() == oldChild)
|
430 |
| { |
431 |
0
| break;
|
432 |
| } |
433 |
0
| ref = ref.next;
|
434 |
| } |
435 |
0
| if (ref == null)
|
436 |
| { |
437 |
0
| throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild not found");
|
438 |
| } |
439 |
0
| Node.discardElement(ref);
|
440 |
| |
441 |
0
| if (this.adaptee.content == null && this.adaptee.type == Node.START_TAG)
|
442 |
| { |
443 |
0
| this.adaptee.setType(Node.START_END_TAG);
|
444 |
| } |
445 |
| |
446 |
0
| return oldChild;
|
447 |
| } |
448 |
| |
449 |
| |
450 |
| |
451 |
| |
452 |
0
| public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
|
453 |
| { |
454 |
| |
455 |
| |
456 |
0
| if (newChild == null)
|
457 |
| { |
458 |
0
| return null;
|
459 |
| } |
460 |
0
| if (!(newChild instanceof DOMNodeImpl))
|
461 |
| { |
462 |
0
| throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "newChild not instanceof DOMNodeImpl");
|
463 |
| } |
464 |
0
| DOMNodeImpl newCh = (DOMNodeImpl) newChild;
|
465 |
| |
466 |
0
| if (this.adaptee.type == Node.ROOT_NODE)
|
467 |
| { |
468 |
0
| if (newCh.adaptee.type != Node.DOCTYPE_TAG && newCh.adaptee.type != Node.PROC_INS_TAG)
|
469 |
| { |
470 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
|
471 |
| } |
472 |
| } |
473 |
0
| else if (this.adaptee.type == Node.START_TAG)
|
474 |
| { |
475 |
0
| if (newCh.adaptee.type != Node.START_TAG
|
476 |
| && newCh.adaptee.type != Node.START_END_TAG |
477 |
| && newCh.adaptee.type != Node.COMMENT_TAG |
478 |
| && newCh.adaptee.type != Node.TEXT_NODE |
479 |
| && newCh.adaptee.type != Node.CDATA_TAG) |
480 |
| { |
481 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
|
482 |
| } |
483 |
| } |
484 |
0
| this.adaptee.insertNodeAtEnd(newCh.adaptee);
|
485 |
| |
486 |
0
| if (this.adaptee.type == Node.START_END_TAG)
|
487 |
| { |
488 |
0
| this.adaptee.setType(Node.START_TAG);
|
489 |
| } |
490 |
| |
491 |
0
| return newChild;
|
492 |
| } |
493 |
| |
494 |
| |
495 |
| |
496 |
| |
497 |
0
| public boolean hasChildNodes()
|
498 |
| { |
499 |
0
| return (adaptee.content != null);
|
500 |
| } |
501 |
| |
502 |
| |
503 |
| |
504 |
| |
505 |
0
| public org.w3c.dom.Node cloneNode(boolean deep)
|
506 |
| { |
507 |
0
| Node node = adaptee.cloneNode(deep);
|
508 |
0
| node.parent = null;
|
509 |
0
| return node.getAdapter();
|
510 |
| } |
511 |
| |
512 |
| |
513 |
| |
514 |
| |
515 |
| |
516 |
0
| public void normalize()
|
517 |
| { |
518 |
| |
519 |
| } |
520 |
| |
521 |
| |
522 |
| |
523 |
| |
524 |
| |
525 |
0
| public boolean supports(String feature, String version)
|
526 |
| { |
527 |
0
| return isSupported(feature, version);
|
528 |
| } |
529 |
| |
530 |
| |
531 |
| |
532 |
| |
533 |
0
| public String getNamespaceURI()
|
534 |
| { |
535 |
0
| return null;
|
536 |
| } |
537 |
| |
538 |
| |
539 |
| |
540 |
| |
541 |
0
| public String getPrefix()
|
542 |
| { |
543 |
0
| return null;
|
544 |
| } |
545 |
| |
546 |
| |
547 |
| |
548 |
| |
549 |
0
| public void setPrefix(String prefix) throws DOMException
|
550 |
| { |
551 |
| |
552 |
| |
553 |
| |
554 |
| } |
555 |
| |
556 |
| |
557 |
| |
558 |
| |
559 |
0
| public String getLocalName()
|
560 |
| { |
561 |
0
| return getNodeName();
|
562 |
| } |
563 |
| |
564 |
| |
565 |
| |
566 |
| |
567 |
0
| public boolean isSupported(String feature, String version)
|
568 |
| { |
569 |
0
| return false;
|
570 |
| } |
571 |
| |
572 |
| |
573 |
| |
574 |
| |
575 |
0
| public boolean hasAttributes()
|
576 |
| { |
577 |
| |
578 |
0
| return this.adaptee.attributes != null;
|
579 |
| } |
580 |
| |
581 |
| |
582 |
| |
583 |
| |
584 |
| |
585 |
0
| public short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException
|
586 |
| { |
587 |
0
| throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
|
588 |
| } |
589 |
| |
590 |
| |
591 |
| |
592 |
| |
593 |
| |
594 |
0
| public String getBaseURI()
|
595 |
| { |
596 |
0
| return null;
|
597 |
| } |
598 |
| |
599 |
| |
600 |
| |
601 |
| |
602 |
| |
603 |
0
| public Object getFeature(String feature, String version)
|
604 |
| { |
605 |
0
| return null;
|
606 |
| } |
607 |
| |
608 |
| |
609 |
| |
610 |
| |
611 |
| |
612 |
0
| public String getTextContent() throws DOMException
|
613 |
| { |
614 |
0
| return null;
|
615 |
| } |
616 |
| |
617 |
| |
618 |
| |
619 |
| |
620 |
| |
621 |
0
| public Object getUserData(String key)
|
622 |
| { |
623 |
0
| return null;
|
624 |
| } |
625 |
| |
626 |
| |
627 |
| |
628 |
| |
629 |
0
| public boolean isDefaultNamespace(String namespaceURI)
|
630 |
| { |
631 |
0
| return false;
|
632 |
| } |
633 |
| |
634 |
| |
635 |
| |
636 |
| |
637 |
| |
638 |
0
| public boolean isEqualNode(org.w3c.dom.Node arg)
|
639 |
| { |
640 |
0
| return false;
|
641 |
| } |
642 |
| |
643 |
| |
644 |
| |
645 |
| |
646 |
| |
647 |
0
| public boolean isSameNode(org.w3c.dom.Node other)
|
648 |
| { |
649 |
0
| return false;
|
650 |
| } |
651 |
| |
652 |
| |
653 |
| |
654 |
| |
655 |
0
| public String lookupNamespaceURI(String prefix)
|
656 |
| { |
657 |
0
| return null;
|
658 |
| } |
659 |
| |
660 |
| |
661 |
| |
662 |
| |
663 |
0
| public String lookupPrefix(String namespaceURI)
|
664 |
| { |
665 |
0
| return null;
|
666 |
| } |
667 |
| |
668 |
| |
669 |
| |
670 |
| |
671 |
| |
672 |
0
| public void setTextContent(String textContent) throws DOMException
|
673 |
| { |
674 |
0
| throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Node is read only");
|
675 |
| } |
676 |
| |
677 |
| |
678 |
| |
679 |
| |
680 |
| |
681 |
0
| public Object setUserData(String key, Object data, UserDataHandler handler)
|
682 |
| { |
683 |
0
| return null;
|
684 |
| } |
685 |
| } |