ElementNodeList.java
5.45 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa;
import com.adobe.xfa.*;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.ResId;
public final class ElementNodeList
extends NodeList {
private final Element mElement;
private Node mLastNode;
private int mLastPosn;
private int mLength;
ElementNodeList(Element e) {
this.mElement = e;
this.reset();
}
@Override
public void append(Obj newNode) {
if (this.isReadOnly() || newNode == null) {
return;
}
if (!(newNode instanceof Node)) {
throw new ExFull(ResId.ArgumentMismatchException);
}
this.mElement.appendChild((Node)newNode, true);
this.reset();
}
@Override
public Object clone() {
return new ArrayNodeList(this.mElement);
}
@Override
public String getClassAtom() {
return "nodeList";
}
@Override
public String getClassName() {
return "nodeList";
}
@Override
public Node getNamedItem(String name) {
if (name == null) {
return null;
}
String aName = name.intern();
for (Node child = this.mElement.getFirstXFAChild(); child != null; child = child.getNextXFASibling()) {
if (aName != child.getName()) continue;
return child;
}
return null;
}
@Override
public Node getNamedItem(String aName, String aClassName, int nTargetOccurrence) {
if (aName == null && aClassName == null) {
return null;
}
int nOccurrence = 0;
for (Node tmp = this.mElement.getFirstXFAChild(); tmp != null; tmp = tmp.getNextXFASibling()) {
boolean bMatched = false;
if (aName != null && aClassName != null) {
if (aClassName == tmp.getClassAtom() && aName == tmp.getPrivateName()) {
bMatched = true;
}
} else if (aClassName != null && aClassName == tmp.getClassAtom()) {
bMatched = true;
} else if (aName != null && aName == tmp.getPrivateName()) {
bMatched = true;
}
if (!bMatched) continue;
if (nOccurrence == nTargetOccurrence) {
return tmp;
}
++nOccurrence;
}
return null;
}
@Override
Integer getOccurrence(Node oNode) {
int nOccurrence = 0;
String aName = oNode.getName();
String aClassName = oNode.getClassAtom();
for (Node child = this.mElement.getFirstXFAChild(); child != null; child = child.getNextXFASibling()) {
if (aClassName != child.getClassAtom() || aName != child.getName()) continue;
if (oNode == child) {
return nOccurrence;
}
++nOccurrence;
}
return null;
}
@Override
public void insert(Obj newNode, Obj refNode) {
if (this.isReadOnly() || newNode == null) {
return;
}
if (refNode == null) {
throw new ExFull(ResId.InsertFailedException);
}
if (!(newNode instanceof Node)) {
throw new ExFull(ResId.ArgumentMismatchException);
}
if (!(refNode instanceof Node)) {
throw new ExFull(ResId.ArgumentMismatchException);
}
this.mElement.insertChild((Node)newNode, (Node)refNode, true);
this.reset();
}
@Override
public Obj item(int index) {
if (index < this.mLastPosn) {
this.mLastPosn = 0;
this.mLastNode = this.mElement.getFirstXFAChild();
}
while (index >= this.mLastPosn) {
if (index == this.mLastPosn) {
return this.mLastNode;
}
this.mLastNode = this.mLastNode.getNextXFASibling();
++this.mLastPosn;
}
return null;
}
@Override
public int length() {
if (this.mLength == -1) {
this.mLength = 0;
for (Node child = this.mElement.getFirstXFAChild(); child != null; child = child.getNextXFASibling()) {
++this.mLength;
}
}
return this.mLength;
}
@Override
public void remove(Obj removeNode) {
if (this.isReadOnly() || removeNode == null) {
return;
}
if (!(removeNode instanceof Node)) {
throw new ExFull(ResId.ArgumentMismatchException);
}
Node node = (Node)removeNode;
if (node.getXFAParent() != this.mElement) {
throw new ExFull(ResId.RemoveFailedException);
}
node.remove();
this.reset();
}
private void reset() {
this.mLastNode = this.mElement.getFirstXFAChild();
this.mLastPosn = 0;
this.mLength = -1;
}
@Override
boolean appendPermsCheck() {
if (this.mElement != null && !this.mElement.checkAncestorPerms()) {
return false;
}
return true;
}
@Override
boolean removePermsCheck(Obj obj) {
Node node;
if (this.mElement != null && !this.mElement.checkAncestorPerms()) {
return false;
}
if (obj instanceof Node && !(node = (Node)obj).checkDescendentPerms()) {
return false;
}
return true;
}
@Override
boolean insertPermsCheck() {
if (this.mElement != null && !this.mElement.checkAncestorPerms()) {
return false;
}
return true;
}
}