XMPStructImpl.java
8.84 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xmp.core.impl;
import com.adobe.xmp.core.XMPArray;
import com.adobe.xmp.core.XMPLanguageAlternative;
import com.adobe.xmp.core.XMPNode;
import com.adobe.xmp.core.XMPNodeVisitor;
import com.adobe.xmp.core.XMPSimple;
import com.adobe.xmp.core.XMPStruct;
import com.adobe.xmp.core.impl.Utils;
import com.adobe.xmp.core.impl.XMPArrayImpl;
import com.adobe.xmp.core.impl.XMPNodeCopyVisitor;
import com.adobe.xmp.core.impl.XMPNodeImpl;
import com.adobe.xmp.core.impl.XMPQName;
import com.adobe.xmp.core.impl.XMPSimpleImpl;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.NoSuchElementException;
import java.util.Set;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
class XMPStructImpl
extends XMPNodeImpl
implements XMPStruct {
LinkedHashMap<XMPQName, XMPNode> struct = new LinkedHashMap(1);
XMPStructImpl(XMPNodeImpl parent, String namespace, String name) {
super(parent, namespace, name);
}
@Override
public XMPSimple setSimple(String namespace, String name, String value) {
if (!Utils.isXMLName(name)) {
throw new IllegalArgumentException("XML name is not valid.");
}
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace)) {
throw new IllegalArgumentException("Creating node in RDF namespace is not allowed.");
}
XMPSimpleImpl newSimple = new XMPSimpleImpl(this, namespace, name, value);
XMPQName qname = new XMPQName(namespace, name);
this.struct.put(qname, newSimple);
return newSimple;
}
@Override
public XMPStruct setStruct(String namespace, String name) {
if (!Utils.isXMLName(name)) {
throw new IllegalArgumentException("XML name is not valid.");
}
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace)) {
throw new IllegalArgumentException("Creating node in RDF namespace is not allowed.");
}
XMPStructImpl newStruct = new XMPStructImpl(this, namespace, name);
XMPQName qname = new XMPQName(namespace, name);
this.struct.put(qname, newStruct);
return newStruct;
}
@Override
public XMPArray setArray(String namespace, String name, XMPArray.Form form) {
if (!Utils.isXMLName(name)) {
throw new IllegalArgumentException("XML name is not valid.");
}
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace)) {
throw new IllegalArgumentException("Creating node in RDF namespace is not allowed.");
}
XMPArrayImpl newArray = new XMPArrayImpl(this, namespace, name, form);
XMPQName qname = new XMPQName(namespace, name);
this.struct.put(qname, newArray);
return newArray;
}
@Override
public XMPLanguageAlternative getLanguageAlternative(String namespace, String name) {
XMPArray array = this.getArray(namespace, name);
return XMPLanguageAlternative.newInstance(array);
}
@Override
public XMPLanguageAlternative setLanguageAlternative(String namespace, String name) {
if (!Utils.isXMLName(name)) {
throw new IllegalArgumentException("XML name is not valid.");
}
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace)) {
throw new IllegalArgumentException("Creating node in RDF namespace is not allowed.");
}
XMPArrayImpl newArray = new XMPArrayImpl(this, namespace, name, XMPArray.Form.ALTERNATIVE);
XMPLanguageAlternative newLangAlt = XMPLanguageAlternative.newInstance(newArray);
if (newLangAlt == null) {
return null;
}
XMPQName qname = new XMPQName(namespace, name);
this.struct.put(qname, newArray);
return newLangAlt;
}
@Override
public XMPSimple getSimple(String namespace, String name) {
XMPQName qname = new XMPQName(namespace, name);
XMPNode node = this.struct.get(qname);
if (node != null) {
return node.adaptTo(XMPSimple.class);
}
return null;
}
@Override
public XMPStruct getStruct(String namespace, String name) {
XMPQName qname = new XMPQName(namespace, name);
XMPNode node = this.struct.get(qname);
if (node != null) {
return node.adaptTo(XMPStruct.class);
}
return null;
}
@Override
public XMPArray getArray(String namespace, String name) {
XMPQName qname = new XMPQName(namespace, name);
XMPNode node = this.struct.get(qname);
if (node != null) {
return node.adaptTo(XMPArray.class);
}
return null;
}
@Override
public void renameField(String namespace, String name, String newNamespace, String newName) {
XMPNode field;
if (!Utils.isXMLName(name)) {
throw new IllegalArgumentException("XML name is not valid.");
}
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace)) {
throw new IllegalArgumentException("Creating node in RDF namespace is not allowed.");
}
if (namespace != null && namespace.length() > 0 && name != null && name.length() > 0 && (field = this.get(namespace, name)) != null) {
this.remove(namespace, name);
XMPQName qname = new XMPQName(newNamespace, newName);
((XMPNodeImpl)field).setNamespace(newNamespace);
((XMPNodeImpl)field).setName(newName);
this.struct.put(qname, field);
}
}
@Override
public int size() {
return this.struct.size();
}
@Override
public XMPNode get(String namespace, String name) {
XMPQName qname = new XMPQName(namespace, name);
return this.struct.get(qname);
}
@Override
public XMPNode remove(String namespace, String name) {
XMPQName qname = new XMPQName(namespace, name);
return this.struct.remove(qname);
}
@Override
public Iterator<XMPNode> iterator() {
return this.struct.values().iterator();
}
@Override
public Iterator<XMPNode> getNamespaceProperties(final String namespace) {
final Iterator<XMPNode> it = this.iterator();
return new Iterator<XMPNode>(){
private XMPNode nextNode;
@Override
public boolean hasNext() {
this.prepareNextNode();
return this.nextNode != null;
}
@Override
public XMPNode next() {
this.prepareNextNode();
if (this.nextNode != null) {
XMPNode result = this.nextNode;
this.nextNode = null;
return result;
}
throw new NoSuchElementException();
}
@Override
public void remove() {
it.remove();
}
private void prepareNextNode() {
while (it.hasNext() && (this.nextNode == null || !this.nextNode.getNamespace().equals(namespace))) {
this.nextNode = (XMPNode)it.next();
}
if (this.nextNode != null && !this.nextNode.getNamespace().equals(namespace)) {
this.nextNode = null;
}
}
};
}
@Override
public Set<String> getUsedNamespaces() {
HashSet<String> usedNamespaces = new HashSet<String>();
for (XMPNode node : this) {
usedNamespaces.add(node.getNamespace());
}
return Collections.unmodifiableSet(usedNamespaces);
}
@Override
public XMPSimple copy(XMPSimple simple) {
if (simple == null) {
return null;
}
XMPNodeCopyVisitor visitor = new XMPNodeCopyVisitor(this);
simple.accept(visitor);
return this.getSimple(simple.getNamespace(), simple.getName());
}
@Override
public XMPStruct copy(XMPStruct struct) {
if (struct == null) {
return null;
}
XMPNodeCopyVisitor visitor = new XMPNodeCopyVisitor(this);
struct.accept(visitor);
return this.getStruct(struct.getNamespace(), struct.getName());
}
@Override
public XMPArray copy(XMPArray array) {
if (array == null) {
return null;
}
XMPNodeCopyVisitor visitor = new XMPNodeCopyVisitor(this);
array.accept(visitor);
return this.getArray(array.getNamespace(), array.getName());
}
@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (!type.equals(XMPStruct.class)) {
return null;
}
return (AdapterType)this;
}
@Override
public void accept(XMPNodeVisitor visitor) {
visitor.visit(this);
}
}