PDFPortableCollection.java
12.4 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
/*
* 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.CosNumeric
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* 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.PDFParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASDate
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection;
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.CosNumeric;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
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.PDFParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASDate;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
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.graphics.xobject.PDFXObject;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionColors;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionFolder;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionItem;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionNavigator;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionResourcesTree;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionSchema;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionSort;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionSplit;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionUtil;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionView;
import java.util.ArrayList;
import java.util.Iterator;
public class PDFPortableCollection
extends PDFCosDictionary {
public static final ASName k_Collection = ASName.create((String)"Collection");
public static final ASName k_Schema = ASName.create((String)"Schema");
public static final ASName k_Sort = ASName.create((String)"Sort");
public static final ASName k_Split = ASName.create((String)"Split");
public static final ASName k_Colors = ASName.create((String)"Colors");
public static final ASName k_Navigator = ASName.create((String)"Navigator");
public static final ASName k_Folders = ASName.create((String)"Folders");
private PDFPortableCollection(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFPortableCollection getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFPortableCollection pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFPortableCollection.class);
if (pdfObject == null) {
pdfObject = new PDFPortableCollection(cosObject);
}
return pdfObject;
}
public static PDFPortableCollection newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary cosObject = PDFCosObject.newCosDictionary(pdfDocument);
PDFPortableCollection pdfObject = new PDFPortableCollection((CosObject)cosObject);
pdfObject.setDictionaryNameValue(ASName.k_Type, k_Collection);
return pdfObject;
}
public PDFCollectionSchema getSchema() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionSchema.getInstance((CosObject)this.getDictionaryDictionaryValue(k_Schema));
}
public void setSchema(PDFCollectionSchema schema) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (schema != null) {
this.setDictionaryValue(k_Schema, schema);
} else {
this.removeValue(k_Schema);
}
}
public PDFCollectionSchema procureSchema() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFCollectionSchema schema = this.getSchema();
if (schema == null) {
schema = PDFCollectionSchema.newInstance(this.getPDFDocument());
this.setSchema(schema);
}
return schema;
}
public PDFCollectionSort getSort() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionSort.getInstance((CosObject)this.getDictionaryDictionaryValue(k_Sort));
}
public void setSort(PDFCollectionSort sort) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (sort != null) {
this.setDictionaryValue(k_Sort, sort);
} else {
this.removeValue(k_Sort);
}
}
public PDFCollectionSort procureSort() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFCollectionSort sort = this.getSort();
if (sort == null) {
try {
sort = PDFCollectionSort.newInstance(this.getPDFDocument(), new ASName[1]);
}
catch (PDFInvalidParameterException e) {
throw new PDFInvalidDocumentException((Throwable)e);
}
this.setSort(sort);
}
return sort;
}
public PDFCollectionView getView() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionView.getInstance(this.getDictionaryNameValue(ASName.k_View));
}
public void setView(PDFCollectionView view) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (view == null) {
this.removeValue(ASName.k_View);
} else {
this.setDictionaryNameValue(ASName.k_View, view.getView());
}
}
public PDFCollectionSplit getSplit() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionSplit.getInstance((CosObject)this.getDictionaryDictionaryValue(k_Split));
}
public void setSplit(PDFCollectionSplit split) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (split == null) {
this.removeValue(k_Split);
} else {
this.setDictionaryValue(k_Split, split);
}
}
public PDFCollectionColors getColors() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionColors.getInstance((CosObject)this.getDictionaryDictionaryValue(k_Colors));
}
public void setColors(PDFCollectionColors colors) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (colors == null) {
this.removeValue(k_Colors);
} else {
this.setDictionaryValue(k_Colors, colors);
}
}
public PDFCollectionNavigator getNavigator() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionNavigator.getInstance((CosObject)this.getDictionaryDictionaryValue(k_Navigator));
}
public void setNavigator(PDFCollectionNavigator navigator) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (navigator == null) {
this.removeValue(k_Navigator);
} else {
this.setDictionaryValue(k_Navigator, navigator);
}
}
public PDFCollectionResourcesTree getResources() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCollectionResourcesTree.getInstance((CosObject)this.getDictionaryDictionaryValue(ASName.k_Resources));
}
public void setResources(PDFCollectionResourcesTree resources) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (resources == null) {
this.removeValue(ASName.k_Resources);
} else {
this.setDictionaryValue(ASName.k_Resources, resources);
}
}
public ASString getInitialDocumentName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryStringValue(ASName.k_D);
}
public void setInitialDocumentName(ASString name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (name != null) {
this.setDictionaryASStringValue(ASName.k_D, name);
} else {
this.removeValue(ASName.k_D);
}
}
public PDFCollectionFolder setRootFolder(String name, String desc, ASDate creationDate, ASDate modDate, PDFXObject thumb, PDFCollectionItem ci) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFCollectionFolder root = this.setRootFolder(name);
root.setDescription(desc);
root.setCreationDate(creationDate);
root.setModificationDate(modDate);
root.setThumb(thumb);
root.setCollectionItem(ci);
this.setDictionaryValue(k_Folders, root);
return root;
}
public PDFCollectionFolder setRootFolder(String name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (name == null) {
this.removeValue(k_Folders);
return null;
}
long newID = 0;
PDFCollectionFolder root = PDFCollectionFolder.newInstanceFolderRoot(this.getPDFDocument(), name, newID);
CosDocument cosDoc = this.getPDFDocument().getCosDocument();
ArrayList<CosNumeric> freeList = new ArrayList<CosNumeric>();
freeList.add(cosDoc.createCosNumeric(1));
freeList.add(cosDoc.createCosNumeric(Integer.MAX_VALUE));
CosArray newFreeObj = this.getPDFDocument().getCosDocument().createCosArray(freeList);
root.setFree(newFreeObj);
this.setDictionaryValue(k_Folders, root);
return root;
}
public PDFCollectionFolder getFolder(String[] path) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (path == null || path.length == 0) {
return this.getRootFolder();
}
if (this.dictionaryContains(k_Folders)) {
PDFCollectionFolder folder = this.getRootFolder();
for (int i = 0; i < path.length; ++i) {
ArrayList children = folder.getChildren();
Iterator iter = children.iterator();
boolean found = false;
while (iter.hasNext()) {
PDFCollectionFolder f = (PDFCollectionFolder)iter.next();
if (!f.getName().equals(path[i])) continue;
folder = f;
found = true;
break;
}
if (found) continue;
return null;
}
return folder;
}
return null;
}
public PDFCollectionFolder getRootFolder() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(k_Folders)) {
return PDFCollectionFolder.getInstance(this.getDictionaryValue(k_Folders));
}
return null;
}
public void removeRootFolder() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFParseException {
if (this.dictionaryContains(k_Folders)) {
PDFCollectionUtil.removePDFCollectionFolder(this.getRootFolder());
}
}
}