PDFAction.java
7.59 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
/*
* 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.CosDocument
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* 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.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.action;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosDocument;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
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.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFActionFactory;
import java.util.LinkedList;
import java.util.NoSuchElementException;
public abstract class PDFAction
extends PDFCosDictionary {
protected PDFAction(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
protected PDFAction(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super((CosObject)PDFCosObject.newCosDictionary(pdfDocument));
this.setType(ASName.k_Action);
}
public ASName getSubtype() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_S);
}
protected void setSubtype(ASName asName) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_S, asName);
}
private void setType(ASName value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_Type, value);
}
public ASName getType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Type);
}
ArrayIterator arrayIterator() {
return new ArrayIterator((CosObject)this.getCosDictionary());
}
public ArrayIterator nextArrayIterator() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return new ArrayIterator(this.getDictionaryValue(ASName.k_Next));
}
public TreeIterator treeIterator() {
return new TreeIterator(this.arrayIterator());
}
public TreeIterator nextTreeIterator() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return new TreeIterator(this.nextArrayIterator());
}
public boolean hasNext() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Next);
}
public void setNext(PDFAction action) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Next, action);
}
public boolean isValid() {
boolean isValid = false;
CosObject cosObj = this.getCosObject();
int cosType = cosObj.getType();
isValid = cosType == 5 || cosType == 3 || cosType == 4 || cosType == 6 && ((CosDictionary)cosObj).containsKey((Object)ASName.k_S);
return isValid;
}
public static void addNextAction(PDFAction main, PDFAction next) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (main.hasNext()) {
CosObject cosObj = main.getDictionaryCosObjectValue(ASName.k_Next);
CosArray array = null;
if (cosObj instanceof CosArray) {
array = (CosArray)cosObj;
array.add(next.getCosObject());
} else if (cosObj instanceof CosDictionary) {
array = main.getPDFDocument().getCosDocument().createCosArray();
array.add(cosObj);
} else {
throw new PDFInvalidDocumentException("/Next entry in action should either be an array or dictionary");
}
main.setDictionaryValue(ASName.k_Next, (CosObject)array);
} else {
main.setNext(next);
}
}
public final class TreeIterator {
private final LinkedList ll;
private ArrayIterator currentArrayIter;
private PDFAction nextAction;
private PDFAction prevAction;
protected TreeIterator(ArrayIterator arrayIter) {
this.ll = new LinkedList();
this.currentArrayIter = arrayIter;
this.ll.add(arrayIter);
}
public boolean hasNext() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.nextAction == null) {
if (this.prevAction != null) {
this.currentArrayIter = this.prevAction.nextArrayIterator();
this.ll.add(this.currentArrayIter);
this.prevAction = null;
}
while (this.currentArrayIter != null && !this.currentArrayIter.hasNext()) {
this.ll.removeLast();
if (!this.ll.isEmpty()) {
this.currentArrayIter = (ArrayIterator)this.ll.getLast();
continue;
}
this.currentArrayIter = null;
}
if (this.currentArrayIter != null && this.currentArrayIter.hasNext()) {
this.nextAction = this.currentArrayIter.next();
}
}
return this.nextAction != null;
}
public PDFAction next() {
if (this.nextAction == null) {
throw new NoSuchElementException();
}
this.prevAction = this.nextAction;
this.nextAction = null;
return this.prevAction;
}
}
public final class ArrayIterator {
private final CosObject dictOrArray;
private int index;
private int size;
protected ArrayIterator(CosObject dictOrArray) {
this.dictOrArray = dictOrArray;
this.size = dictOrArray == null ? 0 : (dictOrArray instanceof CosDictionary ? 1 : ((CosArray)dictOrArray).size());
}
public boolean hasNext() {
return this.index < this.size;
}
public PDFAction next() {
if (!this.hasNext()) {
throw new NoSuchElementException();
}
try {
PDFAction action = this.dictOrArray instanceof CosDictionary ? PDFActionFactory.getInstance(this.dictOrArray) : PDFActionFactory.getInstance(((CosArray)this.dictOrArray).get(this.index));
++this.index;
return action;
}
catch (PDFException e) {
NoSuchElementException newException = new NoSuchElementException("PDF error inside PDFAction.Iterator.next()");
newException.initCause((Throwable)e);
throw newException;
}
}
}
}