ParserRDFUtils.java
3.82 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xmp.core.parser.impl;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
class ParserRDFUtils {
public static final String RDF_VALUE = "value";
public static final Object RDF_LI = "li";
private static final EnumSet<RDFTerm> coreSyntaxTerms = EnumSet.of(RDFTerm.RDF, new RDFTerm[]{RDFTerm.ID, RDFTerm.ABOUT, RDFTerm.PARSE_TYPE, RDFTerm.RESOURCE, RDFTerm.NODE_ID, RDFTerm.DATATYPE});
private static final EnumSet<RDFTerm> oldTerms = EnumSet.of(RDFTerm.ABOUT_EACH, RDFTerm.ABOUT_EACH_PREFIX, RDFTerm.BAG_ID);
private static final EnumSet<RDFTerm> otherTerms = EnumSet.of(RDFTerm.OTHER, RDFTerm.VALUE, RDFTerm.BAG, RDFTerm.SEQ, RDFTerm.ALT);
private static final Map<String, RDFTerm> rdfTermMap = new HashMap<String, RDFTerm>(){};
ParserRDFUtils() {
}
static RDFTerm getRDFTermKind(Node node) {
String localName = node.getLocalName();
String namespace = node.getNamespaceURI();
if (namespace == null && ("about".equals(localName) || "ID".equals(localName)) && node instanceof Attr && "http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(((Attr)node).getOwnerElement().getNamespaceURI())) {
namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
}
if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace)) {
RDFTerm result = rdfTermMap.get(localName);
if (result != null) {
return result;
}
} else if ("http://www.w3.org/XML/1998/namespace".equals(namespace) && "lang".equals(localName)) {
return RDFTerm.XML_LANG;
}
return RDFTerm.OTHER;
}
static boolean isNSDeclaration(Node attribute) {
return "xmlns".equals(attribute.getPrefix()) || attribute.getPrefix() == null && "xmlns".equals(attribute.getNodeName());
}
static boolean isNumberedArrayItemName(String namespace, String nodeName) {
boolean result = "http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespace);
if (result) {
result = RDF_LI.equals(nodeName);
if (nodeName.startsWith("_")) {
result = true;
for (int i = 1; i < nodeName.length(); ++i) {
result = result && nodeName.charAt(i) >= '0' && nodeName.charAt(i) <= '9';
}
}
}
return result;
}
static boolean isCoreSyntaxTerm(RDFTerm term) {
return coreSyntaxTerms.contains((Object)term);
}
static boolean isOldTerm(RDFTerm term) {
return oldTerms.contains((Object)term);
}
static boolean isOtherTerm(RDFTerm term) {
return otherTerms.contains((Object)term);
}
static boolean isPropertyElementName(RDFTerm term) {
if (term == RDFTerm.DESCRIPTION || ParserRDFUtils.isOldTerm(term)) {
return false;
}
return !ParserRDFUtils.isCoreSyntaxTerm(term);
}
static boolean isWhitespaceNode(Node node) {
if (node.getNodeType() != 3) {
return false;
}
String value = node.getNodeValue();
for (int i = 0; i < value.length(); ++i) {
if (Character.isWhitespace(value.charAt(i))) continue;
return false;
}
return true;
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
static enum RDFTerm {
RDF,
ID,
ABOUT,
PARSE_TYPE,
RESOURCE,
NODE_ID,
DATATYPE,
DESCRIPTION,
LI,
ABOUT_EACH,
ABOUT_EACH_PREFIX,
BAG_ID,
XML_LANG,
OTHER,
VALUE,
BAG,
SEQ,
ALT;
private RDFTerm() {
}
}
}