PDFFieldNode.java
28 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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosName
* com.adobe.internal.pdftoolkit.core.cos.CosNumeric
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.util.Utility
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.forms;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosName;
import com.adobe.internal.pdftoolkit.core.cos.CosNumeric;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.util.Utility;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosArrayList;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosUtils;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFText;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFAction;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFAdditionalActions;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFAdditionalActionsField;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFField;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldList;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldType;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldUtils;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFInteractiveForm;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFVariableText;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class PDFFieldNode
extends PDFCosDictionary {
public static final int kReadOnly = 1;
public static final int kRequire = 2;
public static final int kNoExport = 4;
static final ASName[] pureFieldKeys = new ASName[]{ASName.k_FT, ASName.k_Parent, ASName.k_Kids, ASName.k_T, ASName.k_TU, ASName.k_TM, ASName.k_Ff, ASName.k_V, ASName.k_DV, ASName.k_AA, ASName.k_DA, ASName.k_Q, ASName.k_DS, ASName.k_RV, ASName.k_Opt, ASName.k_MaxLen, ASName.k_TI, ASName.k_I, ASName.k_Lock, ASName.k_SV};
static final ASName[] pureFieldAndStructureKeys = new ASName[]{ASName.k_FT, ASName.k_Parent, ASName.k_Kids, ASName.k_T, ASName.k_TU, ASName.k_TM, ASName.k_Ff, ASName.k_V, ASName.k_DV, ASName.k_AA, ASName.k_DA, ASName.k_Q, ASName.k_DS, ASName.k_RV, ASName.k_Opt, ASName.k_MaxLen, ASName.k_TI, ASName.k_I, ASName.k_Lock, ASName.k_SV, ASName.k_StructParent, ASName.k_StructParents};
protected PDFFieldNode(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFFieldNode getInstance(CosObject cosObject) throws PDFCosParseException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFieldNode.getInstance(cosObject, false);
}
public static PDFFieldNode getInstance(CosObject cosObject, boolean useAcrobatIsTerminalCheck) throws PDFCosParseException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
CosDictionary cosDict = (CosDictionary)cosObject;
if (cosDict.containsKey((Object)ASName.k_Fields)) {
return PDFInteractiveForm.getInstance(cosObject);
}
if (PDFFieldUtils.isTerminalField(cosDict, useAcrobatIsTerminalCheck)) {
return PDFField.getInstance(cosObject);
}
PDFFieldNode pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFFieldNode.class);
if (pdfObject == null) {
pdfObject = new PDFFieldNode(cosObject);
}
return pdfObject;
}
public static PDFFieldNode newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary cosObject = PDFCosObject.newCosDictionary(pdfDocument);
return new PDFFieldNode((CosObject)cosObject);
}
public static PDFFieldNode newInstance(PDFFieldNode field) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode newField = PDFFieldNode.newInstance(field.getPDFDocument());
newField.resetFieldEntries(field);
return PDFFieldNode.getInstance(newField.getCosObject());
}
public PDFFieldType getFieldType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosName fieldType = (CosName)PDFCosUtils.getInheritableValue(ASName.k_FT, ASName.k_Parent, this);
return fieldType == null ? null : PDFFieldType.getInstance(fieldType.nameValue());
}
public String getPartialName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_T);
}
public boolean hasPartialName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_T);
}
public String getInheritedPartialName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode parent;
String partialName = this.getPartialName();
if (partialName == null && (parent = this.getParent()) != null && !(parent instanceof PDFInteractiveForm)) {
partialName = parent.getInheritedPartialName();
}
return partialName;
}
public void setPartialName(String partialName) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (partialName == null) {
this.removeValue(ASName.k_T);
} else {
this.setDictionaryStringValue(ASName.k_T, partialName);
}
}
public void setPartialName(String partialName, boolean useUnicodeEncoding) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (partialName == null) {
this.removeValue(ASName.k_T);
} else {
this.setDictionaryTextValue(ASName.k_T, PDFText.newInstance(this.getPDFDocument(), partialName, false, useUnicodeEncoding));
}
}
public String getQualifiedName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode parent = this.getParent();
if (parent == null || parent instanceof PDFInteractiveForm) {
return this.getPartialName();
}
String fullName = parent.getQualifiedName();
String partialName = this.getPartialName();
if (partialName != null) {
fullName = fullName + "." + partialName;
}
return fullName;
}
public String getQualifiedNameNoPartialName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode parent = this.getParent();
if (parent == null || parent instanceof PDFInteractiveForm) {
return this.getPartialName();
}
return parent.getQualifiedName();
}
public String getValueRichText() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode parent;
String richText = this.getDictionaryTextStringOrStreamValue(ASName.k_RV);
if (richText == null && this.isAcrobatAnnotation() && (parent = this.getParent()) != null) {
richText = parent.getDictionaryTextStringOrStreamValue(ASName.k_RV);
}
return richText;
}
public String getAlternateName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_TU);
}
public void setAlternateName(String name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_TU, name);
}
public String getMappingName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_TM);
}
public void setMappingName(String name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_TM, name);
}
public boolean hasFlags() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCosUtils.containsInheritableKey(ASName.k_Ff, ASName.k_Parent, this);
}
public int getFlags() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosNumeric value = (CosNumeric)PDFCosUtils.getInheritableValue(ASName.k_Ff, ASName.k_Parent, this);
return value == null ? 0 : value.numberValue().intValue();
}
public void setFlags(int flags) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_Ff, flags);
}
public boolean isReadOnly() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 1) != 0;
}
public void setReadOnly(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
this.setFlags(this.getFlags() | 1);
} else {
this.setFlags(this.getFlags() & -2);
}
}
public boolean isRequired() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 2) == 2;
}
public void setRequired(boolean reqd) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (reqd) {
this.setFlags(this.getFlags() | 2);
} else {
this.setFlags(this.getFlags() & -3);
}
}
private List getValueListImpl(ASName key) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosValue = PDFCosUtils.getInheritableValue(key, ASName.k_Parent, this);
if (cosValue == null) {
return null;
}
LinkedList<String> stringList = new LinkedList<String>();
if (cosValue.getType() == 3) {
stringList.add(((CosName)cosValue).nameValue().asString(true));
} else if (cosValue.getType() == 5) {
CosArray cosArray = (CosArray)cosValue;
for (int i = 0; i < cosArray.size(); ++i) {
PDFText text = PDFText.getInstance(cosArray.get(i));
stringList.add(text.stringValue());
}
} else if (cosValue.getType() == 6) {
stringList.add((String)cosValue);
} else {
PDFText text = PDFText.getInstance(cosValue);
stringList.add(text.stringValue());
}
return stringList;
}
public List getValueList() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getValueListImpl(ASName.k_V);
}
public List getDefaultValueList() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getValueListImpl(ASName.k_DV);
}
public void setDefaultStringValue(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.setDictionaryTextValue(ASName.k_DV, PDFText.newInstance(this.getPDFDocument(), value));
}
}
public void setRichText(PDFText richText) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.setDictionaryTextValue(ASName.k_RV, richText);
}
}
public void setStringValue(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.setDictionaryTextValue(ASName.k_V, value == null ? null : PDFText.newInstance(this.getPDFDocument(), value));
}
}
public void setTextValue(PDFText value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.setDictionaryTextValue(ASName.k_V, value);
}
}
public void removeValue() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosDictionary().remove(ASName.k_V);
}
public void setNameValue(ASName name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.setDictionaryNameValue(ASName.k_V, name);
}
}
public void setStringValue(String value, boolean isUTF16) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.setDictionaryStringOrStreamValue(ASName.k_V, value, isUTF16);
}
}
public void setListValue(List values) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
if (values == null || values.isEmpty()) {
return;
}
Iterator iterateValues = values.iterator();
CosArray stringArray = PDFCosObject.newCosArray(this.getPDFDocument());
while (iterateValues.hasNext()) {
Object nextValue = iterateValues.next();
if (nextValue instanceof String) {
stringArray.addText((String)nextValue);
continue;
}
if (nextValue instanceof PDFText) {
stringArray.add(((PDFText)nextValue).getCosObject());
continue;
}
throw new PDFInvalidParameterException("Bad value type in list");
}
if (!stringArray.isEmpty()) {
PDFFieldNode field = this;
if (this.isAcrobatAnnotation()) {
field = this.getParent();
}
if (field != null) {
field.getCosDictionary().put(ASName.k_V, (CosObject)stringArray);
}
}
}
public PDFVariableText getVariableText() throws PDFInvalidDocumentException {
return PDFVariableText.getInstance(this.getCosObject());
}
public PDFAdditionalActions getAdditionalActions() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFAdditionalActionsField.getInstance(PDFCosUtils.getInheritableValue(ASName.k_AA, ASName.k_Parent, this));
}
public PDFAdditionalActions procureAdditionalActions() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFAdditionalActionsField.getInstance(PDFCosUtils.getInheritableValue(ASName.k_AA, ASName.k_Parent, this)) != null) {
return PDFAdditionalActionsField.getInstance(PDFCosUtils.getInheritableValue(ASName.k_AA, ASName.k_Parent, this));
}
PDFAdditionalActionsField field = PDFAdditionalActionsField.newInstance(this.getPDFDocument());
this.setAdditionalActions(field);
return field;
}
public void setAdditionalActions(PDFAdditionalActions additionalActions) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_AA, additionalActions);
}
public void setActions(PDFAction actions) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_A, actions);
}
public boolean noExport() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 4) != 0;
}
public PDFFieldNode getParent() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosDictionary().containsKey((Object)ASName.k_Parent)) {
return PDFFieldNode.getInstance(this.getCosDictionary().get(ASName.k_Parent));
}
return null;
}
public void setParent(PDFFieldNode parent) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!(parent instanceof PDFInteractiveForm) && !(this instanceof PDFInteractiveForm)) {
this.setDictionaryValue(ASName.k_Parent, parent);
}
}
public PDFFieldList getChildren() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getChildren(false);
}
public PDFFieldList getChildren(boolean useAcrobatIsTerminalFieldCheck) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFieldList.getInstance(this.getDictionaryCosObjectValue(ASName.k_Kids), useAcrobatIsTerminalFieldCheck);
}
public void removeChildren() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.removeValue(ASName.k_Kids);
}
public void addChild(PDFFieldNode childNode) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldList kids = this.getChildren();
if (kids == null) {
kids = PDFFieldList.newInstance(this.getPDFDocument());
kids.add(childNode);
this.setDictionaryArrayValue(ASName.k_Kids, kids.getCosArray());
} else {
kids.add(childNode);
}
childNode.setParent(this);
}
public void removeChild(PDFFieldNode childNode) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFieldList kids = this.getChildren();
if (kids != null) {
kids.remove(childNode);
if (kids.isEmpty()) {
this.removeChildren();
}
}
}
public boolean isTerminalField() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return false;
}
public boolean isAnnotation() {
return false;
}
public boolean isAcrobatAnnotation() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return false;
}
private void resetFieldEntries(PDFFieldNode field) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
Iterator fieldIterator = field.getCosDictionary().keyIterator();
while (fieldIterator.hasNext()) {
ASName key = (ASName)fieldIterator.next();
if (!Utility.nameInArray((ASName)key, (ASName[])pureFieldKeys)) continue;
this.setDictionaryValue(key, field.getDictionaryCosObjectValue(key));
}
}
public void removeFieldEntries() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
for (int nameInd = 0; nameInd < pureFieldKeys.length; ++nameInd) {
ASName curName = pureFieldKeys[nameInd];
if (!this.dictionaryContains(curName)) continue;
this.getCosDictionary().remove(curName);
}
}
@Override
public String toString() {
String dictStr;
String str = dictStr = super.toString();
try {
str = this.getQualifiedName() + " " + dictStr;
}
catch (Exception e) {
throw new RuntimeException(e);
}
return str;
}
public PDFFieldNode getInheritableValueFieldNode(ASName key) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFieldNode.getInstance((CosObject)PDFCosUtils.getInheritableValueDictionary(key, ASName.k_Parent, this));
}
public Iterator<PDFField> iterator() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.iterator(false);
}
public Iterator<PDFField> iterator(boolean useAcrobatIsTerminalFieldCheck) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isTerminalField()) {
return new PDFFieldNodeIterator(this, null, useAcrobatIsTerminalFieldCheck);
}
return new PDFFieldNodeIterator(this, this.getChildren(useAcrobatIsTerminalFieldCheck), useAcrobatIsTerminalFieldCheck);
}
public Iterator<PDFField> iterator(PDFFieldType filter) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.iterator(new PDFFieldNodeFilter(filter, false), false);
}
public Iterator<PDFField> iterator(PDFFieldType filter, boolean useAcrobatIsTerminalFieldCheck) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.iterator(new PDFFieldNodeFilter(filter, useAcrobatIsTerminalFieldCheck), useAcrobatIsTerminalFieldCheck);
}
private Iterator<PDFField> iterator(PDFCosArrayList.PDFObjectFilter filter, boolean useAcrobatIsTerminalFieldCheck) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isTerminalField()) {
return new PDFFieldNodeIterator(this, null, filter, useAcrobatIsTerminalFieldCheck);
}
return new PDFFieldNodeIterator(this, this.getChildren(useAcrobatIsTerminalFieldCheck), filter, useAcrobatIsTerminalFieldCheck);
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
private class PDFFieldNodeIterator
implements Iterator<PDFField> {
private PDFFieldNode mKid;
private PDFField curField;
private PDFFieldNodeIterator mKidIterator;
private Iterator<PDFFieldNode> mKidsIterator;
private final PDFCosArrayList.PDFObjectFilter mFilter;
private final PDFFieldList kids;
private final boolean useAcrobatIsTerminalFieldCheck;
final /* synthetic */ PDFFieldNode this$0;
private PDFFieldNodeIterator(PDFFieldNode pDFFieldNode, PDFFieldList kids, boolean useAcrobatIsTerminalFieldCheck) {
this.this$0 = pDFFieldNode;
this.curField = null;
this.mFilter = null;
this.kids = kids;
this.useAcrobatIsTerminalFieldCheck = useAcrobatIsTerminalFieldCheck;
if (kids == null) {
return;
}
this.mKidsIterator = kids.iterator(useAcrobatIsTerminalFieldCheck);
}
private PDFFieldNodeIterator(PDFFieldNode pDFFieldNode, PDFFieldList kids, PDFCosArrayList.PDFObjectFilter filter, boolean useAcrobatIsTerminalFieldCheck) {
this.this$0 = pDFFieldNode;
this.curField = null;
this.mFilter = filter;
this.kids = kids;
this.useAcrobatIsTerminalFieldCheck = useAcrobatIsTerminalFieldCheck;
if (kids == null) {
return;
}
this.mKidsIterator = kids.iterator(filter, useAcrobatIsTerminalFieldCheck);
}
@Override
public boolean hasNext() {
if (this.curField == null) {
this.curField = this.fetchNextField();
}
return this.curField != null;
}
@Override
public PDFField next() {
if (this.curField == null) {
throw new NoSuchElementException("Error in PDFFieldNodeIterator next().");
}
PDFField nextField = this.curField;
this.curField = null;
return nextField;
}
@Override
public void remove() {
try {
if (this.mKidIterator == null) {
this.mKidsIterator.remove();
if (this.this$0.getChildren().size() == 0) {
this.this$0.removeChildren();
}
return;
}
this.mKidIterator.remove();
if (this.mKid.getChildren() == null) {
this.mKidsIterator.remove();
if (this.this$0.getChildren().size() == 0) {
this.this$0.removeChildren();
}
}
}
catch (PDFException e) {
IllegalStateException newException = new IllegalStateException("Error in PDFFieldNodeIterator remove().");
newException.initCause((Throwable)e);
throw newException;
}
}
private PDFField fetchNextField() {
if (this.mKidIterator == null) {
if (this.mKidsIterator == null) {
return null;
}
try {
this.kids.useAcrobatIsTerminalFieldCheck = this.useAcrobatIsTerminalFieldCheck;
PDFFieldNode pDFFieldNode = this.mKid = this.mKidsIterator.hasNext() ? this.mKidsIterator.next() : null;
if (this.mKid == null) {
return null;
}
if (this.mKid.isTerminalField()) {
return (PDFField)this.mKid;
}
this.mKidIterator = this.mFilter == null ? (PDFFieldNodeIterator)this.mKid.iterator(this.useAcrobatIsTerminalFieldCheck) : (PDFFieldNodeIterator)this.mKid.iterator(this.mFilter, this.useAcrobatIsTerminalFieldCheck);
}
catch (PDFException e) {
NoSuchElementException newException = new NoSuchElementException("Error in PDFFieldNodeIterator next().");
newException.initCause((Throwable)e);
throw newException;
}
}
this.curField = this.mKidIterator.fetchNextField();
if (this.curField == null) {
this.mKidIterator = null;
this.curField = this.fetchNextField();
}
return this.curField;
}
}
private static class PDFFieldNodeFilter
implements PDFCosArrayList.PDFObjectFilter {
private final PDFField.PDFFieldFilter fieldFilter;
private final boolean useAcrobatIsTerminalFieldCheck;
private PDFFieldNodeFilter(PDFFieldType type, boolean useAcrobatIsTerminalFieldCheck) {
this.fieldFilter = new PDFField.PDFFieldFilter(type);
this.useAcrobatIsTerminalFieldCheck = useAcrobatIsTerminalFieldCheck;
}
public boolean accept(CosObject obj) throws PDFCosParseException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary cosDict = (CosDictionary)obj;
if (cosDict.containsKey((Object)ASName.k_Fields)) {
return false;
}
if (!PDFFieldUtils.isTerminalField(cosDict, this.useAcrobatIsTerminalFieldCheck)) {
return true;
}
return this.fieldFilter.accept(obj);
}
}
}