PDFCosDictionaryMap.java
13.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator
* com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator$Entry
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* 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.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFRuntimeException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionaryMap.AbstractEntryValuesSet
*/
package com.adobe.internal.pdftoolkit.pdf.document;
import com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
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.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFRuntimeException;
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.PDFCosObjectContainer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class PDFCosDictionaryMap<V extends PDFCosObjectContainer>
extends PDFCosDictionary
implements Map<ASName, V> {
protected PDFCosDictionaryMap(CosObject cosDict) throws PDFInvalidDocumentException {
super(cosDict);
}
protected abstract V itemInstantiator(CosObject var1) throws PDFCosParseException, PDFIOException, PDFInvalidDocumentException, PDFSecurityException, PDFInvalidParameterException;
@Override
public int size() {
return this.getCosDictionary().size();
}
@Override
public void clear() {
try {
this.getCosDictionary().clear();
}
catch (PDFException e) {
// empty catch block
}
}
@Override
public boolean isEmpty() {
return this.getCosDictionary().isEmpty();
}
@Override
public boolean containsKey(Object key) {
if (key == null) {
throw new IllegalArgumentException("PDFCosDictionaryMap:containsKey Key cannot be null");
}
return this.getCosDictionary().containsKey(key);
}
private ASName getKeyForValue(Object value, String method) {
try {
if (value == null) {
throw new IllegalArgumentException(method + ": value cannot be null");
}
if (value instanceof CosObject) {
return this.getCosDictionary().getKeyForValue((CosObject)value);
}
if (value instanceof PDFCosObject) {
return this.getCosDictionary().getKeyForValue(((PDFCosObject)value).getCosObject());
}
throw new ClassCastException(method + ": value is not of CosObject or PDFCosObject");
}
catch (PDFException e) {
return null;
}
}
@Override
public boolean containsValue(Object value) {
return this.getKeyForValue(value, "PDFCosDictionaryMap.containsValue") != null;
}
@Override
public Collection values() {
return new AbstractEntryValuesSet(){
private Set entrySet;
public void clear() {
this.entrySet.clear();
}
public boolean contains(Object o) {
return PDFCosDictionaryMap.this.containsValue(o);
}
public boolean isEmpty() {
return this.entrySet.isEmpty();
}
public Iterator iterator() {
final Iterator it = this.entrySet.iterator();
return new Iterator(){
public boolean hasNext() {
return it.hasNext();
}
public Object next() {
return ((PDFCosDictMapEntry)it.next()).getValue();
}
public void remove() {
it.remove();
}
};
}
public boolean remove(Object o) {
ASName key = PDFCosDictionaryMap.this.getKeyForValue(o, "PDFCosDictionaryMap.ValueSet.remove");
if (key != null) {
try {
return PDFCosDictionaryMap.this.getCosDictionary().remove(key) != null;
}
catch (PDFException e) {
// empty catch block
}
}
return false;
}
public int size() {
return this.entrySet.size();
}
};
}
@Override
public void putAll(Map<? extends ASName, ? extends V> t) {
for (Map.Entry<ASName, V> entry : t.entrySet()) {
this.put(entry.getKey(), (PDFCosObjectContainer)entry.getValue());
}
}
@Override
public Set entrySet() {
return new com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionaryMap.AbstractEntryValuesSet<PDFCosDictionaryMap<V>>(){
public void clear() {
try {
PDFCosDictionaryMap.this.getCosDictionary().clear();
}
catch (PDFException e) {
// empty catch block
}
}
public boolean contains(Object o) {
if (o instanceof PDFCosDictMapEntry) {
return PDFCosDictionaryMap.this.getCosDictionary().containsKey((Object)((PDFCosDictMapEntry)o).getKey());
}
return false;
}
public boolean isEmpty() {
return PDFCosDictionaryMap.this.getCosDictionary().isEmpty();
}
public Iterator<PDFCosDictionaryMap<V>> iterator() {
return new Iterator<PDFCosDictionaryMap<V>>(){
private CosContainerValuesIterator it;
@Override
public boolean hasNext() {
return this.it.hasNext();
}
@Override
public PDFCosDictionaryMap<V> next() {
try {
return new PDFCosDictMapEntry(this.it.next());
}
catch (PDFException e) {
NoSuchElementException e1 = new NoSuchElementException();
e1.initCause((Throwable)e);
throw e1;
}
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported");
}
};
}
public boolean remove(Object o) {
if (o instanceof PDFCosDictMapEntry) {
try {
return PDFCosDictionaryMap.this.getCosDictionary().remove(((PDFCosDictMapEntry)o).getKey()) != null;
}
catch (PDFException e) {
// empty catch block
}
}
return false;
}
public int size() {
return PDFCosDictionaryMap.this.getCosDictionary().size();
}
};
}
@Override
public Set<ASName> keySet() {
return this.getCosDictionary().keySet();
}
@Override
public V get(Object key) {
try {
if (key == null) {
throw new IllegalArgumentException("PDFCosDictionaryMap.get: key cannot be null");
}
if (key instanceof ASName) {
CosObject cosObj = this.getCosDictionary().get((ASName)key);
return this.itemInstantiator(cosObj);
}
throw new ClassCastException("PDFCosDictionaryMap.get: key is not of type ASName");
}
catch (PDFException e) {
throw new PDFRuntimeException(e);
}
}
@Override
public V remove(Object key) {
try {
if (key == null) {
throw new IllegalArgumentException("PDFCosDictionaryMap.remove: key cannot be null");
}
if (key instanceof ASName) {
return this.itemInstantiator(this.getCosDictionary().remove((ASName)key));
}
throw new ClassCastException("PDFCosDictionaryMap.remove: key is not of type ASName");
}
catch (PDFException e) {
return null;
}
}
@Override
public V put(ASName key, V value) {
if (key == null || value == null) {
throw new IllegalArgumentException("PDFCosDictionaryMap.put: key or value cannot be null");
}
try {
Object retVal = null;
if (this.containsKey(key)) {
retVal = this.get((Object)key);
}
this.setDictionaryValue(key, value.getPDFCosObject());
return (V)retVal;
}
catch (PDFException e) {
throw new IllegalArgumentException("PDFCosDictionaryMap.put: Unable to put key:" + (Object)key + "/value:" + value + " into the map", (Throwable)e);
}
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
protected class PDFCosDictMapEntry
implements Map.Entry<ASName, V> {
private final CosContainerValuesIterator.Entry entry;
protected PDFCosDictMapEntry(CosContainerValuesIterator.Entry cosEntry) {
this.entry = cosEntry;
}
@Override
public ASName getKey() {
return this.entry.getKey();
}
@Override
public V getValue() {
try {
return PDFCosDictionaryMap.this.itemInstantiator(this.entry.getValue());
}
catch (PDFException e) {
return null;
}
}
@Override
public boolean equals(Object o) {
if (o instanceof PDFCosDictMapEntry) {
return ((PDFCosDictMapEntry)o).getKey() == this.getKey() && ((PDFCosDictMapEntry)o).getValue() == this.getValue();
}
return false;
}
@Override
public V setValue(V value) {
return PDFCosDictionaryMap.this.put(this.entry.getKey(), value);
}
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
private abstract class AbstractEntryValuesSet<T>
implements Set<T> {
private AbstractEntryValuesSet() {
}
@Override
public boolean add(T o) {
throw new UnsupportedOperationException("Value/Entry Sets of Maps do not have this supported");
}
@Override
public boolean addAll(Collection o) {
throw new UnsupportedOperationException("Value/Entry Sets of Maps do not have this supported");
}
@Override
public boolean containsAll(Collection coll) {
for (Object o : coll) {
if (this.contains(o)) continue;
return false;
}
return true;
}
@Override
public boolean removeAll(Collection coll) {
boolean retVal = false;
for (Object o : coll) {
retVal |= this.remove(o);
}
return retVal;
}
@Override
public boolean retainAll(Collection coll) {
boolean retVal = false;
ArrayList toBeRemovedItems = new ArrayList();
for (Object entry : this) {
if (coll.contains(entry)) continue;
toBeRemovedItems.add(entry);
}
for (Object item : toBeRemovedItems) {
retVal |= this.remove(item);
}
return retVal;
}
@Override
public Object[] toArray() {
Object[] objects = new Object[this.size()];
return this.toArray(objects);
}
@Override
public Object[] toArray(Object[] objects) {
if (objects.length < this.size()) {
objects = (Object[])Array.newInstance(objects.getClass().getComponentType(), this.size());
}
int i = 0;
for (Object objects[i++] : this) {
}
return objects;
}
}
}