|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.xml.dom; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| import org.apache.xindice.util.StringUtilities; |
|
25 |
| import org.apache.xindice.xml.NodeSource; |
|
26 |
| import org.apache.xindice.xml.TextWriter; |
|
27 |
| |
|
28 |
| import org.w3c.dom.Attr; |
|
29 |
| import org.w3c.dom.DOMException; |
|
30 |
| import org.w3c.dom.Document; |
|
31 |
| import org.w3c.dom.Element; |
|
32 |
| import org.w3c.dom.NamedNodeMap; |
|
33 |
| import org.w3c.dom.Node; |
|
34 |
| import org.w3c.dom.NodeList; |
|
35 |
| import org.w3c.dom.UserDataHandler; |
|
36 |
| |
|
37 |
| import java.util.ArrayList; |
|
38 |
| import java.util.HashMap; |
|
39 |
| import java.util.HashSet; |
|
40 |
| import java.util.Iterator; |
|
41 |
| import java.util.Map; |
|
42 |
| import java.util.Set; |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| public abstract class NodeImpl implements CompressedNode, DBNode { |
|
50 |
| |
|
51 |
| private static final Log log = LogFactory.getLog(NodeImpl.class); |
|
52 |
| |
|
53 |
| public static final String XMLNS_PREFIX = "xmlns"; |
|
54 |
| public static final String XML_PREFIX = "xml"; |
|
55 |
| |
|
56 |
| public static final String OBJECT_NS = "http://xml.apache.org/xindice/XMLObject"; |
|
57 |
| public static final String OBJECT_HREF = "href"; |
|
58 |
| public static final String OBJECT_TYPE = "type"; |
|
59 |
| |
|
60 |
| public static final String TYPE_CONTENT = "content"; |
|
61 |
| public static final String TYPE_REPLACE = "replace"; |
|
62 |
| public static final String TYPE_INSERT = "insert"; |
|
63 |
| public static final String TYPE_APPEND = "append"; |
|
64 |
| |
|
65 |
| |
|
66 |
| public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; |
|
67 |
| public static final String XML_URI = "http://www.w3.org/XML/1998/namespace"; |
|
68 |
| |
|
69 |
| |
|
70 |
| public static final DOMException EX_NO_MODIFICATION_ALLOWED = |
|
71 |
| new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "This Node Is Read-Only"); |
|
72 |
| |
|
73 |
| public static final DOMException EX_INUSE_ATTRIBUTE = |
|
74 |
| new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, "This Attribute Belongs To Another Element"); |
|
75 |
| |
|
76 |
| public static final DOMException EX_WRONG_DOCUMENT = |
|
77 |
| new DOMException(DOMException.WRONG_DOCUMENT_ERR, "This Attribute Belongs To Another Document"); |
|
78 |
| |
|
79 |
| public static final DOMException EX_NOT_FOUND = |
|
80 |
| new DOMException(DOMException.NOT_FOUND_ERR, "This Node Does Not Belong To This Element"); |
|
81 |
| |
|
82 |
| public static final DOMException EX_HIERARCHY_REQUEST = |
|
83 |
| new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "This Node Cannot Contain This Child"); |
|
84 |
| |
|
85 |
| public static final DOMException EX_NO_DATA_ALLOWED = |
|
86 |
| new DOMException(DOMException.NO_DATA_ALLOWED_ERR, "This Node Has No Value"); |
|
87 |
| |
|
88 |
| public static final DOMException EX_INVALID_STATE = |
|
89 |
| new DOMException(DOMException.INVALID_STATE_ERR, "NodeIterator Has Been Detached"); |
|
90 |
| |
|
91 |
| public static final DOMException EX_DOMSTRING_SIZE = |
|
92 |
| new DOMException(DOMException.DOMSTRING_SIZE_ERR, "String Too Large For Type"); |
|
93 |
| |
|
94 |
| public static final DOMException EX_INDEX_SIZE = |
|
95 |
| new DOMException(DOMException.INDEX_SIZE_ERR, "Index Out Of Bounds"); |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| public static final short DOCUMENT_POSITION_DISCONNECTED = 0x01; |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| public static final short DOCUMENT_POSITION_PRECEDING = 0x02; |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| public static final short DOCUMENT_POSITION_FOLLOWING = 0x04; |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| public static final short DOCUMENT_POSITION_CONTAINS = 0x08; |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| public static final short DOCUMENT_POSITION_CONTAINED_BY = 0x10; |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| public static final short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| protected NodeSource source; |
|
135 |
| protected byte[] data; |
|
136 |
| protected int pos; |
|
137 |
| protected int len; |
|
138 |
| |
|
139 |
| protected boolean loaded; |
|
140 |
| protected boolean dirty; |
|
141 |
| |
|
142 |
| |
|
143 |
| protected NodeImpl parentNode; |
|
144 |
| protected String nodeName; |
|
145 |
| protected String nodeValue; |
|
146 |
| |
|
147 |
| |
|
148 |
| protected Document ownerDocument; |
|
149 |
| protected String nsURI; |
|
150 |
| |
|
151 |
| |
|
152 |
| protected HashMap userData; |
|
153 |
| protected HashMap handlers; |
|
154 |
| protected Object key; |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
0
| public NodeImpl() {
|
|
160 |
| } |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
350638
| public NodeImpl(NodeImpl parent, byte[] data, int pos, int len) {
|
|
171 |
350638
| this.parentNode = parent;
|
|
172 |
350638
| this.data = data;
|
|
173 |
350638
| this.pos = pos;
|
|
174 |
350638
| this.len = len;
|
|
175 |
| |
|
176 |
350638
| if (parent == null) {
|
|
177 |
43811
| ownerDocument = null;
|
|
178 |
306827
| } else if (parent.getNodeType() == DOCUMENT_TYPE_NODE) {
|
|
179 |
0
| this.ownerDocument = (Document) parent;
|
|
180 |
| } else { |
|
181 |
306827
| this.ownerDocument = parent.getOwnerDocument();
|
|
182 |
| } |
|
183 |
| } |
|
184 |
| |
|
185 |
739034
| public NodeImpl(NodeImpl parent, boolean dirty) {
|
|
186 |
739034
| this.parentNode = parent;
|
|
187 |
| |
|
188 |
739034
| if (parent == null) {
|
|
189 |
30213
| this.ownerDocument = null;
|
|
190 |
708821
| } else if (parent.getNodeType() == DOCUMENT_TYPE_NODE) {
|
|
191 |
0
| this.ownerDocument = (Document) parent;
|
|
192 |
| } else { |
|
193 |
708821
| this.ownerDocument = parent.getOwnerDocument();
|
|
194 |
| } |
|
195 |
| |
|
196 |
739034
| if (dirty) {
|
|
197 |
440280
| setDirty();
|
|
198 |
| } |
|
199 |
| } |
|
200 |
| |
|
201 |
0
| public final boolean isLoaded() {
|
|
202 |
0
| return loaded;
|
|
203 |
| } |
|
204 |
| |
|
205 |
0
| protected void checkLoaded() {
|
|
206 |
0
| if (!loaded) {
|
|
207 |
0
| loaded = true;
|
|
208 |
| } |
|
209 |
| } |
|
210 |
| |
|
211 |
0
| public void load() {
|
|
212 |
0
| checkLoaded();
|
|
213 |
| } |
|
214 |
| |
|
215 |
0
| public void unload() {
|
|
216 |
0
| if (loaded) {
|
|
217 |
0
| loaded = false;
|
|
218 |
| } |
|
219 |
| } |
|
220 |
| |
|
221 |
0
| public short getSymbolID() {
|
|
222 |
0
| return -1;
|
|
223 |
| } |
|
224 |
| |
|
225 |
902128
| public final void checkReadOnly() throws DOMException {
|
|
226 |
902128
| DocumentImpl doc = (DocumentImpl) getOwnerDocument();
|
|
227 |
902132
| if (doc != null && doc.isReadOnly()) {
|
|
228 |
0
| throw EX_NO_MODIFICATION_ALLOWED;
|
|
229 |
| } |
|
230 |
| } |
|
231 |
| |
|
232 |
0
| public final boolean isDefined() {
|
|
233 |
0
| return data != null;
|
|
234 |
| } |
|
235 |
| |
|
236 |
18
| public final boolean isDirty() {
|
|
237 |
18
| return dirty;
|
|
238 |
| } |
|
239 |
| |
|
240 |
2711072
| public final void setDirty() {
|
|
241 |
2711071
| dirty = true;
|
|
242 |
2711071
| if (parentNode != null) {
|
|
243 |
1559398
| parentNode.setDirty();
|
|
244 |
| } |
|
245 |
| } |
|
246 |
| |
|
247 |
849
| public byte[] getDataBytes() {
|
|
248 |
849
| return data;
|
|
249 |
| } |
|
250 |
| |
|
251 |
0
| public void setDataBytes(byte[] data, int pos, int len) {
|
|
252 |
0
| this.data = data;
|
|
253 |
0
| this.pos = pos;
|
|
254 |
0
| this.len = len;
|
|
255 |
| } |
|
256 |
| |
|
257 |
0
| public void setDataBytes(byte[] data) {
|
|
258 |
0
| this.data = data;
|
|
259 |
| } |
|
260 |
| |
|
261 |
0
| public int getDataPos() {
|
|
262 |
0
| return pos;
|
|
263 |
| } |
|
264 |
| |
|
265 |
0
| public void setDataPos(int pos) {
|
|
266 |
0
| this.pos = pos;
|
|
267 |
| } |
|
268 |
| |
|
269 |
0
| public int getDataLen() {
|
|
270 |
0
| return len;
|
|
271 |
| } |
|
272 |
| |
|
273 |
0
| public void setDataLen(int len) {
|
|
274 |
0
| this.len = len;
|
|
275 |
| } |
|
276 |
| |
|
277 |
2
| public final void setNodeName(String nodeName) {
|
|
278 |
2
| checkLoaded();
|
|
279 |
2
| this.nodeName = nodeName;
|
|
280 |
2
| setDirty();
|
|
281 |
| } |
|
282 |
| |
|
283 |
410035
| public final void setParentNode(NodeImpl parentNode) {
|
|
284 |
410035
| this.parentNode = parentNode;
|
|
285 |
| } |
|
286 |
| |
|
287 |
0
| protected Node getPreviousSibling(Node node) {
|
|
288 |
0
| return null;
|
|
289 |
| } |
|
290 |
| |
|
291 |
0
| protected Node getNextSibling(Node node) {
|
|
292 |
0
| return null;
|
|
293 |
| } |
|
294 |
| |
|
295 |
27623
| public final void setSource(NodeSource source) {
|
|
296 |
27623
| this.source = source;
|
|
297 |
| } |
|
298 |
| |
|
299 |
11048
| public final NodeSource getSource() {
|
|
300 |
11048
| if (source == null && parentNode != null) {
|
|
301 |
1103
| return parentNode.getSource();
|
|
302 |
| } else { |
|
303 |
9945
| return source;
|
|
304 |
| } |
|
305 |
| } |
|
306 |
| |
|
307 |
0
| public void expandSource() {
|
|
308 |
| } |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
| public abstract short getNodeType(); |
|
316 |
| |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
0
| public Node getLastChild() {
|
|
322 |
0
| return null;
|
|
323 |
| } |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
| |
|
328 |
| |
|
329 |
2
| public final Node getPreviousSibling() {
|
|
330 |
2
| return parentNode != null ? parentNode.getPreviousSibling(this)
|
|
331 |
| : null; |
|
332 |
| } |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
526502
| public final Node getNextSibling() {
|
|
339 |
526502
| return parentNode != null ? parentNode.getNextSibling(this)
|
|
340 |
| : null; |
|
341 |
| } |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
0
| public NamedNodeMap getAttributes() {
|
|
348 |
0
| return null;
|
|
349 |
| } |
|
350 |
| |
|
351 |
3
| public boolean hasAttributes() {
|
|
352 |
3
| return false;
|
|
353 |
| } |
|
354 |
| |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
3285796
| public final Document getOwnerDocument() {
|
|
361 |
3285797
| if (getNodeType() == Node.DOCUMENT_NODE) {
|
|
362 |
552038
| return (Document) this;
|
|
363 |
| } |
|
364 |
| |
|
365 |
2733785
| return ownerDocument;
|
|
366 |
| } |
|
367 |
| |
|
368 |
| |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| |
|
390 |
| |
|
391 |
0
| public Node insertBefore(Node newChild, Node refChild) throws DOMException {
|
|
392 |
0
| throw EX_HIERARCHY_REQUEST;
|
|
393 |
| } |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
| |
|
404 |
| |
|
405 |
| |
|
406 |
1788
| public NodeList getChildNodes() {
|
|
407 |
1788
| return new NodeListImpl(this);
|
|
408 |
| } |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
| |
|
415 |
| |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
| |
|
420 |
0
| public void setNodeValue(String nodeValue) throws DOMException {
|
|
421 |
0
| throw EX_NO_DATA_ALLOWED;
|
|
422 |
| } |
|
423 |
| |
|
424 |
| |
|
425 |
| |
|
426 |
| |
|
427 |
| |
|
428 |
| |
|
429 |
| |
|
430 |
612936
| public final Node getParentNode() {
|
|
431 |
612936
| return parentNode;
|
|
432 |
| } |
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
2217
| public Node getFirstChild() {
|
|
439 |
2217
| return null;
|
|
440 |
| } |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
1537838
| public String getNodeName() {
|
|
446 |
1537838
| checkLoaded();
|
|
447 |
1537834
| return nodeName;
|
|
448 |
| } |
|
449 |
| |
|
450 |
| |
|
451 |
| |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
739705
| public String getNodeValue() throws DOMException {
|
|
460 |
739705
| checkLoaded();
|
|
461 |
739704
| return nodeValue;
|
|
462 |
| } |
|
463 |
| |
|
464 |
| |
|
465 |
| |
|
466 |
| |
|
467 |
| |
|
468 |
| |
|
469 |
| |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
| |
|
475 |
| |
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
| |
|
480 |
| |
|
481 |
0
| public synchronized Node replaceChild(Node newChild, Node oldChild) throws DOMException {
|
|
482 |
0
| throw EX_HIERARCHY_REQUEST;
|
|
483 |
| } |
|
484 |
| |
|
485 |
| |
|
486 |
| |
|
487 |
| |
|
488 |
| |
|
489 |
| |
|
490 |
| |
|
491 |
| |
|
492 |
| |
|
493 |
| |
|
494 |
| |
|
495 |
0
| public synchronized Node removeChild(Node oldChild) throws DOMException {
|
|
496 |
0
| throw EX_NOT_FOUND;
|
|
497 |
| } |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
| |
|
504 |
| |
|
505 |
| |
|
506 |
| |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
0
| public synchronized Node appendChild(Node newChild) throws DOMException {
|
|
516 |
0
| throw EX_HIERARCHY_REQUEST;
|
|
517 |
| } |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
| |
|
522 |
| |
|
523 |
| |
|
524 |
| |
|
525 |
193944
| public boolean hasChildNodes() {
|
|
526 |
193944
| return false;
|
|
527 |
| } |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
| |
|
532 |
| |
|
533 |
| |
|
534 |
| |
|
535 |
| |
|
536 |
| |
|
537 |
| |
|
538 |
| |
|
539 |
| |
|
540 |
| |
|
541 |
| |
|
542 |
| |
|
543 |
| |
|
544 |
21
| public final Node cloneNode(boolean deep) {
|
|
545 |
21
| return cloneNode(deep, true);
|
|
546 |
| } |
|
547 |
| |
|
548 |
21
| protected final synchronized Node cloneNode(boolean deep, boolean invokeHandler) {
|
|
549 |
21
| DocumentImpl doc = (DocumentImpl) getOwnerDocument();
|
|
550 |
| |
|
551 |
| |
|
552 |
21
| if (deep && this.data != null) {
|
|
553 |
2
| byte[] data = this.data;
|
|
554 |
2
| int pos = this.pos;
|
|
555 |
2
| int len = this.len;
|
|
556 |
| |
|
557 |
2
| if (dirty) {
|
|
558 |
0
| data = DOMCompressor.compress(this, doc.getSymbols());
|
|
559 |
0
| pos = 0;
|
|
560 |
0
| len = data.length;
|
|
561 |
| } |
|
562 |
| |
|
563 |
2
| NodeImpl newNode = null;
|
|
564 |
2
| switch (getNodeType()) {
|
|
565 |
| |
|
566 |
0
| case Node.ATTRIBUTE_NODE:
|
|
567 |
0
| newNode = new AttrImpl(this, true);
|
|
568 |
0
| newNode.setNodeName(getNodeName());
|
|
569 |
0
| newNode.setNodeValue(getNodeValue());
|
|
570 |
0
| break;
|
|
571 |
| |
|
572 |
0
| case Node.CDATA_SECTION_NODE:
|
|
573 |
0
| newNode = new CDATASectionImpl(this, data, pos, len);
|
|
574 |
0
| break;
|
|
575 |
| |
|
576 |
0
| case Node.COMMENT_NODE:
|
|
577 |
0
| newNode = new CommentImpl(this, data, pos, len);
|
|
578 |
0
| break;
|
|
579 |
| |
|
580 |
0
| case Node.DOCUMENT_FRAGMENT_NODE:
|
|
581 |
0
| DocumentFragmentImpl df = new DocumentFragmentImpl(this);
|
|
582 |
0
| NodeList nl = getChildNodes();
|
|
583 |
0
| for (int i = 0; i < nl.getLength(); i++) {
|
|
584 |
0
| df.appendChild(nl.item(i).cloneNode(deep));
|
|
585 |
| } |
|
586 |
0
| newNode = df;
|
|
587 |
0
| break;
|
|
588 |
| |
|
589 |
2
| case Node.ELEMENT_NODE:
|
|
590 |
2
| newNode = new ElementImpl(this, data, pos, len);
|
|
591 |
2
| newNode.setNodeName(getNodeName());
|
|
592 |
2
| break;
|
|
593 |
| |
|
594 |
0
| case Node.ENTITY_REFERENCE_NODE:
|
|
595 |
0
| newNode = new EntityReferenceImpl(this, data, pos, len);
|
|
596 |
0
| break;
|
|
597 |
| |
|
598 |
0
| case Node.NOTATION_NODE:
|
|
599 |
0
| newNode = new NotationImpl(this, data, pos, len);
|
|
600 |
0
| break;
|
|
601 |
| |
|
602 |
0
| case Node.PROCESSING_INSTRUCTION_NODE:
|
|
603 |
0
| newNode = new ProcessingInstructionImpl(this, data, pos, len);
|
|
604 |
0
| break;
|
|
605 |
| |
|
606 |
0
| case Node.TEXT_NODE:
|
|
607 |
0
| newNode = new TextImpl(this, data, pos, len);
|
|
608 |
0
| break;
|
|
609 |
| |
|
610 |
0
| default:
|
|
611 |
0
| if (log.isWarnEnabled()) {
|
|
612 |
0
| log.warn("invalid node type : " + getNodeType());
|
|
613 |
| } |
|
614 |
| } |
|
615 |
| |
|
616 |
2
| if (newNode != null) {
|
|
617 |
| |
|
618 |
2
| newNode.parentNode = null;
|
|
619 |
2
| if (invokeHandler) {
|
|
620 |
2
| invokeHandlers(UserDataHandler.NODE_CLONED, this, newNode);
|
|
621 |
| } |
|
622 |
2
| return newNode;
|
|
623 |
| } |
|
624 |
| } |
|
625 |
| |
|
626 |
19
| checkLoaded();
|
|
627 |
19
| NodeImpl node = null;
|
|
628 |
19
| switch (getNodeType()) {
|
|
629 |
0
| case Node.ATTRIBUTE_NODE:
|
|
630 |
0
| AttrImpl attr = (AttrImpl) doc.createAttribute(nodeName);
|
|
631 |
0
| attr.setValue(nodeValue);
|
|
632 |
0
| node = attr;
|
|
633 |
0
| break;
|
|
634 |
| |
|
635 |
0
| case Node.CDATA_SECTION_NODE:
|
|
636 |
0
| node = (NodeImpl) doc.createCDATASection(nodeValue);
|
|
637 |
0
| break;
|
|
638 |
| |
|
639 |
0
| case Node.COMMENT_NODE:
|
|
640 |
0
| node = (NodeImpl) doc.createComment(nodeValue);
|
|
641 |
0
| break;
|
|
642 |
| |
|
643 |
0
| case Node.DOCUMENT_FRAGMENT_NODE:
|
|
644 |
0
| node = (NodeImpl) doc.createDocumentFragment();
|
|
645 |
0
| break;
|
|
646 |
| |
|
647 |
19
| case Node.ELEMENT_NODE:
|
|
648 |
19
| ElementImpl elem = (ElementImpl) doc.createElement(nodeName);
|
|
649 |
19
| NamedNodeMap attrs = getAttributes();
|
|
650 |
19
| int size = attrs.getLength();
|
|
651 |
19
| for (int i = 0; i < size; i++) {
|
|
652 |
11
| Attr a = (Attr) attrs.item(i);
|
|
653 |
11
| elem.setAttribute(a.getName(), a.getValue());
|
|
654 |
| } |
|
655 |
| |
|
656 |
19
| if (getPrefix() != null) {
|
|
657 |
2
| elem.nsURI = lookupNamespaceURI(getPrefix());
|
|
658 |
| } else { |
|
659 |
17
| elem.nsURI = lookupDefaultNamespaceURI();
|
|
660 |
| } |
|
661 |
| |
|
662 |
19
| node = elem;
|
|
663 |
19
| break;
|
|
664 |
| |
|
665 |
0
| case Node.ENTITY_REFERENCE_NODE:
|
|
666 |
0
| node = (NodeImpl) doc.createEntityReference(nodeValue);
|
|
667 |
0
| break;
|
|
668 |
| |
|
669 |
0
| case Node.PROCESSING_INSTRUCTION_NODE:
|
|
670 |
0
| node = (NodeImpl) doc.createProcessingInstruction(nodeName, nodeValue);
|
|
671 |
0
| break;
|
|
672 |
| |
|
673 |
0
| case Node.TEXT_NODE:
|
|
674 |
0
| node = (NodeImpl) doc.createTextNode(nodeValue);
|
|
675 |
0
| break;
|
|
676 |
| |
|
677 |
0
| default:
|
|
678 |
0
| if (log.isWarnEnabled()) {
|
|
679 |
0
| log.warn("invalid node type : " + getNodeType());
|
|
680 |
| } |
|
681 |
0
| break;
|
|
682 |
| } |
|
683 |
| |
|
684 |
19
| if (node != null && deep) {
|
|
685 |
19
| NodeList list = getChildNodes();
|
|
686 |
19
| for (int i = 0; i < list.getLength(); i++) {
|
|
687 |
2
| node.appendChild(list.item(i).cloneNode(deep));
|
|
688 |
| } |
|
689 |
| } |
|
690 |
| |
|
691 |
19
| if (node != null && invokeHandler) {
|
|
692 |
19
| node.parentNode = null;
|
|
693 |
19
| invokeHandlers(UserDataHandler.NODE_CLONED, this, node);
|
|
694 |
| } |
|
695 |
| |
|
696 |
19
| return node;
|
|
697 |
| } |
|
698 |
| |
|
699 |
| |
|
700 |
| |
|
701 |
| |
|
702 |
| |
|
703 |
| |
|
704 |
| |
|
705 |
| |
|
706 |
| |
|
707 |
| |
|
708 |
| |
|
709 |
| |
|
710 |
| |
|
711 |
| |
|
712 |
| |
|
713 |
| |
|
714 |
| |
|
715 |
| |
|
716 |
| |
|
717 |
0
| public void normalize() {
|
|
718 |
| } |
|
719 |
| |
|
720 |
| |
|
721 |
| |
|
722 |
| |
|
723 |
| |
|
724 |
| |
|
725 |
| |
|
726 |
| |
|
727 |
| |
|
728 |
| |
|
729 |
| |
|
730 |
| |
|
731 |
| |
|
732 |
| |
|
733 |
| |
|
734 |
0
| public final boolean isSupported(String feature, String version) {
|
|
735 |
0
| return DOMImplementationImpl.HasFeature(feature, version);
|
|
736 |
| } |
|
737 |
| |
|
738 |
| |
|
739 |
| |
|
740 |
| |
|
741 |
| |
|
742 |
| |
|
743 |
| |
|
744 |
| |
|
745 |
| |
|
746 |
| |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
| |
|
751 |
| |
|
752 |
| |
|
753 |
| |
|
754 |
811610
| public final String getNamespaceURI() {
|
|
755 |
| |
|
756 |
811610
| short nodeType = getNodeType();
|
|
757 |
811612
| if (nodeType == Node.ATTRIBUTE_NODE) {
|
|
758 |
215819
| if (nodeName.equals(XMLNS_PREFIX) || nodeName.startsWith(XMLNS_PREFIX + ":")) {
|
|
759 |
| |
|
760 |
5434
| return XMLNS_URI;
|
|
761 |
210387
| } else if (nodeName.startsWith(XML_PREFIX + ":")) {
|
|
762 |
| |
|
763 |
4
| return XML_URI;
|
|
764 |
| } |
|
765 |
| } |
|
766 |
806174
| if (nsURI != null) {
|
|
767 |
67
| return nsURI;
|
|
768 |
| } |
|
769 |
| |
|
770 |
806107
| if (!(nodeType == Node.ELEMENT_NODE || nodeType == Node.ATTRIBUTE_NODE)) {
|
|
771 |
225139
| return null;
|
|
772 |
| } |
|
773 |
| |
|
774 |
580968
| String prefix = getPrefix();
|
|
775 |
580968
| return prefix != null ? lookupNamespaceURI(prefix)
|
|
776 |
| : lookupDefaultNamespaceURI(); |
|
777 |
| } |
|
778 |
| |
|
779 |
| |
|
780 |
| |
|
781 |
| |
|
782 |
| |
|
783 |
| |
|
784 |
| |
|
785 |
| |
|
786 |
| |
|
787 |
| |
|
788 |
| |
|
789 |
| |
|
790 |
| |
|
791 |
| |
|
792 |
| |
|
793 |
| |
|
794 |
| |
|
795 |
| |
|
796 |
| |
|
797 |
| |
|
798 |
| |
|
799 |
| |
|
800 |
| |
|
801 |
| |
|
802 |
| |
|
803 |
| |
|
804 |
| |
|
805 |
| |
|
806 |
1090250
| public final String getPrefix() {
|
|
807 |
1090250
| short nodeType = getNodeType();
|
|
808 |
1090250
| if (!(nodeType == Node.ELEMENT_NODE || nodeType == Node.ATTRIBUTE_NODE)) {
|
|
809 |
0
| return null;
|
|
810 |
| } |
|
811 |
1090250
| checkLoaded();
|
|
812 |
1090250
| int idx = nodeName.indexOf(':');
|
|
813 |
1090250
| return idx != -1 ? nodeName.substring(0, idx)
|
|
814 |
| : null; |
|
815 |
| } |
|
816 |
| |
|
817 |
| |
|
818 |
| |
|
819 |
| |
|
820 |
| |
|
821 |
| |
|
822 |
| |
|
823 |
| |
|
824 |
| |
|
825 |
| |
|
826 |
| |
|
827 |
| |
|
828 |
| |
|
829 |
| |
|
830 |
| |
|
831 |
| |
|
832 |
| |
|
833 |
| |
|
834 |
| |
|
835 |
| |
|
836 |
| |
|
837 |
| |
|
838 |
| |
|
839 |
| |
|
840 |
| |
|
841 |
| |
|
842 |
| |
|
843 |
| |
|
844 |
0
| public final void setPrefix(String prefix) {
|
|
845 |
0
| short nodeType = getNodeType();
|
|
846 |
0
| if (!(nodeType == Node.ELEMENT_NODE || nodeType == Node.ATTRIBUTE_NODE)) {
|
|
847 |
0
| return;
|
|
848 |
| } |
|
849 |
0
| checkReadOnly();
|
|
850 |
0
| String ln = getLocalName();
|
|
851 |
0
| if (prefix != null) {
|
|
852 |
0
| setNodeName(prefix + ':' + ln);
|
|
853 |
| } else { |
|
854 |
0
| setNodeName(ln);
|
|
855 |
| } |
|
856 |
| } |
|
857 |
| |
|
858 |
| |
|
859 |
| |
|
860 |
| |
|
861 |
| |
|
862 |
| |
|
863 |
| |
|
864 |
| |
|
865 |
959512
| public final String getLocalName() {
|
|
866 |
959512
| short nodeType = getNodeType();
|
|
867 |
959512
| if (!(nodeType == Node.ELEMENT_NODE || nodeType == Node.ATTRIBUTE_NODE)) {
|
|
868 |
450278
| return null;
|
|
869 |
| } |
|
870 |
509234
| String prefix = getPrefix();
|
|
871 |
509234
| return prefix != null ? getNodeName().substring(prefix.length() + 1)
|
|
872 |
| : getNodeName(); |
|
873 |
| } |
|
874 |
| |
|
875 |
| |
|
876 |
| |
|
877 |
| |
|
878 |
| |
|
879 |
| |
|
880 |
| |
|
881 |
1279643
| public final String lookupDefaultNamespaceURI() {
|
|
882 |
1279644
| if (getNodeType() != Node.ELEMENT_NODE) {
|
|
883 |
560180
| return null;
|
|
884 |
| } |
|
885 |
| |
|
886 |
719464
| String uri = ((Element) this).getAttribute(XMLNS_PREFIX);
|
|
887 |
719465
| if (uri != null && uri.length() > 0) {
|
|
888 |
19767
| return uri;
|
|
889 |
| } |
|
890 |
| |
|
891 |
699698
| return parentNode != null ? parentNode.lookupDefaultNamespaceURI()
|
|
892 |
| : null; |
|
893 |
| } |
|
894 |
| |
|
895 |
| |
|
896 |
| |
|
897 |
| |
|
898 |
| |
|
899 |
| |
|
900 |
| |
|
901 |
| |
|
902 |
| |
|
903 |
| |
|
904 |
| |
|
905 |
| |
|
906 |
22
| public final boolean isSameNode(Node other) {
|
|
907 |
22
| return this == other;
|
|
908 |
| } |
|
909 |
| |
|
910 |
| |
|
911 |
| |
|
912 |
| |
|
913 |
| |
|
914 |
| |
|
915 |
| |
|
916 |
| |
|
917 |
| |
|
918 |
0
| public final String lookupPrefix(String namespaceURI) {
|
|
919 |
0
| if (getNodeType() == Node.ELEMENT_NODE) {
|
|
920 |
0
| NamedNodeMap map = getAttributes();
|
|
921 |
0
| int size = map.getLength();
|
|
922 |
0
| for (int i = 0; i < size; i++) {
|
|
923 |
0
| Attr attr = (Attr) map.item(i);
|
|
924 |
0
| String name = attr.getName();
|
|
925 |
0
| if (name.startsWith(XMLNS_PREFIX + ':')
|
|
926 |
| && attr.getValue().equals(namespaceURI)) { |
|
927 |
0
| return name.substring(XMLNS_PREFIX.length() + 1);
|
|
928 |
| } |
|
929 |
| } |
|
930 |
| } |
|
931 |
0
| return parentNode != null ? parentNode.lookupPrefix(namespaceURI) : null;
|
|
932 |
| } |
|
933 |
| |
|
934 |
| |
|
935 |
| |
|
936 |
| |
|
937 |
| |
|
938 |
| |
|
939 |
| |
|
940 |
| |
|
941 |
| |
|
942 |
| |
|
943 |
| |
|
944 |
2017
| public final String lookupNamespaceURI(String prefix) {
|
|
945 |
2017
| String uri = null;
|
|
946 |
2017
| if (getNodeType() == Node.ELEMENT_NODE) {
|
|
947 |
1299
| uri = ((Element) this).getAttribute(XMLNS_PREFIX + ':' + prefix);
|
|
948 |
| } |
|
949 |
2017
| if (uri != null && uri.length() > 0) {
|
|
950 |
1037
| return uri;
|
|
951 |
| } |
|
952 |
| |
|
953 |
980
| return parentNode != null ? parentNode.lookupNamespaceURI(prefix) : null;
|
|
954 |
| } |
|
955 |
| |
|
956 |
| |
|
957 |
| |
|
958 |
| |
|
959 |
| |
|
960 |
| |
|
961 |
| |
|
962 |
| |
|
963 |
| |
|
964 |
| |
|
965 |
| |
|
966 |
| |
|
967 |
| |
|
968 |
| |
|
969 |
| |
|
970 |
| |
|
971 |
2
| public final synchronized Object setUserData(String key, Object data, UserDataHandler handler) {
|
|
972 |
2
| if (userData == null) {
|
|
973 |
2
| userData = new HashMap();
|
|
974 |
| } |
|
975 |
2
| if (handlers == null) {
|
|
976 |
2
| handlers = new HashMap();
|
|
977 |
| } |
|
978 |
| |
|
979 |
2
| Object oldData = userData.get(key);
|
|
980 |
2
| if (data != null) {
|
|
981 |
2
| userData.put(key, data);
|
|
982 |
2
| if (handler != null) {
|
|
983 |
2
| handlers.put(key, handler);
|
|
984 |
| } |
|
985 |
| } else { |
|
986 |
0
| userData.remove(key);
|
|
987 |
0
| handlers.remove(key);
|
|
988 |
| } |
|
989 |
| |
|
990 |
2
| return oldData;
|
|
991 |
| } |
|
992 |
| |
|
993 |
| |
|
994 |
| |
|
995 |
| |
|
996 |
| |
|
997 |
| |
|
998 |
| |
|
999 |
| |
|
1000 |
| |
|
1001 |
0
| public final synchronized Object getUserData(String key) {
|
|
1002 |
0
| if (userData == null) {
|
|
1003 |
0
| return null;
|
|
1004 |
| } |
|
1005 |
0
| return userData.get(key);
|
|
1006 |
| } |
|
1007 |
| |
|
1008 |
0
| Node renameNode(String namespaceURI, String qualifiedName, String prefix) throws DOMException {
|
|
1009 |
0
| throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Only Element and Attribute nodes can be renamed.");
|
|
1010 |
| } |
|
1011 |
| |
|
1012 |
| |
|
1013 |
| |
|
1014 |
| |
|
1015 |
| |
|
1016 |
| |
|
1017 |
| |
|
1018 |
0
| public String getBaseURI() {
|
|
1019 |
0
| return null;
|
|
1020 |
| } |
|
1021 |
| |
|
1022 |
| |
|
1023 |
| |
|
1024 |
| |
|
1025 |
| |
|
1026 |
| |
|
1027 |
| |
|
1028 |
| |
|
1029 |
| |
|
1030 |
| |
|
1031 |
| |
|
1032 |
| |
|
1033 |
| |
|
1034 |
| |
|
1035 |
| |
|
1036 |
| |
|
1037 |
| |
|
1038 |
| |
|
1039 |
| |
|
1040 |
| |
|
1041 |
| |
|
1042 |
| |
|
1043 |
| |
|
1044 |
203
| public String getTextContent() {
|
|
1045 |
203
| return getNodeValue();
|
|
1046 |
| } |
|
1047 |
| |
|
1048 |
| |
|
1049 |
| |
|
1050 |
| |
|
1051 |
| |
|
1052 |
| |
|
1053 |
| |
|
1054 |
| |
|
1055 |
| |
|
1056 |
| |
|
1057 |
4
| public void setTextContent(String textContent) throws DOMException {
|
|
1058 |
4
| checkReadOnly();
|
|
1059 |
4
| checkLoaded();
|
|
1060 |
2
| if (textContent == null || "".equals(textContent)) return;
|
|
1061 |
| |
|
1062 |
| |
|
1063 |
2
| if (hasChildNodes()) {
|
|
1064 |
2
| int num = getChildNodes().getLength();
|
|
1065 |
2
| for (int i = 0; i < num; i++) {
|
|
1066 |
8
| removeChild(getChildNodes().item(0));
|
|
1067 |
| } |
|
1068 |
| } |
|
1069 |
| |
|
1070 |
2
| appendChild(new TextImpl(this, textContent));
|
|
1071 |
| } |
|
1072 |
| |
|
1073 |
| |
|
1074 |
| |
|
1075 |
| |
|
1076 |
| |
|
1077 |
| |
|
1078 |
| |
|
1079 |
| |
|
1080 |
| |
|
1081 |
| |
|
1082 |
| |
|
1083 |
| |
|
1084 |
| |
|
1085 |
| |
|
1086 |
| |
|
1087 |
| |
|
1088 |
| |
|
1089 |
| |
|
1090 |
| |
|
1091 |
| |
|
1092 |
| |
|
1093 |
| |
|
1094 |
| |
|
1095 |
| |
|
1096 |
| |
|
1097 |
| |
|
1098 |
| |
|
1099 |
| |
|
1100 |
| |
|
1101 |
| |
|
1102 |
| |
|
1103 |
| |
|
1104 |
| |
|
1105 |
| |
|
1106 |
| |
|
1107 |
| |
|
1108 |
| |
|
1109 |
| |
|
1110 |
18
| public boolean isEqualNode(Node other) {
|
|
1111 |
4
| if (this.isSameNode(other)) return true;
|
|
1112 |
| |
|
1113 |
| |
|
1114 |
14
| if (other == null || other.getNodeType() != this.getNodeType()) {
|
|
1115 |
0
| return false;
|
|
1116 |
| } |
|
1117 |
| |
|
1118 |
| |
|
1119 |
| |
|
1120 |
14
| return StringUtilities.equals(getNodeName(), other.getNodeName()) &&
|
|
1121 |
| StringUtilities.equals(getLocalName(), other.getLocalName()) && |
|
1122 |
| StringUtilities.equals(getNamespaceURI(), other.getNamespaceURI()) && |
|
1123 |
| StringUtilities.equals(getPrefix(), other.getPrefix()) && |
|
1124 |
| StringUtilities.equals(getNodeValue(), other.getNodeValue()); |
|
1125 |
| |
|
1126 |
| } |
|
1127 |
| |
|
1128 |
| |
|
1129 |
| |
|
1130 |
| |
|
1131 |
| |
|
1132 |
| |
|
1133 |
| |
|
1134 |
0
| public Object getFeature(String feature, String version) {
|
|
1135 |
0
| if (DOMImplementationImpl.HasFeature(feature, version)) {
|
|
1136 |
0
| return this;
|
|
1137 |
| } |
|
1138 |
| |
|
1139 |
0
| return null;
|
|
1140 |
| } |
|
1141 |
| |
|
1142 |
| |
|
1143 |
| |
|
1144 |
| |
|
1145 |
| |
|
1146 |
| |
|
1147 |
0
| public boolean isDefaultNamespace(String namespaceURI) {
|
|
1148 |
0
| return namespaceURI.equals(lookupDefaultNamespaceURI());
|
|
1149 |
| } |
|
1150 |
| |
|
1151 |
| |
|
1152 |
| |
|
1153 |
| |
|
1154 |
| |
|
1155 |
| |
|
1156 |
| |
|
1157 |
| |
|
1158 |
| |
|
1159 |
| |
|
1160 |
| |
|
1161 |
| |
|
1162 |
| |
|
1163 |
12
| public short compareDocumentPosition(Node other) throws DOMException {
|
|
1164 |
12
| if (this == other) {
|
|
1165 |
0
| return 0;
|
|
1166 |
| } |
|
1167 |
| |
|
1168 |
12
| if (!(other instanceof NodeImpl)) {
|
|
1169 |
0
| throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Nodes are from different DOM implementations");
|
|
1170 |
| } |
|
1171 |
| |
|
1172 |
12
| if (getOwnerDocument() != other.getOwnerDocument()) {
|
|
1173 |
2
| return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
|
|
1174 |
| } |
|
1175 |
| |
|
1176 |
10
| ArrayList ancestors = new ArrayList();
|
|
1177 |
10
| Node root = findAncestors(this, other, ancestors);
|
|
1178 |
10
| Node ancNode = (Node) ancestors.get(0);
|
|
1179 |
10
| Node ancOther = (Node) ancestors.get(1);
|
|
1180 |
| |
|
1181 |
10
| if (root == null) {
|
|
1182 |
0
| return DOCUMENT_POSITION_DISCONNECTED;
|
|
1183 |
| } |
|
1184 |
| |
|
1185 |
10
| if (root == other) {
|
|
1186 |
2
| return DOCUMENT_POSITION_CONTAINS | DOCUMENT_POSITION_PRECEDING;
|
|
1187 |
| } |
|
1188 |
| |
|
1189 |
8
| if (root == this) {
|
|
1190 |
4
| return DOCUMENT_POSITION_CONTAINED_BY | DOCUMENT_POSITION_FOLLOWING;
|
|
1191 |
| } |
|
1192 |
| |
|
1193 |
4
| short ancNodeType = ancNode.getNodeType();
|
|
1194 |
4
| short ancOtherType = ancOther.getNodeType();
|
|
1195 |
| |
|
1196 |
4
| boolean nodeIsChild = ancNodeType != ATTRIBUTE_NODE && ancNodeType != NOTATION_NODE;
|
|
1197 |
4
| boolean otherIsChild = ancOtherType != ATTRIBUTE_NODE && ancOtherType != NOTATION_NODE;
|
|
1198 |
| |
|
1199 |
4
| if (nodeIsChild && otherIsChild) {
|
|
1200 |
2
| Node child = root.getFirstChild();
|
|
1201 |
| |
|
1202 |
4
| while (child != null) {
|
|
1203 |
4
| if (child == ancNode) {
|
|
1204 |
2
| return DOCUMENT_POSITION_FOLLOWING;
|
|
1205 |
2
| } else if (child == ancOther) {
|
|
1206 |
0
| return DOCUMENT_POSITION_PRECEDING;
|
|
1207 |
| } |
|
1208 |
| |
|
1209 |
2
| child = child.getNextSibling();
|
|
1210 |
| } |
|
1211 |
| |
|
1212 |
0
| return 0;
|
|
1213 |
2
| } else if (nodeIsChild ^ otherIsChild) {
|
|
1214 |
2
| return nodeIsChild ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
|
|
1215 |
| } else { |
|
1216 |
0
| if (ancNodeType != ancOtherType) {
|
|
1217 |
0
| return ancNodeType > ancOtherType ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
|
|
1218 |
| } else { |
|
1219 |
0
| return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
|
|
1220 |
| } |
|
1221 |
| } |
|
1222 |
| } |
|
1223 |
| |
|
1224 |
28
| private Node findParent(Set seen, Node node, ArrayList path) {
|
|
1225 |
28
| if (node == null) {
|
|
1226 |
0
| return null;
|
|
1227 |
| } |
|
1228 |
| |
|
1229 |
28
| seen.add(node);
|
|
1230 |
28
| path.add(node);
|
|
1231 |
28
| return node.getParentNode();
|
|
1232 |
| } |
|
1233 |
| |
|
1234 |
10
| private Node findAncestors(Node node1, Node node2, ArrayList ancestors) {
|
|
1235 |
10
| ArrayList path1 = new ArrayList();
|
|
1236 |
10
| ArrayList path2 = new ArrayList();
|
|
1237 |
10
| HashSet seen = new HashSet();
|
|
1238 |
| |
|
1239 |
10
| Node root = null;
|
|
1240 |
10
| do {
|
|
1241 |
14
| node1 = findParent(seen, node1, path1);
|
|
1242 |
14
| node2 = findParent(seen, node2, path2);
|
|
1243 |
| |
|
1244 |
14
| if (seen.contains(node1)) {
|
|
1245 |
2
| root = node1;
|
|
1246 |
2
| ancestors.add(path1.get(path1.size() - 1));
|
|
1247 |
2
| int idx = path2.indexOf(node1);
|
|
1248 |
2
| ancestors.add(path2.get(idx > 0 ? idx - 1 : 0));
|
|
1249 |
| |
|
1250 |
2
| break;
|
|
1251 |
12
| } else if (seen.contains(node2)) {
|
|
1252 |
6
| root = node2;
|
|
1253 |
6
| int idx = path1.indexOf(node2);
|
|
1254 |
6
| ancestors.add(path1.get(idx > 0 ? idx - 1 : 0));
|
|
1255 |
6
| ancestors.add(path2.get(path2.size() - 1));
|
|
1256 |
| |
|
1257 |
6
| break;
|
|
1258 |
6
| } else if (node1 != null && node1 == node2) {
|
|
1259 |
2
| root = node1;
|
|
1260 |
2
| ancestors.add(path1.get(path1.size() - 1));
|
|
1261 |
2
| ancestors.add(path2.get(path2.size() - 1));
|
|
1262 |
| |
|
1263 |
2
| break;
|
|
1264 |
| } |
|
1265 |
4
| } while (node1 != null || node2 != null);
|
|
1266 |
| |
|
1267 |
10
| return root;
|
|
1268 |
| } |
|
1269 |
| |
|
1270 |
| |
|
1271 |
| |
|
1272 |
| |
|
1273 |
| |
|
1274 |
| |
|
1275 |
| |
|
1276 |
| |
|
1277 |
| |
|
1278 |
| |
|
1279 |
| |
|
1280 |
| |
|
1281 |
| |
|
1282 |
| |
|
1283 |
| |
|
1284 |
| |
|
1285 |
| |
|
1286 |
| |
|
1287 |
| |
|
1288 |
| |
|
1289 |
| |
|
1290 |
| |
|
1291 |
| |
|
1292 |
| |
|
1293 |
| |
|
1294 |
| |
|
1295 |
| |
|
1296 |
| |
|
1297 |
| |
|
1298 |
| |
|
1299 |
| |
|
1300 |
| |
|
1301 |
| |
|
1302 |
| |
|
1303 |
| |
|
1304 |
| |
|
1305 |
| |
|
1306 |
| |
|
1307 |
| |
|
1308 |
| |
|
1309 |
| |
|
1310 |
| |
|
1311 |
| |
|
1312 |
| |
|
1313 |
| |
|
1314 |
| |
|
1315 |
| |
|
1316 |
4462
| protected void invokeHandlers(short op, Node src, Node dst) {
|
|
1317 |
4462
| if (!(src instanceof NodeImpl)) {
|
|
1318 |
0
| return;
|
|
1319 |
| } |
|
1320 |
| |
|
1321 |
4462
| ((NodeImpl) src).invokeHandlers(op, dst);
|
|
1322 |
| } |
|
1323 |
| |
|
1324 |
4462
| protected synchronized void invokeHandlers(short op, Node dst) {
|
|
1325 |
4462
| if (handlers == null || handlers.isEmpty()) {
|
|
1326 |
4458
| return;
|
|
1327 |
| } |
|
1328 |
| |
|
1329 |
4
| for (Iterator i = handlers.entrySet().iterator(); i.hasNext(); ) {
|
|
1330 |
4
| final Map.Entry entry = (Map.Entry) i.next();
|
|
1331 |
4
| final String key = (String) entry.getKey();
|
|
1332 |
4
| final UserDataHandler handler = (UserDataHandler) entry.getValue();
|
|
1333 |
| |
|
1334 |
4
| try {
|
|
1335 |
4
| handler.handle(op, key, userData.get(key), this, dst);
|
|
1336 |
| } catch (Exception e) { |
|
1337 |
0
| log.error("User data handler '" + key + "' failed for operation " + op, e);
|
|
1338 |
| } |
|
1339 |
| } |
|
1340 |
| |
|
1341 |
| } |
|
1342 |
| |
|
1343 |
| |
|
1344 |
| |
|
1345 |
| |
|
1346 |
9
| public String toString() {
|
|
1347 |
9
| return TextWriter.toString(this);
|
|
1348 |
| } |
|
1349 |
| } |