PDFFileSpecification.java
13.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.cos.CosStream
* com.adobe.internal.pdftoolkit.core.cos.CosString
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* 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
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.document;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
import com.adobe.internal.pdftoolkit.core.cos.CosString;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
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.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFEmbeddedFile;
import com.adobe.internal.pdftoolkit.pdf.document.PDFText;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFThumbnailImage;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObject;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObjectFactory;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.collection.PDFCollectionItem;
public class PDFFileSpecification
extends PDFCosObject {
public static final ASName k_CI = ASName.create((String)"CI");
public static final ASName k_UF = ASName.create((String)"UF");
private PDFFileSpecification(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFFileSpecification getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFFileSpecification pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFFileSpecification.class);
if (pdfObject == null) {
pdfObject = new PDFFileSpecification(cosObject);
}
return pdfObject;
}
public static PDFFileSpecification newSkeletonInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary dict = PDFCosObject.newCosDictionary(pdfDocument);
dict.put(ASName.k_Type, ASName.k_Filespec);
return new PDFFileSpecification((CosObject)dict);
}
public static PDFFileSpecification newInstance(PDFDocument pdfDocument, byte[] filename) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFileSpecification.newInstance(pdfDocument, new ASString(filename), null);
}
public static PDFFileSpecification newInstance(PDFDocument pdfDocument, byte[] filename, PDFEmbeddedFile pdfEmbeddedFile) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFileSpecification.newInstance(pdfDocument, new ASString(filename), pdfEmbeddedFile);
}
public static PDFFileSpecification newInstance(PDFDocument pdfDocument, ASString filename, PDFEmbeddedFile pdfEmbeddedFile) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFileSpecification pdfFS = PDFFileSpecification.newSkeletonInstance(pdfDocument);
pdfFS.setFileName(filename);
pdfFS.setEmbeddedFile(pdfEmbeddedFile);
return pdfFS;
}
public ASName getFSType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).getName(ASName.k_FS);
}
return null;
}
public void setFSType(ASName fsType) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
((CosDictionary)this.getCosObject()).put(ASName.k_FS, fsType);
}
public boolean hasFilename() {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).containsKey((Object)ASName.k_F);
}
return true;
}
public ASString getFilename() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).getString(ASName.k_F);
}
return ((CosString)this.getCosObject()).stringValue();
}
public void setFileName(ASString name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
((CosDictionary)this.getCosObject()).put(ASName.k_F, name);
}
public void setFileName(byte[] name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
((CosDictionary)this.getCosObject()).put(ASName.k_F, new ASString(name));
}
public String getUnicodeName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
CosObject nameDict = ((CosDictionary)this.getCosObject()).get(k_UF);
if (nameDict == null) {
return null;
}
PDFText textName = PDFText.getInstance(nameDict);
return textName.stringValue();
}
return null;
}
public void setUnicodeName(String fileName) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFText name = PDFText.createString(this.getPDFDocument(), fileName);
((CosDictionary)this.getCosObject()).put(k_UF, name.getCosObject());
}
public ASString getDOSFilename() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).getString(ASName.k_DOS);
}
return null;
}
public void setDOSFileName(byte[] name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
((CosDictionary)this.getCosObject()).put(ASName.k_DOS, new ASString(name));
}
public ASString getUnixFilename() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).getString(ASName.k_Unix);
}
return null;
}
public void setUnixFileName(byte[] name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
((CosDictionary)this.getCosObject()).put(ASName.k_Unix, new ASString(name));
}
public ASString getMacFilename() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).getString(ASName.k_Mac);
}
return null;
}
public void setMacFileName(byte[] name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
((CosDictionary)this.getCosObject()).put(ASName.k_Mac, new ASString(name));
}
public boolean hasThumbnail() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
return ((CosDictionary)this.getCosObject()).containsKey((Object)ASName.k_Thumb);
}
return false;
}
public PDFXObject getThumbnail() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary thumb;
if (this.isDictionaryFS() && (thumb = ((CosDictionary)this.getCosObject()).getCosDictionary(ASName.k_Thumb)) != null) {
return PDFXObjectFactory.getInstance((CosObject)thumb);
}
return null;
}
public void setThumbnail(PDFXObject xObj) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
if (xObj == null) {
((CosDictionary)this.getCosObject()).remove(ASName.k_Thumb);
} else {
CosObject thumb = xObj.getCosObject();
((CosDictionary)this.getCosObject()).put(ASName.k_Thumb, thumb);
}
}
}
public boolean hasEmbeddedFile() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
CosDictionary efDict = ((CosDictionary)this.getCosObject()).getCosDictionary(ASName.k_EF);
return efDict != null ? efDict.containsKey((Object)ASName.k_F) : false;
}
return false;
}
public PDFEmbeddedFile getEmbeddedFile() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary efDict;
if (this.isDictionaryFS() && (efDict = ((CosDictionary)this.getCosObject()).getCosDictionary(ASName.k_EF)) != null) {
return PDFEmbeddedFile.getInstance(efDict.get(ASName.k_F));
}
return null;
}
public PDFEmbeddedFile procureEmbeddedFile() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
if (this.hasEmbeddedFile()) {
return this.getEmbeddedFile();
}
return PDFEmbeddedFile.newInstance(this.getPDFDocument());
}
public void setEmbeddedFile(PDFEmbeddedFile embeddedFile) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
if (embeddedFile != null) {
CosDictionary efDict = ((CosDictionary)this.getCosObject()).getCosDictionary(ASName.k_EF);
if (efDict == null) {
efDict = PDFCosObject.newCosDictionary(this.getPDFDocument());
}
efDict.put(ASName.k_F, embeddedFile.getCosObject());
((CosDictionary)this.getCosObject()).put(ASName.k_EF, (CosObject)efDict);
}
}
public PDFCollectionItem getCollectionItem() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS()) {
CosDictionary ciDict = ((CosDictionary)this.getCosObject()).getCosDictionary(k_CI);
return PDFCollectionItem.getInstance((CosObject)ciDict);
}
return null;
}
public void setCollectionItem(PDFCollectionItem colItem) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.isDictionaryFS() && colItem != null) {
this.ensureFSIsDictionary();
}
if (this.isDictionaryFS()) {
if (colItem == null) {
((CosDictionary)this.getCosObject()).remove(k_CI);
} else {
((CosDictionary)this.getCosObject()).put(k_CI, colItem.getCosObject());
}
}
}
private boolean isDictionaryFS() {
return this.getCosObject() instanceof CosDictionary;
}
private void ensureFSIsDictionary() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosObj = this.getCosObject();
if (cosObj instanceof CosString) {
CosDictionary cosFS = PDFCosObject.newCosDictionary(this.getPDFDocument());
cosFS.put(ASName.k_Type, ASName.k_Filespec);
this.replaceCosObject((CosObject)cosFS);
cosFS.put(ASName.k_F, cosObj);
}
}
public void setDescription(String description) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.ensureFSIsDictionary();
PDFText textValue = PDFText.newInstance(this.getPDFDocument(), description);
((CosDictionary)this.getCosObject()).put(ASName.k_Desc, textValue.getCosObject());
}
public String getDescription() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFText textValue;
if (this.isDictionaryFS() && (textValue = PDFText.getInstance(((CosDictionary)this.getCosObject()).get(ASName.k_Desc))) != null) {
return textValue.stringValue();
}
return null;
}
public PDFThumbnailImage getThumbnailStream() throws PDFCosParseException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFThumbnailImage.getInstance((CosObject)((CosDictionary)this.getCosObject()).getCosStream(ASName.k_Thumb));
}
public void setThumbnailStream(PDFThumbnailImage thumbnailStream) throws PDFCosParseException, PDFIOException, PDFSecurityException {
((CosDictionary)this.getCosObject()).put(ASName.k_Thumb, thumbnailStream.getCosObject());
}
public ASName getAFRelationship() throws PDFCosParseException, PDFIOException, PDFSecurityException {
ASName name = ((CosDictionary)this.getCosObject()).getName(ASName.k_AFRelationship);
if (name != null) {
return name;
}
return ASName.k_Source;
}
public void setAFRelationship(ASName name) throws PDFCosParseException, PDFIOException, PDFSecurityException {
((CosDictionary)this.getCosObject()).put(ASName.k_AFRelationship, name);
}
}