PDFEmbeddedTarget.java
8.66 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
/*
* 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.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.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.action;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
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.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCatalog;
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.document.PDFNameDictionary;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.PDFDestination;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.PDFNamedDestinations;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPage;
public class PDFEmbeddedTarget
extends PDFCosDictionary {
private PDFEmbeddedTarget(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
private PDFEmbeddedTarget(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super((CosObject)PDFCosObject.newCosDictionary(pdfDocument));
this.setRelationship(ASName.k_P);
}
public static PDFEmbeddedTarget getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFEmbeddedTarget pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFEmbeddedTarget.class);
if (pdfObject == null) {
pdfObject = new PDFEmbeddedTarget(cosObject);
}
return pdfObject;
}
public static PDFEmbeddedTarget newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFEmbeddedTarget pdfObject = new PDFEmbeddedTarget(pdfDocument);
return pdfObject;
}
public static PDFEmbeddedTarget newInstance(PDFDocument pdfDocument, ASString embeddedFileName) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
CosDictionary targetObj = PDFCosObject.newCosDictionary(pdfDocument);
targetObj.put(ASName.k_R, ASName.k_C);
if (embeddedFileName == null) {
throw new PDFInvalidParameterException("Embedded file name is required.");
}
targetObj.put(ASName.k_N, embeddedFileName);
PDFEmbeddedTarget target = PDFEmbeddedTarget.getInstance((CosObject)targetObj);
return target;
}
public static PDFEmbeddedTarget newInstance(PDFDocument pdfDocument, Object fileAttachAnnotPage, Object fileAttachAnnotLocation) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
CosDictionary targetObj = PDFCosObject.newCosDictionary(pdfDocument);
targetObj.put(ASName.k_R, ASName.k_C);
PDFEmbeddedTarget target = PDFEmbeddedTarget.getInstance((CosObject)targetObj);
if (fileAttachAnnotPage != null && (fileAttachAnnotPage instanceof Integer || fileAttachAnnotPage instanceof ASString)) {
if (fileAttachAnnotPage instanceof Integer) {
targetObj.put(ASName.k_P, ((Integer)fileAttachAnnotPage).intValue());
} else {
target.setDictionaryASStringValue(ASName.k_P, (ASString)fileAttachAnnotPage);
}
} else {
throw new PDFInvalidParameterException("File attachment annot page is required.");
}
if (fileAttachAnnotLocation != null && (fileAttachAnnotLocation instanceof Integer || fileAttachAnnotLocation instanceof String)) {
if (fileAttachAnnotLocation instanceof Integer) {
targetObj.put(ASName.k_A, ((Integer)fileAttachAnnotPage).intValue());
} else {
target.setDictionaryStringValue(ASName.k_A, (String)fileAttachAnnotPage);
}
} else {
throw new PDFInvalidParameterException("File attachment annot location is required.");
}
return target;
}
public ASName getRelationship() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_R);
}
public void setRelationship(ASName r) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_R, r);
}
public int getPageIndex() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.dictionaryContains(ASName.k_P)) {
return -1;
}
CosObject cosObj = this.getDictionaryCosObjectValue(ASName.k_P);
if (cosObj.getType() == 1) {
return this.getDictionaryIntValue(ASName.k_P);
}
if (cosObj.getType() == 4) {
ASString name = this.getDictionaryStringValue(ASName.k_P);
PDFNameDictionary nameDict = this.getPDFDocument().requireCatalog().getNameDictionary();
if (nameDict == null) {
return -1;
}
PDFNamedDestinations namedDests = nameDict.getNamedDestinations();
if (namedDests == null) {
return -1;
}
PDFDestination dest = (PDFDestination)namedDests.getEntry(name);
if (dest == null) {
return -1;
}
PDFPage page = dest.getPage();
if (page == null) {
return -1;
}
return page.getIndex();
}
return -1;
}
public void setPageIndex(int index) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_P, index);
}
public int getAnnotationIndex() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.dictionaryContains(ASName.k_A)) {
return -1;
}
CosObject cosObj = this.getDictionaryCosObjectValue(ASName.k_A);
if (cosObj.getType() == 1) {
return this.getDictionaryIntValue(ASName.k_A);
}
return -1;
}
public void setAnnotationIndex(int index) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_A, index);
}
public String getAnnotationName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.dictionaryContains(ASName.k_A)) {
return null;
}
CosObject cosObj = this.getDictionaryCosObjectValue(ASName.k_A);
if (cosObj.getType() == 4) {
return this.getDictionaryTextStringValue(ASName.k_A);
}
return null;
}
public void setAnnotationName(String annotName) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_A, annotName);
}
public ASString getName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.dictionaryContains(ASName.k_N)) {
return null;
}
return this.getDictionaryStringValue(ASName.k_N);
}
public void setName(ASString name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryASStringValue(ASName.k_N, name);
}
public PDFEmbeddedTarget getEmbeddedTarget() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.dictionaryContains(ASName.k_T)) {
return null;
}
return PDFEmbeddedTarget.getInstance(this.getDictionaryCosObjectValue(ASName.k_T));
}
public void setEmbeddedTarget(PDFEmbeddedTarget target) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_T, target);
}
}