PDFBookmarkNode.java
6.38 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* 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.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.navigation;
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.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.interactive.navigation.PDFBookmark;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public abstract class PDFBookmarkNode
extends PDFCosDictionary {
protected PDFBookmarkNode(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public PDFBookmark getFirstKid() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFBookmark.getInstance(this.getDictionaryCosObjectValue(ASName.k_First));
}
public PDFBookmark getLastKid() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFBookmark.getInstance(this.getDictionaryCosObjectValue(ASName.k_Last));
}
public void setLast(PDFBookmark bookmark) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Last, bookmark);
}
public void setFirst(PDFBookmark bookmark) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_First, bookmark);
}
public abstract int getCount() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public boolean hasCount() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Count);
}
public void setCount(int count) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_Count, count);
}
public int getNumKids() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
int num = 0;
for (PDFBookmark kid = this.getFirstKid(); kid != null; kid = kid.getNext()) {
++num;
}
return num;
}
public void setKids(PDFBookmark toInsert) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setFirst(toInsert);
PDFBookmark lastToInsert = null;
for (PDFBookmark b = toInsert; b != null; b = b.getNext()) {
b.setParent(this);
lastToInsert = b;
}
this.setLast(lastToInsert);
}
public abstract PDFBookmark findDepthFirst(String var1) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public Iterator iterator() {
try {
return new Iterator();
}
catch (PDFInvalidDocumentException e) {
return null;
}
catch (PDFIOException e) {
return null;
}
catch (PDFSecurityException e) {
return null;
}
}
public class Iterator {
private PDFBookmark nextBookmark;
private PDFBookmark lastReturnedBookmark;
private boolean bookmarkTreeEmpty;
private final ArrayList<PDFBookmark> bookmarkStack;
private Set<Integer> visitedSet;
protected Iterator() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.bookmarkStack = new ArrayList();
this.visitedSet = new HashSet<Integer>();
if (PDFBookmarkNode.this instanceof PDFBookmark) {
this.nextBookmark = (PDFBookmark)PDFBookmarkNode.this;
} else {
this.nextBookmark = PDFBookmarkNode.this.getFirstKid();
if (this.nextBookmark == null) {
this.bookmarkTreeEmpty = true;
}
}
if (this.nextBookmark != null) {
this.bookmarkStack.add(this.nextBookmark);
}
}
public boolean hasNext() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.bookmarkTreeEmpty && this.lastReturnedBookmark == this.nextBookmark) {
PDFBookmark firstKid = this.lastReturnedBookmark.getFirstKid();
if (firstKid != null) {
this.nextBookmark = firstKid;
this.bookmarkStack.add(firstKid);
} else {
this.nextBookmark = this.lastReturnedBookmark.getNext();
if (this.nextBookmark != null) {
this.bookmarkStack.set(this.bookmarkStack.size() - 1, this.nextBookmark);
} else {
while (this.nextBookmark == null && this.bookmarkStack.size() > 1) {
this.bookmarkStack.remove(this.bookmarkStack.size() - 1);
this.nextBookmark = this.bookmarkStack.get(this.bookmarkStack.size() - 1).getNext();
if (this.nextBookmark == null) continue;
this.bookmarkStack.set(this.bookmarkStack.size() - 1, this.nextBookmark);
}
}
}
}
if (this.nextBookmark != null) {
if (!this.visitedSet.contains(this.nextBookmark.getCosObject().getObjNum())) {
return true;
}
throw new RuntimeException("Cycle has been detected in Bookmark tree");
}
return false;
}
public PDFBookmark next() {
Integer value;
this.lastReturnedBookmark = this.nextBookmark;
if (this.nextBookmark != null && (value = Integer.valueOf(this.nextBookmark.getCosObject().getObjNum())) != 0) {
this.visitedSet.add(value);
}
return this.nextBookmark;
}
}
}