⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parserdf.java

📁 flash xmp sdk,flash官方SDK
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				{					Node currChild = xmlNode.getChildNodes().item(i);					if (currChild.getNodeType() != Node.TEXT_NODE)					{						rdf_ResourcePropertyElement (xmp, xmpParent, xmlNode, isTopLevel);						return;					}				}								rdf_LiteralPropertyElement (xmp, xmpParent, xmlNode, isTopLevel);			}			else			{				rdf_EmptyPropertyElement (xmp, xmpParent, xmlNode, isTopLevel);			}		}			}		/**	 * 7.2.15 resourcePropertyElt	 *		start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) )	 *		ws* nodeElement ws*	 *		end-element()	 *	 * This handles structs using an rdf:Description node, 	 * arrays using rdf:Bag/Seq/Alt, and typedNodes. It also catches and cleans up qualified 	 * properties written with rdf:Description and rdf:value.	 * 	 * @param xmp the xmp metadata object that is generated	 * @param xmpParent the parent xmp node	 * @param xmlNode the currently processed XML node	 * @param isTopLevel Flag if the node is a top-level node	 * @throws XMPException thown on parsing errors	 */	private static void rdf_ResourcePropertyElement(XMPMetaImpl xmp, XMPNode xmpParent,			Node xmlNode, boolean isTopLevel) throws XMPException	{		if (isTopLevel  &&  "iX:changes".equals(xmlNode.getNodeName()))		{			// Strip old "punchcard" chaff which has on the prefix "iX:".			return;			}				XMPNode newCompound = addChildNode(xmp, xmpParent, xmlNode, "", isTopLevel);				// walk through the attributes		for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)		{			Node attribute = xmlNode.getAttributes().item(i);			if ("xmlns".equals(attribute.getPrefix())  ||					(attribute.getPrefix() == null  &&  "xmlns".equals(attribute.getNodeName())))			{				continue;			}						String attrLocal = attribute.getLocalName();			String attrNS = attribute.getNamespaceURI();			if (XML_LANG.equals(attribute.getNodeName()))			{				addQualifierNode (newCompound, XML_LANG, attribute.getNodeValue());			} 			else if ("ID".equals(attrLocal)  &&  NS_RDF.equals(attrNS))			{				continue;	// Ignore all rdf:ID attributes.			}			else			{				throw new XMPException(					"Invalid attribute for resource property element", BADRDF);			}		}		// walk through the children				Node currChild = null;		boolean found = false;		int i;		for (i = 0; i < xmlNode.getChildNodes().getLength(); i++)		{			currChild = xmlNode.getChildNodes().item(i);			if (!isWhitespaceNode(currChild))			{				if (currChild.getNodeType() == Node.ELEMENT_NODE  &&  !found)				{					boolean isRDF = NS_RDF.equals(currChild.getNamespaceURI());					String childLocal = currChild.getLocalName();										if (isRDF  &&  "Bag".equals(childLocal))					{						newCompound.getOptions().setArray(true);					}					else if (isRDF  &&  "Seq".equals(childLocal))					{						newCompound.getOptions().setArray(true).setArrayOrdered(true);					}					else if (isRDF  &&  "Alt".equals(childLocal))					{						newCompound.getOptions().setArray(true).setArrayOrdered(true)								.setArrayAlternate(true);					}					else					{						newCompound.getOptions().setStruct(true);						if (!isRDF  &&  !"Description".equals(childLocal))						{							String typeName = currChild.getNamespaceURI();							if (typeName == null)							{								throw new XMPException(										"All XML elements must be in a namespace", BADXMP);							}							typeName += ':' + childLocal;							addQualifierNode (newCompound, "rdf:type", typeName);						}					}						rdf_NodeElement (xmp, newCompound, currChild, false);										if (newCompound.getHasValueChild())					{						fixupQualifiedNode (newCompound);					} 					else if (newCompound.getOptions().isArrayAlternate())					{						XMPNodeUtils.detectAltText(newCompound);					}														found = true;					break;				}				else if (found)				{					// found second child element					throw new XMPException(						"Invalid child of resource property element", BADRDF);				}				else				{					throw new XMPException(						"Children of resource property element must be XML elements", BADRDF);				}			}		}				if (!found)		{			// didn't found any child elements			throw new XMPException("Missing child of resource property element", BADRDF);		}	}			/**	 * 7.2.16 literalPropertyElt	 *		start-element ( URI == propertyElementURIs, 	 *				attributes == set ( idAttr?, datatypeAttr?) )	 *		text()	 *		end-element()	 *	 * Add a leaf node with the text value and qualifiers for the attributes.	 * @param xmp the xmp metadata object that is generated	 * @param xmpParent the parent xmp node	 * @param xmlNode the currently processed XML node	 * @param isTopLevel Flag if the node is a top-level node	 * @throws XMPException thown on parsing errors	 */		private static void rdf_LiteralPropertyElement(XMPMetaImpl xmp, XMPNode xmpParent,			Node xmlNode, boolean isTopLevel) throws XMPException	{		XMPNode newChild = addChildNode (xmp, xmpParent, xmlNode, null, isTopLevel);				for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)		{			Node attribute = xmlNode.getAttributes().item(i);			if ("xmlns".equals(attribute.getPrefix())  ||					(attribute.getPrefix() == null  &&  "xmlns".equals(attribute.getNodeName())))			{				continue;			}						String attrNS = attribute.getNamespaceURI();			String attrLocal = attribute.getLocalName();			if (XML_LANG.equals(attribute.getNodeName()))			{				addQualifierNode(newChild, XML_LANG, attribute.getNodeValue());			} 			else if (NS_RDF.equals(attrNS)  &&					 ("ID".equals(attrLocal)  ||  "datatype".equals(attrLocal)))			{				continue;	// Ignore all rdf:ID and rdf:datatype attributes.			}			else			{				throw new XMPException(					"Invalid attribute for literal property element", BADRDF);			}		}		String textValue = "";		for (int i = 0; i < xmlNode.getChildNodes().getLength(); i++)		{			Node child = xmlNode.getChildNodes().item(i);			if (child.getNodeType() == Node.TEXT_NODE)			{				textValue += child.getNodeValue();			}			else			{				throw new XMPException("Invalid child of literal property element", BADRDF);			}		}		newChild.setValue(textValue);	}			/**	 * 7.2.17 parseTypeLiteralPropertyElt	 *		start-element ( URI == propertyElementURIs,	 *			attributes == set ( idAttr?, parseLiteral ) )	 *		literal	 *		end-element()	 * 	 * @throws XMPException thown on parsing errors	 */	private static void rdf_ParseTypeLiteralPropertyElement() throws XMPException	{		throw new XMPException("ParseTypeLiteral property element not allowed", BADXMP);	}		/**	 * 7.2.18 parseTypeResourcePropertyElt	 *		start-element ( URI == propertyElementURIs, 	 *			attributes == set ( idAttr?, parseResource ) )	 *		propertyEltList	 *		end-element()	 *	 * Add a new struct node with a qualifier for the possible rdf:ID attribute. 	 * Then process the XML child nodes to get the struct fields.	 * 	 * @param xmp the xmp metadata object that is generated	 * @param xmpParent the parent xmp node	 * @param xmlNode the currently processed XML node	 * @param isTopLevel Flag if the node is a top-level node	 * @throws XMPException thown on parsing errors	 */	private static void rdf_ParseTypeResourcePropertyElement(XMPMetaImpl xmp, XMPNode xmpParent,			Node xmlNode, boolean isTopLevel) throws XMPException	{		XMPNode newStruct = addChildNode (xmp, xmpParent, xmlNode, "", isTopLevel);				newStruct.getOptions().setStruct(true);		for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)		{			Node attribute = xmlNode.getAttributes().item(i);			if ("xmlns".equals(attribute.getPrefix())  ||					(attribute.getPrefix() == null  &&  "xmlns".equals(attribute.getNodeName())))			{				continue;			}						String attrLocal = attribute.getLocalName();			String attrNS = attribute.getNamespaceURI();			if (XML_LANG.equals(attribute.getNodeName()))			{				addQualifierNode (newStruct, XML_LANG, attribute.getNodeValue());			}			else if (NS_RDF.equals(attrNS)  &&					 ("ID".equals(attrLocal)  ||  "parseType".equals(attrLocal)))			{				continue;	// The caller ensured the value is "Resource".							// Ignore all rdf:ID attributes.			} 			else			{				throw new XMPException("Invalid attribute for ParseTypeResource property element",						BADRDF);			}		}		rdf_PropertyElementList (xmp, newStruct, xmlNode, false);		if (newStruct.getHasValueChild())		{			fixupQualifiedNode (newStruct);		}	}		/**	 * 7.2.19 parseTypeCollectionPropertyElt	 *		start-element ( URI == propertyElementURIs, 	 *			attributes == set ( idAttr?, parseCollection ) )	 *		nodeElementList	 *		end-element()	 *	 * @throws XMPException thown on parsing errors	 */	private static void rdf_ParseTypeCollectionPropertyElement() throws XMPException	{		throw new XMPException("ParseTypeCollection property element not allowed", BADXMP);	}	/**	 * 7.2.20 parseTypeOtherPropertyElt	 *		start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseOther ) )	 *		propertyEltList	 *		end-element()	 * 	 * @throws XMPException thown on parsing errors	 */	private static void rdf_ParseTypeOtherPropertyElement() throws XMPException	{		throw new XMPException("ParseTypeOther property element not allowed", BADXMP);	}	/**	 * 7.2.21 emptyPropertyElt	 *		start-element ( URI == propertyElementURIs,	 *						attributes == set (	 *							idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) )	 *		end-element()	 *	 *	<ns:Prop1/>  <!-- a simple property with an empty value --> 	 *	<ns:Prop2 rdf:resource="http: *www.adobe.com/"/> <!-- a URI value --> 	 *	<ns:Prop3 rdf:value="..." ns:Qual="..."/> <!-- a simple qualified property --> 	 *	<ns:Prop4 ns:Field1="..." ns:Field2="..."/> <!-- a struct with simple fields -->	 *	 * An emptyPropertyElt is an element with no contained content, just a possibly empty set of	 * attributes. An emptyPropertyElt can represent three special cases of simple XMP properties: a	 * simple property with an empty value (ns:Prop1), a simple property whose value is a URI	 * (ns:Prop2), or a simple property with simple qualifiers (ns:Prop3). 	 * An emptyPropertyElt can also represent an XMP struct whose fields are all simple and 	 * unqualified (ns:Prop4).	 *	 * It is an error to use both rdf:value and rdf:resource - that can lead to invalid  RDF in the	 * verbose form written using a literalPropertyElt.	 *	 * The XMP mapping for an emptyPropertyElt is a bit different from generic RDF, partly for 	 * design reasons and partly for historical reasons. The XMP mapping rules are:	 * <ol> 	 *		<li> If there is an rdf:value attribute then this is a simple property	 *				 with a text value.	 *		All other attributes are qualifiers.	 *		<li> If there is an rdf:resource attribute then this is a simple property 	 *			with a URI value. 	 *		All other attributes are qualifiers.	 *		<li> If there are no attributes other than xml:lang, rdf:ID, or rdf:nodeID	 *				then this is a simple 	 *		property with an empty value. 	 *		<li> Otherwise this is a struct, the attributes other than xml:lang, rdf:ID, 	 *				or rdf:nodeID are fields. 	 * </ol>	 * 	 * @param xmp the xmp metadata object that is generated	 * @param xmpParent the parent xmp node	 * @param xmlNode the currently processed XML node	 * @param isTopLevel Flag if the node is a top-level node	 * @throws XMPException thown on parsing errors	 */	private static void rdf_EmptyPropertyElement(XMPMetaImpl xmp, XMPNode xmpParent, Node xmlNode,			boolean isTopLevel) throws XMPException	{		boolean hasPropertyAttrs = false;		boolean hasResourceAttr = false;		boolean hasNodeIDAttr = false;		boolean hasValueAttr = false;				Node valueNode = null;	// ! Can come from rdf:value or rdf:resource.				if (xmlNode.hasChildNodes())		{			throw new XMPException(					"Nested content not allowed with rdf:resource or property attributes",					BADRDF);		}				// First figure out what XMP this maps to and remember the XML node for a simple value.		for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)		{			Node attribute = xmlNode.getAttributes().item(i);			if ("xmlns".equals(attribute.getPrefix())  ||					(attribute.getPrefix() == null  &&  "xmlns".equals(attribute.getNodeName())))			{				continue;			}						int attrTerm = getRDFTermKind (attribute);			switch (attrTerm)			{				case RDFTERM_ID :					// Nothing to do.					break;				case RDFTERM_RESOURCE :					if (hasNodeIDAttr)					{						throw new XMPException(							"Empty property element can't have both rdf:resource and rdf:nodeID",							BADRDF);					}					else if (hasValueAttr)					{						throw new XMPException(								"Empty property element can't have both rdf:value and rdf:resource",								BADXMP);					}					hasResourceAttr = true;					if (!hasValueAttr) 					{						valueNode = attribute;					}						break;				case RDFTERM_NODE_ID:				if (hasResourceAttr)				{					throw new XMPException(							"Empty property element can't have both rdf:resource and rdf:nodeID",							BADRDF);				}				hasNodeIDAttr = true;				break;			case RDFTERM_OTHER:				if ("value".equals(attribute.getLocalName())						&& NS_RDF.equals(attribute.getNamespaceURI()))				{					if (hasResourceAttr)					{						throw new XMPException(								"Empty property element can't have both rdf:value and rdf:resource",								BADXMP);					}					hasValueAttr = true;					valueNode = attribute;				}				else if (!XML_LANG.equals(attribute.getNodeName()))				{					hasPropertyAttrs = true;				}				break;			default:				throw new XMPException("Unrecognized attribute of empty property element",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -