PDFOCGroupList.java
5.91 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
/*
* 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.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
*/
package com.adobe.internal.pdftoolkit.pdf.graphics.optionalcontent;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
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.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.optionalcontent.PDFOCGroup;
import com.adobe.internal.pdftoolkit.pdf.graphics.optionalcontent.PDFOCGroupArray;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class PDFOCGroupList
extends PDFCosObject {
private static final int ARRAY = 1;
private static final int DICTIONARY = 2;
private final int mType;
private PDFOCGroupList(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
if (cosObject instanceof CosArray) {
this.mType = 1;
} else if (cosObject instanceof CosDictionary) {
this.mType = 2;
} else {
throw new PDFInvalidDocumentException("Array or dictionary expected");
}
}
public static PDFOCGroupList getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFOCGroupList pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFOCGroupList.class);
if (pdfObject == null) {
pdfObject = new PDFOCGroupList(cosObject);
}
return pdfObject;
}
public static PDFOCGroupList newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosObject = PDFCosObject.newCosArray(pdfDocument);
return new PDFOCGroupList((CosObject)cosObject);
}
public static PDFOCGroupList newInstance(PDFDocument pdfDocument, PDFOCGroup ocg) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
PDFOCGroupList pdfObject = PDFOCGroupList.newInstance(pdfDocument);
pdfObject.add(ocg);
return pdfObject;
}
public Iterator iterator() throws PDFInvalidDocumentException {
if (this.mType == 1) {
return this.getOCGroupArray().iterator();
}
return new OCGSingleIterator();
}
public boolean contains(PDFOCGroup ocg) throws PDFInvalidDocumentException {
if (this.mType == 1) {
return this.getOCGroupArray().contains(ocg);
}
return this.getSingleOCGroup() == ocg;
}
public PDFOCGroup getOCGByName(String name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFOCGroup result = null;
Iterator iter = this.iterator();
while (iter.hasNext()) {
String ocgName;
PDFOCGroup ocg = (PDFOCGroup)iter.next();
if (ocg == null || !(ocgName = ocg.getName()).equals(name)) continue;
result = ocg;
break;
}
return result;
}
public PDFOCGroupArray getOCGroupArray() throws PDFInvalidDocumentException {
if (this.mType == 1) {
return PDFOCGroupArray.getInstance(this.getCosObject());
}
return null;
}
public PDFOCGroup getSingleOCGroup() {
if (this.mType == 2) {
try {
return PDFOCGroup.getInstance(this.getCosObject());
}
catch (PDFInvalidDocumentException e) {
return null;
}
}
return null;
}
public void add(PDFOCGroup ocg) throws PDFIOException, PDFSecurityException, PDFInvalidParameterException, PDFInvalidDocumentException {
if (this.mType != 1) {
throw new PDFInvalidParameterException("Illegal attempt to add an OCG to an OCG dictionary rather than an OCG array.");
}
this.getOCGroupArray().add(ocg);
}
public boolean isEmpty() throws PDFInvalidDocumentException {
if (this.mType == 1) {
return this.getOCGroupArray().isEmpty();
}
return false;
}
public int size() throws PDFInvalidDocumentException {
if (this.mType == 1) {
return this.getOCGroupArray().size();
}
return 1;
}
class OCGSingleIterator
implements Iterator {
private CosObject mNextObj;
OCGSingleIterator() {
this.mNextObj = null;
this.mNextObj = PDFOCGroupList.this.getCosObject();
}
public void remove() {
throw new UnsupportedOperationException("Not implemented");
}
public boolean hasNext() {
return this.mNextObj != null;
}
public Object next() {
CosObject obj = this.mNextObj;
if (obj == null) {
throw new NoSuchElementException();
}
this.mNextObj = null;
try {
return PDFOCGroup.getInstance(obj);
}
catch (PDFInvalidDocumentException e) {
return null;
}
}
}
}