RNGUtils.java
4.58 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.xmp.schema.model.ArrayType
* com.adobe.xmp.schema.model.ArrayType$ArrayForm
* com.adobe.xmp.schema.model.SimpleType
* com.adobe.xmp.schema.model.SimpleType$BasicType
* org.kohsuke.rngom.rngparser.digested.DAttributePattern
* org.kohsuke.rngom.rngparser.digested.DElementPattern
* org.kohsuke.rngom.rngparser.nc.NameClass
* org.kohsuke.rngom.rngparser.nc.SimpleNameClass
*/
package com.adobe.xmp.schema.rng.parser.utils;
import com.adobe.xmp.schema.model.ArrayType;
import com.adobe.xmp.schema.model.SimpleType;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGUnexpectedElementFoundException;
import com.adobe.xmp.schema.rng.parser.generator.XMPSchemaGenerator;
import java.util.Map;
import javax.xml.namespace.QName;
import org.kohsuke.rngom.rngparser.digested.DAttributePattern;
import org.kohsuke.rngom.rngparser.digested.DElementPattern;
import org.kohsuke.rngom.rngparser.nc.NameClass;
import org.kohsuke.rngom.rngparser.nc.SimpleNameClass;
public class RNGUtils {
public static ArrayType.ArrayForm getArrayForm(QName qname) {
if (qname == null) {
return null;
}
String name = qname.getLocalPart();
String ns = qname.getNamespaceURI();
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(ns)) {
if ("Alt".equals(name)) {
return ArrayType.ArrayForm.ALTERNATIVE;
}
if ("Bag".equals(name)) {
return ArrayType.ArrayForm.UNORDERED;
}
if ("Seq".equals(name)) {
return ArrayType.ArrayForm.ORDERED;
}
return null;
}
return null;
}
private static boolean compareQualifiedNames(QName qname, String ns, String localName) {
if (qname == null) {
return false;
}
String qLocal = qname.getLocalPart();
String qNS = qname.getNamespaceURI();
return ns.equals(qNS) && localName.equals(qLocal);
}
public static boolean isElementArrayStart(QName qname) {
return RNGUtils.compareQualifiedNames(qname, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "li");
}
public static boolean isElementRDFDesc(QName qname) {
return RNGUtils.compareQualifiedNames(qname, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "Description");
}
public static boolean isElementRDFRDF(QName qname) {
return RNGUtils.compareQualifiedNames(qname, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF");
}
public static boolean isElementRDFValue(QName qname) {
return RNGUtils.compareQualifiedNames(qname, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "value");
}
public static boolean isElementRDFAbout(QName qname) {
return RNGUtils.compareQualifiedNames(qname, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about");
}
public static boolean isAttributeXMLLang(QName qname) {
return RNGUtils.compareQualifiedNames(qname, "http://www.w3.org/XML/1998/namespace", "lang");
}
public static QName getSimpleName(DElementPattern p) {
NameClass name = p.getName();
QName qName = null;
if (!(name instanceof SimpleNameClass)) {
throw new RNGUnexpectedElementFoundException("Excpected simple name class");
}
SimpleNameClass sName = (SimpleNameClass)name;
qName = sName.name;
return qName;
}
public static QName getSimpleName(DAttributePattern p) {
NameClass name = p.getName();
QName qName = null;
if (!(name instanceof SimpleNameClass)) {
throw new RNGUnexpectedElementFoundException("Excpected simple name class");
}
SimpleNameClass sName = (SimpleNameClass)name;
qName = sName.name;
return qName;
}
public static Object convertSimpleRawValue(String value, String xmpDataType) {
try {
SimpleType.BasicType basicType = XMPSchemaGenerator.kBasicTypes.get(xmpDataType.toLowerCase());
switch (basicType) {
case BOOLEAN: {
return Boolean.valueOf(value.toLowerCase());
}
case INTEGER: {
return Integer.valueOf(value);
}
case REAL: {
return Double.valueOf(value);
}
}
return value;
}
catch (NumberFormatException e) {
return null;
}
}
public static boolean isEmptyString(String s) {
return s == null || s.trim().length() == 0;
}
}