XMPIteratorImpl.java
11.2 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.xmp.impl;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPIterator;
import com.adobe.internal.xmp.XMPMetaFactory;
import com.adobe.internal.xmp.impl.QName;
import com.adobe.internal.xmp.impl.XMPMetaImpl;
import com.adobe.internal.xmp.impl.XMPNode;
import com.adobe.internal.xmp.impl.XMPNodeUtils;
import com.adobe.internal.xmp.impl.xpath.XMPPath;
import com.adobe.internal.xmp.impl.xpath.XMPPathParser;
import com.adobe.internal.xmp.impl.xpath.XMPPathSegment;
import com.adobe.internal.xmp.options.IteratorOptions;
import com.adobe.internal.xmp.options.PropertyOptions;
import com.adobe.internal.xmp.properties.XMPPropertyInfo;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
public class XMPIteratorImpl
implements XMPIterator {
private IteratorOptions options;
private String baseNS = null;
protected boolean skipSiblings = false;
protected boolean skipSubtree = false;
private Iterator nodeIterator = null;
public XMPIteratorImpl(XMPMetaImpl xmp, String schemaNS, String propPath, IteratorOptions options) throws XMPException {
boolean baseProperty;
this.options = options != null ? options : new IteratorOptions();
XMPNode startNode = null;
String initialPath = null;
boolean baseSchema = schemaNS != null && schemaNS.length() > 0;
boolean bl = baseProperty = propPath != null && propPath.length() > 0;
if (!baseSchema && !baseProperty) {
startNode = xmp.getRoot();
} else if (baseSchema && baseProperty) {
XMPPath path = XMPPathParser.expandXPath(schemaNS, propPath);
XMPPath basePath = new XMPPath();
for (int i = 0; i < path.size() - 1; ++i) {
basePath.add(path.getSegment(i));
}
startNode = XMPNodeUtils.findNode(xmp.getRoot(), path, false, null);
this.baseNS = schemaNS;
initialPath = basePath.toString();
} else if (baseSchema && !baseProperty) {
startNode = XMPNodeUtils.findSchemaNode(xmp.getRoot(), schemaNS, false);
} else {
throw new XMPException("Schema namespace URI is required", 101);
}
this.nodeIterator = startNode != null ? (!this.options.isJustChildren() ? new NodeIterator(this, startNode, initialPath, 1) : new NodeIteratorChildren(startNode, initialPath)) : Collections.EMPTY_LIST.iterator();
}
public void skipSubtree() {
this.skipSubtree = true;
}
public void skipSiblings() {
this.skipSubtree();
this.skipSiblings = true;
}
public boolean hasNext() {
return this.nodeIterator.hasNext();
}
public Object next() {
return this.nodeIterator.next();
}
public void remove() {
throw new UnsupportedOperationException("The XMPIterator does not support remove().");
}
protected IteratorOptions getOptions() {
return this.options;
}
protected String getBaseNS() {
return this.baseNS;
}
protected void setBaseNS(String baseNS) {
this.baseNS = baseNS;
}
private class NodeIteratorChildren
extends NodeIterator {
private String parentPath;
private Iterator childrenIterator;
private int index;
public NodeIteratorChildren(XMPNode parentNode, String parentPath) {
super(XMPIteratorImpl.this);
this.index = 0;
if (parentNode.getOptions().isSchemaNode()) {
XMPIteratorImpl.this.setBaseNS(parentNode.getName());
}
this.parentPath = this.accumulatePath(parentNode, parentPath, 1);
this.childrenIterator = parentNode.iterateChildren();
}
public boolean hasNext() {
if (this.getReturnProperty() != null) {
return true;
}
if (XMPIteratorImpl.this.skipSiblings) {
return false;
}
if (this.childrenIterator.hasNext()) {
XMPNode child = (XMPNode)this.childrenIterator.next();
++this.index;
String path = null;
if (child.getOptions().isSchemaNode()) {
XMPIteratorImpl.this.setBaseNS(child.getName());
} else if (child.getParent() != null) {
path = this.accumulatePath(child, this.parentPath, this.index);
}
if (!XMPIteratorImpl.this.getOptions().isJustLeafnodes() || !child.hasChildren()) {
this.setReturnProperty(this.createPropertyInfo(child, XMPIteratorImpl.this.getBaseNS(), path));
return true;
}
return this.hasNext();
}
return false;
}
}
private class NodeIterator
implements Iterator {
protected static final int ITERATE_NODE = 0;
protected static final int ITERATE_CHILDREN = 1;
protected static final int ITERATE_QUALIFIER = 2;
private int state;
private XMPNode visitedNode;
private String path;
private Iterator childrenIterator;
private int index;
private Iterator subIterator;
private XMPPropertyInfo returnProperty;
final /* synthetic */ XMPIteratorImpl this$0;
public NodeIterator(XMPIteratorImpl xMPIteratorImpl) {
this.this$0 = xMPIteratorImpl;
this.state = 0;
this.childrenIterator = null;
this.index = 0;
this.subIterator = Collections.EMPTY_LIST.iterator();
this.returnProperty = null;
}
public NodeIterator(XMPIteratorImpl xMPIteratorImpl, XMPNode visitedNode, String parentPath, int index) {
this.this$0 = xMPIteratorImpl;
this.state = 0;
this.childrenIterator = null;
this.index = 0;
this.subIterator = Collections.EMPTY_LIST.iterator();
this.returnProperty = null;
this.visitedNode = visitedNode;
this.state = 0;
if (visitedNode.getOptions().isSchemaNode()) {
xMPIteratorImpl.setBaseNS(visitedNode.getName());
}
this.path = this.accumulatePath(visitedNode, parentPath, index);
}
public boolean hasNext() {
if (this.returnProperty != null) {
return true;
}
if (this.state == 0) {
return this.reportNode();
}
if (this.state == 1) {
boolean hasNext;
if (this.childrenIterator == null) {
this.childrenIterator = this.visitedNode.iterateChildren();
}
if (!(hasNext = this.iterateChildren(this.childrenIterator)) && this.visitedNode.hasQualifier() && !this.this$0.getOptions().isOmitQualifiers()) {
this.state = 2;
this.childrenIterator = null;
hasNext = this.hasNext();
}
return hasNext;
}
if (this.childrenIterator == null) {
this.childrenIterator = this.visitedNode.iterateQualifier();
}
return this.iterateChildren(this.childrenIterator);
}
protected boolean reportNode() {
this.state = 1;
if (!(this.visitedNode.getParent() == null || this.this$0.getOptions().isJustLeafnodes() && this.visitedNode.hasChildren())) {
this.returnProperty = this.createPropertyInfo(this.visitedNode, this.this$0.getBaseNS(), this.path);
return true;
}
return this.hasNext();
}
private boolean iterateChildren(Iterator iterator) {
if (this.this$0.skipSiblings) {
this.this$0.skipSiblings = false;
this.subIterator = Collections.EMPTY_LIST.iterator();
}
if (!this.subIterator.hasNext() && iterator.hasNext()) {
XMPNode child = (XMPNode)iterator.next();
++this.index;
this.subIterator = new NodeIterator(this.this$0, child, this.path, this.index);
}
if (this.subIterator.hasNext()) {
this.returnProperty = (XMPPropertyInfo)this.subIterator.next();
return true;
}
return false;
}
public Object next() {
if (this.hasNext()) {
XMPPropertyInfo result = this.returnProperty;
this.returnProperty = null;
return result;
}
throw new NoSuchElementException("There are no more nodes to return");
}
public void remove() {
throw new UnsupportedOperationException();
}
protected String accumulatePath(XMPNode currNode, String parentPath, int currentIndex) {
String separator;
String segmentName;
if (currNode.getParent() == null || currNode.getOptions().isSchemaNode()) {
return null;
}
if (currNode.getParent().getOptions().isArray()) {
separator = "";
segmentName = "[" + String.valueOf(currentIndex) + "]";
} else {
separator = "/";
segmentName = currNode.getName();
}
if (parentPath == null || parentPath.length() == 0) {
return segmentName;
}
if (this.this$0.getOptions().isJustLeafname()) {
return !segmentName.startsWith("?") ? segmentName : segmentName.substring(1);
}
return parentPath + separator + segmentName;
}
protected XMPPropertyInfo createPropertyInfo(final XMPNode node, final String baseNS, final String path) {
final String value = node.getOptions().isSchemaNode() ? null : node.getValue();
return new XMPPropertyInfo(){
public String getNamespace() {
if (!node.getOptions().isSchemaNode()) {
QName qname = new QName(node.getName());
return XMPMetaFactory.getSchemaRegistry().getNamespaceURI(qname.getPrefix());
}
return baseNS;
}
public String getPath() {
return path;
}
public String getValue() {
return value;
}
public PropertyOptions getOptions() {
return node.getOptions();
}
public String getLanguage() {
return null;
}
};
}
protected Iterator getChildrenIterator() {
return this.childrenIterator;
}
protected void setChildrenIterator(Iterator childrenIterator) {
this.childrenIterator = childrenIterator;
}
protected XMPPropertyInfo getReturnProperty() {
return this.returnProperty;
}
protected void setReturnProperty(XMPPropertyInfo returnProperty) {
this.returnProperty = returnProperty;
}
}
}