1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.dom;
16
17 import org.htmlunit.html.DomNode;
18 import org.htmlunit.html.DomNodeIterator;
19 import org.htmlunit.javascript.HtmlUnitScriptable;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstructor;
22 import org.htmlunit.javascript.configuration.JsxFunction;
23 import org.htmlunit.javascript.configuration.JsxGetter;
24
25
26
27
28
29
30
31 @JsxClass
32 public class NodeIterator extends HtmlUnitScriptable {
33
34 private DomNodeIterator iterator_;
35
36
37
38
39 public NodeIterator() {
40 super();
41 }
42
43
44
45
46 @JsxConstructor
47 public void jsConstructor() {
48
49 }
50
51
52
53
54
55
56
57
58
59 public NodeIterator(final Node root, final int whatToShow,
60 final org.w3c.dom.traversal.NodeFilter filter) {
61 super();
62 iterator_ = new DomNodeIterator(root.getDomNodeOrDie(), whatToShow, filter, true);
63 }
64
65
66
67
68
69 @JsxGetter
70 public Node getRoot() {
71 return getNodeOrNull(iterator_.getRoot());
72 }
73
74 private static Node getNodeOrNull(final DomNode domNode) {
75 if (domNode == null) {
76 return null;
77 }
78 return domNode.getScriptableObject();
79 }
80
81
82
83
84
85 public long getWhatToShow() {
86 if (iterator_.getWhatToShow() == NodeFilter.SHOW_ALL) {
87 return 0xFFFFFFFFL;
88 }
89 return iterator_.getWhatToShow();
90 }
91
92
93
94
95
96 @JsxGetter
97 public Object getFilter() {
98
99 return iterator_.getFilter();
100 }
101
102
103
104
105 @JsxFunction
106 public void detach() {
107 iterator_.detach();
108 }
109
110
111
112
113
114 @JsxFunction
115 public Node nextNode() {
116 return getNodeOrNull(iterator_.nextNode());
117 }
118
119
120
121
122
123 @JsxFunction
124 public Node previousNode() {
125 return getNodeOrNull(iterator_.previousNode());
126 }
127 }