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

📄 xmpmetaimpl.java

📁 flash xmp sdk,flash官方SDK
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	/**	 * @see XMPMeta#getPropertyBase64(String, String)	 */	public byte[] getPropertyBase64(String schemaNS, String propName) throws XMPException	{		return (byte[]) getPropertyObject(schemaNS, propName, VALUE_BASE64);	}	/**	 * @see XMPMeta#getPropertyString(String, String)	 */	public String getPropertyString(String schemaNS, String propName) throws XMPException	{		return (String) getPropertyObject(schemaNS, propName, VALUE_STRING);	}	/**	 * @see XMPMeta#setPropertyBase64(String, String, byte[], PropertyOptions)	 */	public void setPropertyBase64(String schemaNS, String propName, byte[] propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, propValue, options);	}		/**	 * @see XMPMeta#setPropertyBase64(String, String, byte[])	 */	public void setPropertyBase64(String schemaNS, String propName, byte[] propValue)			throws XMPException	{		setProperty(schemaNS, propName, propValue, null);	}		/**	 * @throws XMPException	 * @see XMPMeta#getQualifier(String, String, String, String)	 */	public XMPProperty getQualifier(String schemaNS, String propName, String qualNS, 		String qualName) throws XMPException	{		// qualNS and qualName are checked inside composeQualfierPath		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertPropName(propName);		String qualPath = propName + XMPPathFactory.composeQualifierPath(qualNS, qualName);		return getProperty(schemaNS, qualPath);	}	/**	 * @see XMPMeta#getStructField(String, String, String, String)	 */	public XMPProperty getStructField(String schemaNS, String structName, String fieldNS,			String fieldName) throws XMPException	{		// fieldNS and fieldName are checked inside composeStructFieldPath		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertStructName(structName);		String fieldPath = structName + XMPPathFactory.composeStructFieldPath(fieldNS, fieldName);		return getProperty(schemaNS, fieldPath);	}	/**	 * @throws XMPException	 * @see XMPMeta#iterator()	 */	public XMPIterator iterator() throws XMPException	{		return iterator(null, null, null);	}	/**	 * @see XMPMeta#iterator(IteratorOptions)	 */	public XMPIterator iterator(IteratorOptions options) throws XMPException	{		return iterator(null, null, options);	}	/**	 * @see XMPMeta#iterator(String, String, IteratorOptions)	 */	public XMPIterator iterator(String schemaNS, String propName, IteratorOptions options)			throws XMPException	{		return new XMPIteratorImpl(this, schemaNS, propName, options);	}	/**	 * @throws XMPException	 * @see XMPMeta#setArrayItem(String, String, int, String, PropertyOptions)	 */	public void setArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue,			PropertyOptions options) throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertArrayName(arrayName);		// Just lookup, don't try to create.		XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName);		XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null);		if (arrayNode != null)		{			doSetArrayItem(arrayNode, itemIndex, itemValue, options, false);		}		else		{			throw new XMPException("Specified array does not exist", XMPError.BADXPATH);		}	}		/**	 * @see XMPMeta#setArrayItem(String, String, int, String)	 */	public void setArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue)			throws XMPException	{		setArrayItem(schemaNS, arrayName, itemIndex, itemValue, null);	}		/**	 * @throws XMPException	 * @see XMPMeta#insertArrayItem(String, String, int, String,	 *      PropertyOptions)	 */	public void insertArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue,			PropertyOptions options) throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertArrayName(arrayName);		// Just lookup, don't try to create.		XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName);		XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null);		if (arrayNode != null)		{			doSetArrayItem(arrayNode, itemIndex, itemValue, options, true);		}		else		{			throw new XMPException("Specified array does not exist", XMPError.BADXPATH);		}	}		/**	 * @see XMPMeta#insertArrayItem(String, String, int, String)	 */	public void insertArrayItem(String schemaNS, String arrayName, int itemIndex, String itemValue)			throws XMPException	{		insertArrayItem(schemaNS, arrayName, itemIndex, itemValue, null);	}		/**	 * @throws XMPException	 * @see XMPMeta#setProperty(String, String, Object, PropertyOptions)	 */	public void setProperty(String schemaNS, String propName, Object propValue,			PropertyOptions options) throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertPropName(propName);		options = XMPNodeUtils.verifySetOptions(options, propValue);		XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName);		XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, true, options);		if (propNode != null)		{			setNode(propNode, propValue, options, false);		}		else		{			throw new XMPException("Specified property does not exist", XMPError.BADXPATH);		}	}		/**	 * @see XMPMeta#setProperty(String, String, Object)	 */	public void setProperty(String schemaNS, String propName, Object propValue) throws XMPException	{		setProperty(schemaNS, propName, propValue, null);	}		/**	 * @throws XMPException	 * @see XMPMeta#setQualifier(String, String, String, String, String,	 *      PropertyOptions)	 */	public void setQualifier(String schemaNS, String propName, String qualNS, String qualName,			String qualValue, PropertyOptions options) throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertPropName(propName);		if (!doesPropertyExist(schemaNS, propName))		{			throw new XMPException("Specified property does not exist!", XMPError.BADXPATH);		}		String qualPath = propName + XMPPathFactory.composeQualifierPath(qualNS, qualName);		setProperty(schemaNS, qualPath, qualValue, options);	}		/**	 * @see XMPMeta#setQualifier(String, String, String, String, String)	 */	public void setQualifier(String schemaNS, String propName, String qualNS, String qualName,			String qualValue) throws XMPException	{		setQualifier(schemaNS, propName, qualNS, qualName, qualValue, null);			}		/**	 * @see XMPMeta#setStructField(String, String, String, String, String,	 *      PropertyOptions)	 */	public void setStructField(String schemaNS, String structName, String fieldNS,			String fieldName, String fieldValue, PropertyOptions options) throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertStructName(structName);		String fieldPath = structName + XMPPathFactory.composeStructFieldPath(fieldNS, fieldName);		setProperty(schemaNS, fieldPath, fieldValue, options);	}		/**	 * @see XMPMeta#setStructField(String, String, String, String, String)	 */	public void setStructField(String schemaNS, String structName, String fieldNS,			String fieldName, String fieldValue) throws XMPException	{		setStructField(schemaNS, structName, fieldNS, fieldName, fieldValue, null);	}		/**	 * @see XMPMeta#getObjectName()	 */	public String getObjectName()	{		return tree.getName() != null ? tree.getName() : "";	}	/**	 * @see XMPMeta#setObjectName(String)	 */	public void setObjectName(String name)	{		tree.setName(name);	}	/**	 * Performs a deep clone of the XMPMeta-object	 * 	 * @see java.lang.Object#clone()	 */	public Object clone()	{		XMPNode clonedTree = (XMPNode) tree.clone();		return new XMPMetaImpl(clonedTree);	}	/**	 * @see XMPMeta#dumpObject()	 */	public String dumpObject()	{		// renders tree recursively		return getRoot().dumpNode(true);	}		/**	 * @see XMPMeta#sort()	 */	public void sort()	{		this.tree.sort();	}	/**	 * @return Returns the root node of the XMP tree.	 */	public XMPNode getRoot()	{		return tree;	}	// -------------------------------------------------------------------------------------	// private	/**	 * Locate or create the item node and set the value. Note the index	 * parameter is one-based! The index can be in the range [1..size + 1] or	 * "last()", normalize it and check the insert flags. The order of the	 * normalization checks is important. If the array is empty we end up with	 * an index and location to set item size + 1.	 * 	 * @param arrayNode an array node	 * @param itemIndex the index where to insert the item	 * @param itemValue the item value	 * @param itemOptions the options for the new item	 * @param insert insert oder overwrite at index position?	 * @throws XMPException	 */	private void doSetArrayItem(XMPNode arrayNode, int itemIndex, String itemValue,			PropertyOptions itemOptions, boolean insert) throws XMPException	{		XMPNode itemNode = new XMPNode(ARRAY_ITEM_NAME, null);		itemOptions = XMPNodeUtils.verifySetOptions(itemOptions, itemValue);		// in insert mode the index after the last is allowed,		// even ARRAY_LAST_ITEM points to the index *after* the last.		int maxIndex = insert ? arrayNode.getChildrenLength() + 1 : arrayNode.getChildrenLength();		if (itemIndex == ARRAY_LAST_ITEM)		{			itemIndex = maxIndex;		}		if (1 <= itemIndex && itemIndex <= maxIndex)		{			if (!insert)			{				arrayNode.removeChild(itemIndex);			}			arrayNode.addChild(itemIndex, itemNode);			setNode(itemNode, itemValue, itemOptions, false);		}		else		{			throw new XMPException("Array index out of bounds", XMPError.BADINDEX);		}	}	/**	 * The internals for setProperty() and related calls, used after the node is	 * found or created.	 * 	 * @param node	 *            the newly created node	 * @param value	 *            the node value, can be <code>null</code>	 * @param newOptions	 *            options for the new node, must not be <code>null</code>.	 * @param deleteExisting flag if the existing value is to be overwritten 	 * @throws XMPException thrown if options and value do not correspond	 */	void setNode(XMPNode node, Object value, PropertyOptions newOptions, boolean deleteExisting)			throws XMPException	{		if (deleteExisting)		{			node.clear();		}		// its checked by setOptions(), if the merged result is a valid options set		node.getOptions().mergeWith(newOptions);		if (!node.getOptions().isCompositeProperty())		{			// This is setting the value of a leaf node.			XMPNodeUtils.setNodeValue(node, value);		}		else		{			if (value != null && value.toString().length() > 0)			{				throw new XMPException("Composite nodes can't have values", XMPError.BADXPATH);			}			node.removeChildren();		}	}	/**	 * Evaluates a raw node value to the given value type, apply special	 * conversions for defined types in XMP.	 * 	 * @param valueType	 *            an int indicating the value type	 * @param propNode	 *            the node containing the value	 * @return Returns a literal value for the node.	 * @throws XMPException	 */	private Object evaluateNodeValue(int valueType, final XMPNode propNode) throws XMPException	{		final Object value;		String rawValue = propNode.getValue();		switch (valueType)		{		case VALUE_BOOLEAN:			value = new Boolean(XMPUtils.convertToBoolean(rawValue));			break;		case VALUE_INTEGER:			value = new Integer(XMPUtils.convertToInteger(rawValue));			break;		case VALUE_LONG:			value = new Long(XMPUtils.convertToLong(rawValue));			break;		case VALUE_DOUBLE:			value = new Double(XMPUtils.convertToDouble(rawValue));			break;		case VALUE_DATE:			value = XMPUtils.convertToDate(rawValue);			break;		case VALUE_CALENDAR:			XMPDateTime dt = XMPUtils.convertToDate(rawValue);			value = dt.getCalendar();			break;		case VALUE_BASE64:			value = XMPUtils.decodeBase64(rawValue);			break;		case VALUE_STRING:		default:			// leaf values return empty string instead of null			// for the other cases the converter methods provides a "null"			// value.			// a default value can only occur if this method is made public.			value = rawValue != null || propNode.getOptions().isCompositeProperty() ? rawValue : "";			break;		}		return value;	}}

⌨️ 快捷键说明

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