PDFStructureRoot.java
7.61 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosDocument
* 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
*/
package com.adobe.internal.pdftoolkit.pdf.interchange.structure;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosDocument;
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.pdf.document.PDFCatalog;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFMarkInfo;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureClassMap;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureContentInterface;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureElement;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureIDTree;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureNode;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureParentTree;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureRoleMap;
import com.adobe.internal.pdftoolkit.pdf.interchange.structure.PDFStructureType;
import java.util.Iterator;
public class PDFStructureRoot
extends PDFStructureNode {
private PDFStructureRoot(CosObject cosObj) throws PDFInvalidDocumentException {
super(cosObj);
}
private PDFStructureRoot(PDFDocument pdfDoc) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(pdfDoc);
this.setDictionaryNameValue(ASName.k_Type, ASName.k_StructTreeRoot);
}
public static PDFStructureRoot getInstance(CosDictionary cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject((CosObject)cosObject) == null) {
return null;
}
PDFStructureRoot pdfObject = PDFCosObject.getCachedInstance((CosObject)cosObject, PDFStructureRoot.class);
if (pdfObject == null) {
pdfObject = new PDFStructureRoot((CosObject)cosObject);
}
return pdfObject;
}
public static PDFStructureRoot newInstance(PDFDocument forDoc) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFCatalog catalogDict = forDoc.requireCatalog();
if (catalogDict.hasStructureRoot()) {
return null;
}
PDFStructureRoot structRoot = new PDFStructureRoot(forDoc);
PDFMarkInfo markInfoDict = PDFMarkInfo.getInstance((CosObject)forDoc.getCosDocument().createDirectCosDictionary());
markInfoDict.setMarked(true);
catalogDict.setStructureRoot(structRoot);
catalogDict.setMarkInfo(markInfoDict);
return structRoot;
}
public static PDFStructureRoot newInstance(PDFDocument forDoc, PDFStructureElement firstChild) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFStructureRoot structRoot = PDFStructureRoot.newInstance(forDoc);
if (structRoot == null) {
return null;
}
structRoot.addContent(firstChild);
return structRoot;
}
public PDFStructureType getStructureType() {
return PDFStructureType.Root;
}
public PDFStructureParentTree getParentTree() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFStructureParentTree.getInstance(this.getCosDictionary().get(ASName.k_ParentTree));
}
public PDFStructureParentTree procureParentTree() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFStructureParentTree parentTree = this.getParentTree();
if (parentTree == null) {
parentTree = PDFStructureParentTree.newInstance(this.getPDFDocument());
this.getCosDictionary().put(ASName.k_ParentTree, parentTree.getCosObject());
this.setNextParentKey(0);
}
return parentTree;
}
public int addParentTree(PDFStructureContentInterface node) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
Object itr;
Integer n;
PDFStructureParentTree parentTree = this.procureParentTree();
Integer lastKey = this.getNextParentKey();
if (lastKey == null) {
lastKey = Integer.MIN_VALUE;
itr = parentTree.keyIterator();
while (itr.hasNext()) {
lastKey = Math.max(lastKey, (Integer)itr.next());
}
n = lastKey;
Integer n2 = lastKey = Integer.valueOf(lastKey + 1);
}
itr = lastKey;
n = lastKey = Integer.valueOf(lastKey + 1);
parentTree.addEntry(itr, node);
this.setNextParentKey(lastKey);
return lastKey;
}
public PDFStructureRoleMap getRoleMap() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFStructureRoleMap.getInstance(this.getCosDictionary().get(ASName.k_RoleMap));
}
public void setRoleMap(PDFStructureRoleMap roleMap) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosDictionary().put(ASName.k_RoleMap, roleMap.getCosObject());
}
public PDFStructureClassMap getClassMap() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFStructureClassMap.getInstance(this.getCosDictionary().get(ASName.k_ClassMap));
}
public void setClassMap(PDFStructureClassMap classMap) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosDictionary().put(ASName.k_ClassMap, classMap.getCosObject());
}
public void removeParentTree() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosDictionary().remove(ASName.k_ParentTree);
}
public PDFStructureIDTree getIdTree() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFStructureIDTree.getInstance(this.getCosDictionary().get(ASName.k_IDTree));
}
public void setIDTree(PDFStructureIDTree idTree) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosDictionary().put(ASName.k_IDTree, idTree.getCosObject());
}
public Integer getNextParentKey() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryIntValue(ASName.k_ParentTreeNextKey);
}
public void setNextParentKey(int key) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosDictionary().put(ASName.k_ParentTreeNextKey, key);
}
public ASName getType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Type);
}
}