PDFMetaDataInfo.java
10.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
/*
* 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.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.ASDate
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
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.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.ASDate;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.XMLNameValidator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class PDFMetaDataInfo
extends PDFCosDictionary {
private static final char COLON = ':';
protected PDFMetaDataInfo(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public String getAuthor() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_Author);
}
public void setAuthor(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_Author, value);
}
public String getCreator() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_Creator);
}
public void setCreator(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_Creator, value);
}
public ASDate getCreationDate() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryDateValue(ASName.k_CreationDate);
}
public void setCreationDate(ASDate dateCreated) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (dateCreated == null) {
this.removeValue(ASName.k_CreationDate);
} else {
this.setDictionaryStringValue(ASName.k_CreationDate, dateCreated.asString());
}
}
public String getKeywords() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_Keywords);
}
public void setKeywords(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_Keywords, value);
}
public ASDate getModificationDate() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryDateValue(ASName.k_ModDate);
}
public void setModificationDate(ASDate dateModified) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (dateModified == null) {
this.removeValue(ASName.k_ModDate);
} else {
this.setDictionaryStringValue(ASName.k_ModDate, dateModified.asString());
}
}
public String getProducer() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_Producer);
}
public void setProducer(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_Producer, value);
}
public String getSubject() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_Subject);
}
public void setSubject(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_Subject, value);
}
public String getTitle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_Title);
}
public void setTitle(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_Title, value);
}
public String getTrapped() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValueAsString(ASName.k_Trapped);
}
public void setTrapped(String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_Trapped, value);
}
public List<String[]> getCustomProperties() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ArrayList<String[]> custProps = new ArrayList<String[]>();
try {
CosDictionary dict = this.getCosDictionary();
List dictKeys = dict.getKeys();
for (int idx = 0; idx < dictKeys.size(); ++idx) {
String keyString;
ASName key = (ASName)dictKeys.get(idx);
if (!this.isCustomProperty(key)) continue;
String[] property = new String[2];
CosObject value = dict.get(key);
if (!(value instanceof CosString) || (keyString = key.asString(true)) == null || keyString.length() == 0) continue;
property[0] = this.escapeCustomProperty(keyString);
property[1] = ((CosString)value).asString();
custProps.add(property);
}
}
catch (PDFCosParseException e) {
throw new PDFInvalidDocumentException("Cannot get Custom Properties.", (Throwable)e);
}
return custProps;
}
private String escapeCustomProperty(String propName) {
StringBuilder ret = new StringBuilder();
if (XMLNameValidator.isWellFormedXMLName(propName) && propName.indexOf(58) == -1) {
return propName;
}
char ch = propName.charAt(0);
if (!XMLNameValidator.isNameStartChar(ch) || ch == ':') {
ret.append(this.escapeCharacterCode(ch));
} else {
ret.append(ch);
}
for (int i = 1; i < propName.length(); ++i) {
ch = propName.charAt(i);
if (!XMLNameValidator.isNameChar(ch) || ch == ':') {
ret.append(this.escapeCharacterCode(ch));
continue;
}
ret.append(ch);
}
return ret.toString();
}
private String escapeCharacterCode(char ch) {
StringBuilder ret = new StringBuilder();
ret.append('\u2182');
String uniValue = Integer.toHexString(ch);
if (uniValue.length() == 1) {
ret.append("000");
}
if (uniValue.length() == 2) {
ret.append("00");
}
if (uniValue.length() == 3) {
ret.append("0");
}
ret.append(uniValue);
return ret.toString();
}
public void setCustomProperties(List properties) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
try {
if (properties == null) {
CosDictionary dict = this.getCosDictionary();
List dictKeys = dict.getKeys();
for (int idx = 0; idx < dictKeys.size(); ++idx) {
ASName key = (ASName)dictKeys.get(idx);
if (!this.isCustomProperty(key)) continue;
this.removeValue(key);
}
} else {
for (int idx = 0; idx < properties.size(); ++idx) {
String key = ((String[])properties.get(idx))[0];
this.setDictionaryStringOrStreamValue(ASName.create((String)key), ((String[])properties.get(idx))[1]);
}
}
}
catch (PDFInvalidDocumentException e) {
throw new PDFInvalidDocumentException("Cannot set Custom Properties", (Throwable)e);
}
}
public void setCustomProperties(List<String[]> properties, HashMap<String, String> oldDocInfoPropMap) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
try {
if (properties == null) {
CosDictionary dict = this.getCosDictionary();
List dictKeys = dict.getKeys();
for (int idx = 0; idx < dictKeys.size(); ++idx) {
ASName key = (ASName)dictKeys.get(idx);
if (!this.isCustomProperty(key)) continue;
this.removeValue(key);
}
} else {
if (oldDocInfoPropMap != null) {
for (Map.Entry<String, String> entry : oldDocInfoPropMap.entrySet()) {
this.removeValue(ASName.create((String)entry.getKey()));
}
}
for (int idx = 0; idx < properties.size(); ++idx) {
String[] prop = properties.get(idx);
String key = prop[0];
String value = prop[1];
this.setDictionaryStringOrStreamValue(ASName.create((String)key), value);
}
}
}
catch (PDFInvalidDocumentException e) {
throw new PDFInvalidDocumentException("Cannot set Custom Properties", (Throwable)e);
}
}
private boolean isCustomProperty(ASName name) {
return !name.equals((Object)ASName.k_Title) && !name.equals((Object)ASName.k_Author) && !name.equals((Object)ASName.k_Subject) && !name.equals((Object)ASName.k_Keywords) && !name.equals((Object)ASName.k_Creator) && !name.equals((Object)ASName.k_Producer) && !name.equals((Object)ASName.k_CreationDate) && !name.equals((Object)ASName.k_ModDate) && !name.equals((Object)ASName.k_Trapped);
}
}