imToken v2.14.1版本的 MD5 值为:83050b2c91219b46832c8336279e7878
以下内容为反编译后的 ParseRDF.java 源代码,内容仅作参考
package com.adobe.internal.xmp.impl;
import com.adobe.internal.xmp.XMPConst;
import com.adobe.internal.xmp.XMPError;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMetaFactory;
import com.adobe.internal.xmp.XMPSchemaRegistry;
import com.adobe.internal.xmp.options.ParseOptions;
import com.adobe.internal.xmp.options.PropertyOptions;
import java.util.ArrayList;
import java.util.Iterator;
import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public class ParseRDF implements XMPError, XMPConst {
static final boolean $assertionsDisabled = false;
public static final String DEFAULT_PREFIX = "_dflt";
public static final int RDFTERM_ABOUT = 3;
public static final int RDFTERM_ABOUT_EACH = 10;
public static final int RDFTERM_ABOUT_EACH_PREFIX = 11;
public static final int RDFTERM_BAG_ID = 12;
public static final int RDFTERM_DATATYPE = 7;
public static final int RDFTERM_DESCRIPTION = 8;
public static final int RDFTERM_FIRST_CORE = 1;
public static final int RDFTERM_FIRST_OLD = 10;
public static final int RDFTERM_FIRST_SYNTAX = 1;
public static final int RDFTERM_ID = 2;
public static final int RDFTERM_LAST_CORE = 7;
public static final int RDFTERM_LAST_OLD = 12;
public static final int RDFTERM_LAST_SYNTAX = 9;
public static final int RDFTERM_LI = 9;
public static final int RDFTERM_NODE_ID = 6;
public static final int RDFTERM_OTHER = 0;
public static final int RDFTERM_PARSE_TYPE = 4;
public static final int RDFTERM_RDF = 1;
public static final int RDFTERM_RESOURCE = 5;
private static boolean isCoreSyntaxTerm(int i2) {
return 1 <= i2 && i2 <= 7;
}
private static boolean isOldTerm(int i2) {
return 10 <= i2 && i2 <= 12;
}
public static XMPMetaImpl parse(Node node, ParseOptions parseOptions) throws XMPException {
XMPMetaImpl xMPMetaImpl = new XMPMetaImpl();
rdf_RDF(xMPMetaImpl, node, parseOptions);
return xMPMetaImpl;
}
static void rdf_RDF(XMPMetaImpl xMPMetaImpl, Node node, ParseOptions parseOptions) throws XMPException {
if (node.hasAttributes()) {
rdf_NodeElementList(xMPMetaImpl, xMPMetaImpl.getRoot(), node, parseOptions);
return;
}
throw new XMPException("Invalid attributes of rdf:RDF element", 202);
}
private static void rdf_NodeElementList(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, ParseOptions parseOptions) throws XMPException {
for (int i2 = 0; i2 < node.getChildNodes().getLength(); i2++) {
Node item = node.getChildNodes().item(i2);
if (!isWhitespaceNode(item)) {
rdf_NodeElement(xMPMetaImpl, xMPNode, item, true, parseOptions);
}
}
}
private static void rdf_NodeElement(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2, ParseOptions parseOptions) throws XMPException {
int rDFTermKind = getRDFTermKind(node);
if (rDFTermKind != 8 && rDFTermKind != 0) {
throw new XMPException("Node element must be rdf:Description or typed node", 202);
}
if (z2 && rDFTermKind == 0) {
throw new XMPException("Top level typed node not allowed", 203);
}
rdf_NodeElementAttrs(xMPMetaImpl, xMPNode, node, z2, parseOptions);
rdf_PropertyElementList(xMPMetaImpl, xMPNode, node, z2, parseOptions);
}
private static void rdf_NodeElementAttrs(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2, ParseOptions parseOptions) throws XMPException {
int i2 = 0;
for (int i3 = 0; i3 < node.getAttributes().getLength(); i3++) {
Node item = node.getAttributes().item(i3);
if (!"xmlns".equals(item.getPrefix()) && (item.getPrefix() != null || !"xmlns".equals(item.getNodeName()))) {
int rDFTermKind = getRDFTermKind(item);
if (rDFTermKind == 0) {
addChildNode(xMPMetaImpl, xMPNode, item, item.getNodeValue(), z2);
} else if (rDFTermKind != 6 && rDFTermKind != 2 && rDFTermKind != 3) {
throw new XMPException("Invalid nodeElement attribute", 202);
} else {
if (i2 > 0) {
throw new XMPException("Mutally exclusive about, ID, nodeID attributes", 202);
}
i2++;
if (z2 && rDFTermKind == 3) {
if (xMPNode.getName() != null && xMPNode.getName().length() > 0) {
if (!xMPNode.getName().equals(item.getNodeValue())) {
throw new XMPException("Mismatched top level rdf:about values", 203);
}
} else {
xMPNode.setName(item.getNodeValue());
}
}
}
}
}
}
private static void rdf_PropertyElementList(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2, ParseOptions parseOptions) throws XMPException {
for (int i2 = 0; i2 < node.getChildNodes().getLength(); i2++) {
Node item = node.getChildNodes().item(i2);
if (!isWhitespaceNode(item)) {
if (item.getNodeType() != 1) {
throw new XMPException("Expected property element node not found", 202);
}
if (xMPNode.getOptions().isArrayLimited() && i2 > xMPNode.getOptions().getArrayElementsLimit()) {
return;
}
rdf_PropertyElement(xMPMetaImpl, xMPNode, item, z2, parseOptions);
}
}
}
private static void rdf_PropertyElement(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2, ParseOptions parseOptions) throws XMPException {
if (!isPropertyElementName(getRDFTermKind(node))) {
throw new XMPException("Invalid property element name", 202);
}
NamedNodeMap attributes = node.getAttributes();
ArrayList<String> arrayList = null;
for (int i2 = 0; i2 < attributes.getLength(); i2++) {
Node item = attributes.item(i2);
if ("xmlns".equals(item.getPrefix()) || (item.getPrefix() == null && "xmlns".equals(item.getNodeName()))) {
if (arrayList == null) {
arrayList = new ArrayList();
}
arrayList.add(item.getNodeName());
}
}
if (arrayList != null) {
for (String str : arrayList) {
attributes.removeNamedItem(str);
}
}
if (attributes.getLength() > 3) {
rdf_EmptyPropertyElement(xMPMetaImpl, xMPNode, node, z2);
return;
}
for (int i3 = 0; i3 < attributes.getLength(); i3++) {
Node item2 = attributes.item(i3);
String localName = item2.getLocalName();
String namespaceURI = item2.getNamespaceURI();
String nodeValue = item2.getNodeValue();
if (!XMPConst.XML_LANG.equals(item2.getNodeName()) || ("ID".equals(localName) && XMPConst.NS_RDF.equals(namespaceURI))) {
if ("datatype".equals(localName) && XMPConst.NS_RDF.equals(namespaceURI)) {
rdf_LiteralPropertyElement(xMPMetaImpl, xMPNode, node, z2);
return;
} else if (!"parseType".equals(localName) || !XMPConst.NS_RDF.equals(namespaceURI)) {
rdf_EmptyPropertyElement(xMPMetaImpl, xMPNode, node, z2);
return;
} else if ("Literal".equals(nodeValue)) {
rdf_ParseTypeLiteralPropertyElement();
return;
} else if ("Resource".equals(nodeValue)) {
rdf_ParseTypeResourcePropertyElement(xMPMetaImpl, xMPNode, node, z2, parseOptions);
return;
} else if ("Collection".equals(nodeValue)) {
rdf_ParseTypeCollectionPropertyElement();
return;
} else {
rdf_ParseTypeOtherPropertyElement();
return;
}
}
}
if (node.hasChildNodes()) {
for (int i4 = 0; i4 < node.getChildNodes().getLength(); i4++) {
if (node.getChildNodes().item(i4).getNodeType() != 3) {
rdf_ResourcePropertyElement(xMPMetaImpl, xMPNode, node, z2, parseOptions);
return;
}
}
rdf_LiteralPropertyElement(xMPMetaImpl, xMPNode, node, z2);
return;
}
rdf_EmptyPropertyElement(xMPMetaImpl, xMPNode, node, z2);
}
private static void rdf_ResourcePropertyElement(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2, ParseOptions parseOptions) throws XMPException {
Integer num;
if (z2 && "iX:changes".equals(node.getNodeName())) {
return;
}
XMPNode addChildNode = addChildNode(xMPMetaImpl, xMPNode, node, "", z2);
for (int i2 = 0; i2 < node.getAttributes().getLength(); i2++) {
Node item = node.getAttributes().item(i2);
if (!"xmlns".equals(item.getPrefix()) && (item.getPrefix() != null || !"xmlns".equals(item.getNodeName()))) {
String localName = item.getLocalName();
String namespaceURI = item.getNamespaceURI();
if (XMPConst.XML_LANG.equals(item.getNodeName())) {
addQualifierNode(addChildNode, XMPConst.XML_LANG, item.getNodeValue());
} else if (!"ID".equals(localName) || !XMPConst.NS_RDF.equals(namespaceURI)) {
throw new XMPException("Invalid attribute for resource property element", 202);
}
}
}
boolean z3 = false;
for (int i3 = 0; i3 < node.getChildNodes().getLength(); i3++) {
Node item2 = node.getChildNodes().item(i3);
if (!isWhitespaceNode(item2)) {
if (item2.getNodeType() != 1 || z3) {
if (z3) {
throw new XMPException("Invalid child of resource property element", 202);
}
throw new XMPException("Children of resource property element must be XML elements", 202);
}
boolean equals = XMPConst.NS_RDF.equals(item2.getNamespaceURI());
String localName2 = item2.getLocalName();
if (equals && "Bag".equals(localName2)) {
addChildNode.getOptions().setArray(true);
} else if (equals && "Seq".equals(localName2)) {
addChildNode.getOptions().setArray(true).setArrayOrdered(true);
} else if (equals && "Alt".equals(localName2)) {
addChildNode.getOptions().setArray(true).setArrayOrdered(true).setArrayAlternate(true);
} else {
addChildNode.getOptions().setStruct(true);
if (!equals && !"Description".equals(localName2)) {
String namespaceURI2 = item2.getNamespaceURI();
if (namespaceURI2 == null) {
throw new XMPException("All XML elements must be in a namespace", 203);
}
addQualifierNode(addChildNode, XMPConst.RDF_TYPE, namespaceURI2 + ':' + localName2);
}
}
if (addChildNode.getOptions().isArray() && (num = parseOptions.getXMPNodesToLimit().get(addChildNode.getName())) != null) {
addChildNode.getOptions().setArrayElementLimit(num.intValue());
}
rdf_NodeElement(xMPMetaImpl, addChildNode, item2, false, parseOptions);
if (addChildNode.getHasValueChild()) {
fixupQualifiedNode(addChildNode);
} else if (addChildNode.getOptions().isArrayAlternate()) {
XMPNodeUtils.detectAltText(addChildNode);
}
z3 = true;
}
}
if (!z3) {
throw new XMPException("Missing child of resource property element", 202);
}
}
private static void rdf_LiteralPropertyElement(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2) throws XMPException {
Node item;
XMPNode addChildNode = addChildNode(xMPMetaImpl, xMPNode, node, null, z2);
for (int i2 = 0; i2 < node.getAttributes().getLength(); i2++) {
Node item2 = node.getAttributes().item(i2);
if (!"xmlns".equals(item2.getPrefix()) && (item2.getPrefix() != null || !"xmlns".equals(item2.getNodeName()))) {
String namespaceURI = item2.getNamespaceURI();
String localName = item2.getLocalName();
if (XMPConst.XML_LANG.equals(item2.getNodeName())) {
addQualifierNode(addChildNode, XMPConst.XML_LANG, item2.getNodeValue());
} else if (!XMPConst.NS_RDF.equals(namespaceURI) || (!"ID".equals(localName) && !"datatype".equals(localName))) {
throw new XMPException("Invalid attribute for literal property element", 202);
}
}
}
String str = "";
for (int i3 = 0; i3 < node.getChildNodes().getLength(); i3++) {
if (node.getChildNodes().item(i3).getNodeType() != 3) {
throw new XMPException("Invalid child of literal property element", 202);
}
str = str + item.getNodeValue();
}
addChildNode.setValue(str);
}
private static void rdf_ParseTypeLiteralPropertyElement() throws XMPException {
throw new XMPException("ParseTypeLiteral property element not allowed", 203);
}
private static void rdf_ParseTypeResourcePropertyElement(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2, ParseOptions parseOptions) throws XMPException {
XMPNode addChildNode = addChildNode(xMPMetaImpl, xMPNode, node, "", z2);
addChildNode.getOptions().setStruct(true);
for (int i2 = 0; i2 < node.getAttributes().getLength(); i2++) {
Node item = node.getAttributes().item(i2);
if (!"xmlns".equals(item.getPrefix()) && (item.getPrefix() != null || !"xmlns".equals(item.getNodeName()))) {
String localName = item.getLocalName();
String namespaceURI = item.getNamespaceURI();
if (XMPConst.XML_LANG.equals(item.getNodeName())) {
addQualifierNode(addChildNode, XMPConst.XML_LANG, item.getNodeValue());
} else if (!XMPConst.NS_RDF.equals(namespaceURI) || (!"ID".equals(localName) && !"parseType".equals(localName))) {
throw new XMPException("Invalid attribute for ParseTypeResource property element", 202);
}
}
}
rdf_PropertyElementList(xMPMetaImpl, addChildNode, node, false, parseOptions);
if (addChildNode.getHasValueChild()) {
fixupQualifiedNode(addChildNode);
}
}
private static void rdf_ParseTypeCollectionPropertyElement() throws XMPException {
throw new XMPException("ParseTypeCollection property element not allowed", 203);
}
private static void rdf_ParseTypeOtherPropertyElement() throws XMPException {
throw new XMPException("ParseTypeOther property element not allowed", 203);
}
private static void rdf_EmptyPropertyElement(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, boolean z2) throws XMPException {
boolean z3;
int i2;
if (node.hasChildNodes()) {
throw new XMPException("Nested content not allowed with rdf:resource or property attributes", 202);
}
Node node2 = null;
boolean z4 = false;
boolean z5 = false;
boolean z6 = false;
boolean z7 = false;
for (int i3 = 0; i3 < node.getAttributes().getLength(); i3++) {
Node item = node.getAttributes().item(i3);
if (!"xmlns".equals(item.getPrefix()) && (item.getPrefix() != null || !"xmlns".equals(item.getNodeName()))) {
int rDFTermKind = getRDFTermKind(item);
if (rDFTermKind != 0) {
if (rDFTermKind == 2) {
continue;
} else if (rDFTermKind != 5) {
if (rDFTermKind != 6) {
throw new XMPException("Unrecognized attribute of empty property element", 202);
}
if (z5) {
throw new XMPException("Empty property element can't have both rdf:resource and rdf:nodeID", 202);
}
z7 = true;
} else if (z7) {
throw new XMPException("Empty property element can't have both rdf:resource and rdf:nodeID", 202);
} else {
if (z4) {
throw new XMPException("Empty property element can't have both rdf:value and rdf:resource", 203);
}
if (!z4) {
node2 = item;
}
z5 = true;
}
} else if ("value".equals(item.getLocalName()) && XMPConst.NS_RDF.equals(item.getNamespaceURI())) {
if (z5) {
throw new XMPException("Empty property element can't have both rdf:value and rdf:resource", 203);
}
node2 = item;
z4 = true;
} else if (!XMPConst.XML_LANG.equals(item.getNodeName())) {
z6 = true;
}
}
}
XMPNode addChildNode = addChildNode(xMPMetaImpl, xMPNode, node, "", z2);
if (z4 || z5) {
addChildNode.setValue(node2 != null ? node2.getNodeValue() : "");
if (!z4) {
addChildNode.getOptions().setURI(true);
}
} else if (z6) {
addChildNode.getOptions().setStruct(true);
z3 = true;
for (i2 = 0; i2 < node.getAttributes().getLength(); i2++) {
Node item2 = node.getAttributes().item(i2);
if (item2 != node2 && !"xmlns".equals(item2.getPrefix()) && (item2.getPrefix() != null || !"xmlns".equals(item2.getNodeName()))) {
int rDFTermKind2 = getRDFTermKind(item2);
if (rDFTermKind2 != 0) {
if (rDFTermKind2 != 2) {
if (rDFTermKind2 == 5) {
addQualifierNode(addChildNode, "rdf:resource", item2.getNodeValue());
} else if (rDFTermKind2 != 6) {
throw new XMPException("Unrecognized attribute of empty property element", 202);
}
}
} else if (!z3) {
addQualifierNode(addChildNode, item2.getNodeName(), item2.getNodeValue());
} else if (XMPConst.XML_LANG.equals(item2.getNodeName())) {
addQualifierNode(addChildNode, XMPConst.XML_LANG, item2.getNodeValue());
} else {
addChildNode(xMPMetaImpl, addChildNode, item2, item2.getNodeValue(), false);
}
}
}
}
z3 = false;
while (i2 < node.getAttributes().getLength()) {
}
}
private static XMPNode addChildNode(XMPMetaImpl xMPMetaImpl, XMPNode xMPNode, Node node, String str, boolean z2) throws XMPException {
XMPSchemaRegistry schemaRegistry = XMPMetaFactory.getSchemaRegistry();
String namespaceURI = node.getNamespaceURI();
if (namespaceURI != null) {
if (XMPConst.NS_DC_DEPRECATED.equals(namespaceURI)) {
namespaceURI = "http://purl.org/dc/elements/1.1/";
}
String namespacePrefix = schemaRegistry.getNamespacePrefix(namespaceURI);
if (namespacePrefix == null) {
namespacePrefix = schemaRegistry.registerNamespace(namespaceURI, node.getPrefix() != null ? node.getPrefix() : DEFAULT_PREFIX);
}
String str2 = namespacePrefix + node.getLocalName();
PropertyOptions propertyOptions = new PropertyOptions();
boolean z3 = false;
if (z2) {
xMPNode = XMPNodeUtils.findSchemaNode(xMPMetaImpl.getRoot(), namespaceURI, DEFAULT_PREFIX, true);
xMPNode.setImplicit(false);
if (schemaRegistry.findAlias(str2) != null) {
xMPMetaImpl.getRoot().setHasAliases(true);
xMPNode.setHasAliases(true);
z3 = true;
}
}
boolean isNumberedArrayItemName = isNumberedArrayItemName(str2);
boolean equals = "rdf:value".equals(str2);
XMPNode xMPNode2 = new XMPNode(str2, str, propertyOptions);
xMPNode2.setAlias(z3);
if (!equals) {
xMPNode.addChild(xMPNode2);
} else {
xMPNode.addChild(1, xMPNode2);
}
if (equals) {
if (z2 || !xMPNode.getOptions().isStruct()) {
throw new XMPException("Misplaced rdf:value element", 202);
}
xMPNode.setHasValueChild(true);
}
boolean isArray = xMPNode.getOptions().isArray();
if (isArray && isNumberedArrayItemName) {
xMPNode2.setName("[]");
} else if (!isArray && isNumberedArrayItemName) {
throw new XMPException("Misplaced rdf:li element", 202);
} else {
if (isArray && !isNumberedArrayItemName) {
throw new XMPException("Arrays cannot have arbitrary child names", 202);
}
}
return xMPNode2;
}
throw new XMPException("XML namespace required for all elements and attributes", 202);
}
private static XMPNode addQualifierNode(XMPNode xMPNode, String str, String str2) throws XMPException {
if (XMPConst.XML_LANG.equals(str)) {
str2 = Utils.normalizeLangValue(str2);
}
XMPNode xMPNode2 = new XMPNode(str, str2, null);
xMPNode.addQualifier(xMPNode2);
return xMPNode2;
}
private static void fixupQualifiedNode(XMPNode xMPNode) throws XMPException {
XMPNode child = xMPNode.getChild(1);
if (child.getOptions().getHasLanguage()) {
if (xMPNode.getOptions().getHasLanguage()) {
throw new XMPException("Redundant xml:lang for rdf:value element", 203);
}
XMPNode qualifier = child.getQualifier(1);
child.removeQualifier(qualifier);
xMPNode.addQualifier(qualifier);
}
for (int i2 = 1; i2 <= child.getQualifierLength(); i2++) {
xMPNode.addQualifier(child.getQualifier(i2));
}
for (int i3 = 2; i3 <= xMPNode.getChildrenLength(); i3++) {
xMPNode.addQualifier(xMPNode.getChild(i3));
}
xMPNode.setHasValueChild(false);
xMPNode.getOptions().setStruct(false);
xMPNode.getOptions().mergeWith(child.getOptions());
xMPNode.setValue(child.getValue());
xMPNode.removeChildren();
Iterator iterateChildren = child.iterateChildren();
while (iterateChildren.hasNext()) {
xMPNode.addChild((XMPNode) iterateChildren.next());
}
}
private static boolean isWhitespaceNode(Node node) {
if (node.getNodeType() != 3) {
return false;
}
String nodeValue = node.getNodeValue();
for (int i2 = 0; i2 < nodeValue.length(); i2++) {
if (!Character.isWhitespace(nodeValue.charAt(i2))) {
return false;
}
}
return true;
}
private static boolean isPropertyElementName(int i2) {
if (i2 == 8 || isOldTerm(i2)) {
return false;
}
return !isCoreSyntaxTerm(i2);
}
private static int getRDFTermKind(Node node) {
String localName = node.getLocalName();
String namespaceURI = node.getNamespaceURI();
if (namespaceURI == null && (("about".equals(localName) || "ID".equals(localName)) && (node instanceof Attr) && XMPConst.NS_RDF.equals(((Attr) node).getOwnerElement().getNamespaceURI()))) {
namespaceURI = XMPConst.NS_RDF;
}
if (XMPConst.NS_RDF.equals(namespaceURI)) {
if ("li".equals(localName)) {
return 9;
}
if ("parseType".equals(localName)) {
return 4;
}
if ("Description".equals(localName)) {
return 8;
}
if ("about".equals(localName)) {
return 3;
}
if ("resource".equals(localName)) {
return 5;
}
if ("RDF".equals(localName)) {
return 1;
}
if ("ID".equals(localName)) {
return 2;
}
if ("nodeID".equals(localName)) {
return 6;
}
if ("datatype".equals(localName)) {
return 7;
}
if ("aboutEach".equals(localName)) {
return 10;
}
if ("aboutEachPrefix".equals(localName)) {
return 11;
}
return "bagID".equals(localName) ? 12 : 0;
}
return 0;
}
private static boolean isNumberedArrayItemName(String str) {
boolean equals = "rdf:li".equals(str);
if (str.startsWith("rdf:_")) {
boolean z2 = true;
for (int i2 = 5; i2 < str.length(); i2++) {
z2 = z2 && str.charAt(i2) >= '0' && str.charAt(i2) <= '9';
}
return z2;
}
return equals;
}
}