DataWindow.java
16 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.data;
import com.adobe.xfa.Arg;
import com.adobe.xfa.Document;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.NodeList;
import com.adobe.xfa.Obj;
import com.adobe.xfa.ScriptTable;
import com.adobe.xfa.data.DataModel;
import com.adobe.xfa.data.DataNode;
import com.adobe.xfa.data.DataWindowFilter;
import com.adobe.xfa.data.DataWindowScript;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.IntegerHolder;
import com.adobe.xfa.ut.ResId;
import java.util.ArrayList;
import java.util.List;
public final class DataWindow
extends Obj {
private static final int DEFAULT_GRANULARITY = 16;
private String maRecordName;
private boolean mbDefined;
private boolean mbLazyLoading;
private boolean mbUpToDate;
private DataModel mDataModel;
private final List<DataWindowFilter> mFilters = new ArrayList<DataWindowFilter>();
private int mnAbsRecordIndex;
private int mnCurrentRecordIndex;
private int mnDesiredRecordsAfter;
private int mnDesiredRecordsBefore;
private int mnRecordLevel;
private int mnRecordsAfter;
private int mnRecordsBefore;
private int mnSpecifiedRecordLevel;
private final List<Integer> mRecordIndexes = new ArrayList<Integer>();
private final ArrayList<DataNode> mRecords = new ArrayList(16);
private Element mStartNode;
void addFilter(DataWindowFilter oFilter) {
this.mFilters.add(oFilter);
}
public void addRecordGroup(DataNode dataGroup) {
if (this.mRecords.size() == 16) {
this.mRecords.ensureCapacity(1024);
}
for (int i = 0; i < this.mFilters.size(); ++i) {
DataWindowFilter f = this.mFilters.get(i);
if (f.filterRecord(dataGroup, this.mnAbsRecordIndex)) continue;
++this.mnAbsRecordIndex;
return;
}
this.mRecords.add(dataGroup);
this.mRecordIndexes.add(this.mnAbsRecordIndex);
++this.mnAbsRecordIndex;
}
private void adjustRecordLevel(boolean bUseRecordName) {
IntegerHolder recordLevel;
assert (this.mnRecordLevel == 0);
Element oNewRoot = this.findStartNode(this.mStartNode, true);
if (oNewRoot == null) {
return;
}
Document doc = oNewRoot.getOwnerDocument();
for (Element parent = oNewRoot.getXFAParent(); parent != doc && parent != null; parent = parent.getXFAParent()) {
++this.mnRecordLevel;
}
this.mnRecordLevel += this.mnSpecifiedRecordLevel;
if (bUseRecordName && this.maRecordName != null && this.findRecordByName(oNewRoot, recordLevel = new IntegerHolder(this.mnRecordLevel), this.maRecordName)) {
this.mnRecordLevel = recordLevel.value;
}
}
public int currentRecordNumber() {
this.validate(false);
return this.mnCurrentRecordIndex;
}
void dataGroupAddedOrRemoved(DataNode dataGroup, boolean bAdded) {
Element oParent;
DataNode oDomPeer;
if (this.mDataModel == null) {
return;
}
if (!this.mbUpToDate) {
return;
}
if (this.mbLazyLoading) {
return;
}
if (this.maRecordName != null && this.maRecordName != dataGroup.getName()) {
return;
}
Element oAliasNode = this.mDataModel.getAliasNode();
if (oAliasNode == dataGroup) {
this.invalidate();
return;
}
for (oParent = dataGroup; oParent != null && oParent != oAliasNode; oParent = oParent.getXFAParent()) {
}
if (oParent == null) {
return;
}
if (this.mnRecordLevel == 0) {
this.adjustRecordLevel(true);
if (this.mnRecordLevel == 0) {
return;
}
}
if ((oDomPeer = dataGroup) == null) {
return;
}
int nLevel = 1;
for (Element parentCheck = oDomPeer.getXFAParent(); parentCheck != null; parentCheck = parentCheck.getXFAParent()) {
if (++nLevel <= this.mnRecordLevel) continue;
return;
}
if (nLevel == this.mnRecordLevel) {
this.invalidate();
}
}
private boolean findRecordByName(Element root, IntegerHolder recordLevel, String aRecordName) {
String aName = root.getLocalName();
String aNewName = this.mDataModel.getMapping(aName);
if (aNewName != "") {
aName = aNewName;
}
if (aRecordName == aName && !this.isExcluded(root)) {
return recordLevel.value > 0;
}
for (Node node = root.getFirstXMLChild(); node != null; node = node.getNextXMLSibling()) {
++recordLevel.value;
if (node instanceof Element && this.findRecordByName((Element)node, recordLevel, aRecordName)) {
return recordLevel.value > 0;
}
--recordLevel.value;
}
return false;
}
private Element findStartNode(Element node, boolean bCheckParent) {
String aNS;
boolean bHasModelParent = false;
if (bCheckParent && this.mDataModel.isCompatibleNS(aNS = node.getNS()) && node.getLocalName() == "datasets") {
bHasModelParent = true;
}
if (!bHasModelParent && !this.isExcluded(node)) {
return node;
}
for (Node childNode = node.getFirstXMLChild(); childNode != null; childNode = childNode.getNextXMLSibling()) {
if (!(childNode instanceof Element)) continue;
Element childElement = (Element)childNode;
Element search = null;
if (bHasModelParent) {
String aNS2 = childElement.getNS();
String aLocalName = childElement.getLocalName();
if (this.mDataModel.isCompatibleNS(aNS2) && (aLocalName == "data" || aLocalName == "Data")) {
search = this.findStartNode(childElement, false);
}
} else {
search = this.findStartNode(childElement, false);
}
if (search == null) continue;
return search;
}
return null;
}
@Override
public String getClassAtom() {
return "dataWindow";
}
@Override
public String getClassName() {
return "dataWindow";
}
public Arg getScriptProperty(String sPropertyName) {
throw new ExFull(ResId.UNSUPPORTED_OPERATION, "DataWindow#getScriptProperty");
}
@Override
public ScriptTable getScriptTable() {
return DataWindowScript.getScriptTable();
}
public void gotoRecord(int newRecord) {
this.validate(false);
if (this.mbDefined && newRecord == this.currentRecordNumber()) {
return;
}
if (this.mbLazyLoading) {
int newLastRecord = newRecord + this.mnDesiredRecordsAfter;
if (newLastRecord < newRecord) {
newLastRecord = Integer.MAX_VALUE;
}
if (this.mnCurrentRecordIndex + this.mnRecordsAfter < newLastRecord) {
this.loadToRecord(newLastRecord);
} else if (this.mRecords.get(newRecord) == null) {
this.mbDefined = false;
throw new ExFull(ResId.InvalidRecordException);
}
}
if (newRecord < 0 || newRecord >= this.mRecords.size()) {
this.mbDefined = false;
return;
}
this.mnCurrentRecordIndex = newRecord;
this.mbDefined = true;
this.mnRecordsAfter = this.mRecords.size() - this.mnCurrentRecordIndex - 1;
if (this.mnRecordsAfter > this.mnDesiredRecordsAfter) {
this.mnRecordsAfter = this.mnDesiredRecordsAfter;
}
this.mnRecordsBefore = this.mnCurrentRecordIndex;
if (this.mnRecordsBefore > this.mnDesiredRecordsBefore) {
this.mnRecordsBefore = this.mnDesiredRecordsBefore;
}
this.notifyPeers(0, "record", null);
}
void initialize(DataModel root, Element startNode, int recordLevel, String aRecordName, int nDesiredRecordsBefore, int nDesiredRecordsAfter) {
this.mbUpToDate = false;
this.mStartNode = startNode;
this.mnSpecifiedRecordLevel = recordLevel;
this.maRecordName = aRecordName;
Document doc = startNode.getOwnerDocument();
this.mbLazyLoading = doc.isIncrementalLoad();
this.mnDesiredRecordsBefore = nDesiredRecordsBefore;
this.mnDesiredRecordsAfter = nDesiredRecordsAfter;
this.mDataModel = root;
if (this.mnRecordLevel == 0) {
this.adjustRecordLevel(false);
}
if (this.maRecordName != null) {
Element startNodeCopy = this.findStartNode(startNode, true);
if (startNodeCopy == null) {
this.mDataModel.addErrorList(new ExFull(ResId.CantFindRecordException), 3, null);
return;
}
IntegerHolder recordLevelHolder = new IntegerHolder(this.mnRecordLevel);
if (!this.findRecordByName(startNodeCopy, recordLevelHolder, this.maRecordName)) {
if (!this.mbLazyLoading) {
this.mDataModel.addErrorList(new ExFull(ResId.CantFindRecordException), 3, null);
return;
}
Element e = doc.loadToNextElement(null);
while (e != null) {
String aName = e.getLocalName();
if (aName == this.maRecordName && !this.isExcluded(e)) {
if (this.findRecordByName(startNodeCopy, recordLevelHolder, this.maRecordName)) break;
this.mDataModel.addErrorList(new ExFull(ResId.CantFindRecordException), 3, null);
return;
}
e = doc.loadToNextElement(null);
}
if (e == null) {
this.mDataModel.addErrorList(new ExFull(ResId.CantFindRecordException), 3, null);
return;
}
}
this.mnRecordLevel = recordLevelHolder.value;
}
}
private void invalidate() {
this.mbUpToDate = false;
this.mRecords.clear();
this.mRecordIndexes.clear();
this.notifyPeers(0, "", null);
}
public boolean isDefined() {
this.validate(false);
return this.mbDefined;
}
private boolean isExcluded(Element node) {
String aNS = node.getNS();
return this.mDataModel.isCompatibleNS(aNS) || this.mDataModel.excludeNS(aNS);
}
boolean isRecordDepth(Node node) {
int nLevel = 1;
Document oDoc = node.getOwnerDocument();
for (Element parentCheck = node.getXMLParent(); parentCheck != null && parentCheck != oDoc; parentCheck = parentCheck.getXMLParent()) {
if (++nLevel <= this.mnRecordLevel) continue;
return false;
}
return nLevel == this.mnRecordLevel;
}
public boolean isRecordGroup(DataNode dataGroup) {
if (this.maRecordName != null && this.maRecordName != dataGroup.getName()) {
return false;
}
if (dataGroup.getXFAParent() == this.mDataModel) {
return false;
}
Node peer = dataGroup.getXmlPeer();
return this.isRecordDepth(peer);
}
public boolean isUpToDate() {
return this.mbUpToDate;
}
private void loadToRecord(int newRecord) {
assert (this.mbLazyLoading);
if (newRecord < this.mnCurrentRecordIndex) {
this.mbDefined = false;
throw new ExFull(ResId.InvalidRecordException);
}
while (this.mDataModel.loadToNextRecord() != null) {
int nWindowSize;
int nRecordsSize = this.mRecords.size();
if (nRecordsSize > (nWindowSize = this.mnDesiredRecordsAfter + this.mnDesiredRecordsBefore + 1)) {
DataNode dataGroup;
int nLast;
int i = nLast = nRecordsSize - nWindowSize - 1;
while ((dataGroup = this.mRecords.get(i)) != null) {
dataGroup.remove();
this.mRecords.set(i, null);
if (i == 0) break;
--i;
}
}
if (nRecordsSize < newRecord) continue;
return;
}
}
public void moveCurrentRecord(int recordOffset) {
this.validate(false);
this.gotoRecord(this.currentRecordNumber() + recordOffset);
}
private void populate(DataNode root) {
NodeList children = root.getNodes();
int numChildren = children.length();
for (int i = 0; i < numChildren; ++i) {
DataNode node = (DataNode)children.item(i);
if (!node.isSameClass("dataGroup")) continue;
if (this.isRecordGroup(node)) {
this.addRecordGroup(node);
continue;
}
this.populate(node);
}
}
void postLoad() {
if (this.mbDefined) {
// empty if block
}
}
public DataNode record(int recordOffset) {
this.validate(true);
if (recordOffset < 0 && - recordOffset > this.recordsBefore()) {
throw new ExFull(ResId.OutsideDataWindowException);
}
if (recordOffset > 0 && recordOffset > this.recordsAfter()) {
throw new ExFull(ResId.OutsideDataWindowException);
}
return this.mRecords.get(recordOffset + this.mnCurrentRecordIndex);
}
public int recordAbsIndex(int recordOffset) {
this.validate(true);
if (recordOffset < 0 && - recordOffset > this.recordsBefore()) {
throw new ExFull(ResId.OutsideDataWindowException);
}
if (recordOffset > 0 && recordOffset > this.recordsAfter()) {
throw new ExFull(ResId.OutsideDataWindowException);
}
return this.mRecordIndexes.get(recordOffset + this.mnCurrentRecordIndex);
}
public int recordsAfter() {
this.validate(true);
return this.mnRecordsAfter;
}
public int recordsBefore() {
this.validate(true);
return this.mnRecordsBefore;
}
public boolean removeRecordGroup(DataNode dataGroup) {
for (int i = 0; i < this.mRecords.size(); ++i) {
if (this.mRecords.get(i) != dataGroup) continue;
this.mRecords.remove(i);
this.mRecordIndexes.remove(i);
--this.mnAbsRecordIndex;
return true;
}
return false;
}
private void reset() {
this.mnCurrentRecordIndex = 0;
this.mnRecordsBefore = 0;
this.mnRecordsAfter = 0;
this.mbDefined = false;
if (this.mRecords.size() > 0) {
this.mnRecordsAfter = this.mRecords.size() - 1;
if (this.mnRecordsAfter > this.mnDesiredRecordsAfter) {
this.mnRecordsAfter = this.mnDesiredRecordsAfter;
}
this.mbDefined = true;
}
}
public void resetRecordDepth() {
this.mnRecordLevel = 0;
this.adjustRecordLevel(true);
this.mbUpToDate = false;
this.validate(false);
}
public void setScriptProperty(String sPropertyName, Arg propertyValue) {
throw new ExFull(ResId.UNSUPPORTED_OPERATION, "DataWindow#setScriptProperty");
}
void uninitialize() {
this.mnRecordLevel = 0;
this.mDataModel = null;
this.mStartNode = null;
}
public void updateAfterLoad() {
if (this.mbLazyLoading) {
int nLastRecord = this.mnDesiredRecordsAfter == Integer.MAX_VALUE ? Integer.MAX_VALUE : 1 + this.mnDesiredRecordsAfter;
this.loadToRecord(nLastRecord);
}
this.mbUpToDate = true;
this.reset();
}
private void validate(boolean bMustBeDefined) {
if (!this.mbUpToDate && this.mDataModel != null) {
this.invalidate();
this.populate((DataNode)this.mDataModel.getAliasNode());
this.reset();
this.mbUpToDate = true;
}
if (bMustBeDefined && !this.mbDefined) {
throw new ExFull(ResId.UndefinedDataWindowException);
}
}
}