AnnotationsFactory.java
2.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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.kohsuke.rngom.rngparser.digested.DAnnotation
* org.kohsuke.rngom.rngparser.digested.DAnnotation$Attribute
*/
package com.adobe.xmp.schema.rng.parser.annotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGDecorationAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGLabelAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGSchemaAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGTypeAnnotation;
import java.util.List;
import org.kohsuke.rngom.rngparser.digested.DAnnotation;
import org.w3c.dom.Element;
public class AnnotationsFactory {
private static final String SCHEMA = "schema";
private static final String NAMESPACE = "namespace";
private static final String DECORATION = "decoration";
private static final String PROPERTY = "property";
private static final String TYPE = "type";
private static final String LABEL = "label";
public static RNGAnnotation[] createAnnotationArray(DAnnotation annot) {
if (annot == null || annot == DAnnotation.EMPTY) {
return null;
}
List list = annot.getChildren();
if (list == null || list.size() == 0) {
DAnnotation.Attribute tAttr = annot.getAttribute("http://ns.adobe.com/xmp/schema/info/", "type");
if (tAttr != null) {
return new RNGAnnotation[]{new RNGTypeAnnotation(annot)};
}
DAnnotation.Attribute lAttr = annot.getAttribute("http://ns.adobe.com/xmp/schema/info/", "label");
if (lAttr != null) {
return new RNGAnnotation[]{new RNGLabelAnnotation(annot)};
}
return null;
}
if (list.size() == 0) {
return null;
}
RNGAnnotation[] arr = new RNGAnnotation[list.size()];
int idx = 0;
for (Element e : list) {
arr[idx++] = AnnotationsFactory.createAnnotation(e);
}
return arr;
}
public static RNGAnnotation createAnnotation(Element element) {
if (element == null) {
return null;
}
if ("http://ns.adobe.com/xmp/schema/info/".equals(element.getNamespaceURI())) {
if ("schema".equals(element.getLocalName()) || "namespace".equals(element.getLocalName())) {
return new RNGSchemaAnnotation(element);
}
if ("decoration".equals(element.getLocalName()) || "property".equals(element.getLocalName())) {
return new RNGDecorationAnnotation(element);
}
if ("type".equals(element.getLocalName())) {
return new RNGTypeAnnotation(element);
}
if ("label".equals(element.getLocalName())) {
return new RNGLabelAnnotation(element);
}
}
return null;
}
}