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

📄 xmpmetaimpl.java

📁 flash xmp sdk,flash官方SDK
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				arrayNode.getOptions().setArrayAltText(true);			}			else			{				throw new XMPException(					"Specified property is no alt-text array", XMPError.BADXPATH);			}		}		// Make sure the x-default item, if any, is first.		boolean haveXDefault = false;		XMPNode xdItem = null;		for (Iterator it = arrayNode.iterateChildren(); it.hasNext();)		{			XMPNode currItem = (XMPNode) it.next();			if (!currItem.hasQualifier()					|| !XMPConst.XML_LANG.equals(currItem.getQualifier(1).getName()))			{				throw new XMPException("Language qualifier must be first", XMPError.BADXPATH);			}			else if (XMPConst.X_DEFAULT.equals(currItem.getQualifier(1).getValue()))			{				xdItem = currItem;				haveXDefault = true;				break;			}		}		// Moves x-default to the beginning of the array		if (xdItem != null  &&  arrayNode.getChildrenLength() > 1)		{			arrayNode.removeChild(xdItem);			arrayNode.addChild(1, xdItem);		}		// Find the appropriate item.		// chooseLocalizedText will make sure the array is a language		// alternative.		Object[] result = XMPNodeUtils.chooseLocalizedText(arrayNode, genericLang, specificLang);		int match = ((Integer) result[0]).intValue();		XMPNode itemNode = (XMPNode) result[1];		boolean specificXDefault = XMPConst.X_DEFAULT.equals(specificLang);		switch (match)		{		case XMPNodeUtils.CLT_NO_VALUES:			// Create the array items for the specificLang and x-default, with			// x-default first.			XMPNodeUtils.appendLangItem(arrayNode, XMPConst.X_DEFAULT, itemValue);			haveXDefault = true;			if (!specificXDefault)			{				XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);			}			break;		case XMPNodeUtils.CLT_SPECIFIC_MATCH:			if (!specificXDefault)			{				// Update the specific item, update x-default if it matches the				// old value.				if (haveXDefault && xdItem != itemNode && xdItem != null						&& xdItem.getValue().equals(itemNode.getValue()))				{					xdItem.setValue(itemValue);				}				// ! Do this after the x-default check!				itemNode.setValue(itemValue);			}			else			{				// Update all items whose values match the old x-default value.				assert  haveXDefault  &&  xdItem == itemNode;				for (Iterator it = arrayNode.iterateChildren(); it.hasNext();)				{					XMPNode currItem = (XMPNode) it.next();					if (currItem == xdItem							|| !currItem.getValue().equals(									xdItem != null ? xdItem.getValue() : null))					{						continue;					}					currItem.setValue(itemValue);				}				// And finally do the x-default item.				if (xdItem != null)				{						xdItem.setValue(itemValue);				}				}			break;		case XMPNodeUtils.CLT_SINGLE_GENERIC:			// Update the generic item, update x-default if it matches the old			// value.			if (haveXDefault && xdItem != itemNode && xdItem != null					&& xdItem.getValue().equals(itemNode.getValue()))			{				xdItem.setValue(itemValue);			}			itemNode.setValue(itemValue); // ! Do this after			// the x-default			// check!			break;		case XMPNodeUtils.CLT_MULTIPLE_GENERIC:			// Create the specific language, ignore x-default.			XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);			if (specificXDefault)			{				haveXDefault = true;			}			break;		case XMPNodeUtils.CLT_XDEFAULT:			// Create the specific language, update x-default if it was the only			// item.			if (xdItem != null  &&  arrayNode.getChildrenLength() == 1)			{				xdItem.setValue(itemValue);			}			XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);			break;		case XMPNodeUtils.CLT_FIRST_ITEM:			// Create the specific language, don't add an x-default item.			XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);			if (specificXDefault)			{				haveXDefault = true;			}			break;		default:			// does not happen under normal circumstances			throw new XMPException("Unexpected result from ChooseLocalizedText",					XMPError.INTERNALFAILURE);		}		// Add an x-default at the front if needed.		if (!haveXDefault && arrayNode.getChildrenLength() == 1)		{			XMPNodeUtils.appendLangItem(arrayNode, XMPConst.X_DEFAULT, itemValue);		}	}		/**	 * @see XMPMeta#setLocalizedText(String, String, String, String, String)	 */	public void setLocalizedText(String schemaNS, String altTextName, String genericLang,			String specificLang, String itemValue) throws XMPException	{		setLocalizedText(schemaNS, altTextName, genericLang, specificLang, itemValue, null);	}		/**	 * @throws XMPException	 * @see XMPMeta#getProperty(String, String)	 */	public XMPProperty getProperty(String schemaNS, String propName) throws XMPException	{		return getProperty(schemaNS, propName, VALUE_STRING);	}	/**	 * Returns a property, but the result value can be requested. It can be one	 * of {@link XMPMetaImpl#VALUE_STRING}, {@link XMPMetaImpl#VALUE_BOOLEAN},	 * {@link XMPMetaImpl#VALUE_INTEGER}, {@link XMPMetaImpl#VALUE_LONG},	 * {@link XMPMetaImpl#VALUE_DOUBLE}, {@link XMPMetaImpl#VALUE_DATE},	 * {@link XMPMetaImpl#VALUE_CALENDAR}, {@link XMPMetaImpl#VALUE_BASE64}.	 * 	 * @see XMPMeta#getProperty(String, String)	 * @param schemaNS	 *            a schema namespace	 * @param propName	 *            a property name or path	 * @param valueType	 *            the type of the value, see VALUE_...	 * @return Returns an <code>XMPProperty</code>	 * @throws XMPException	 *             Collects any exception that occurs.	 */	protected XMPProperty getProperty(String schemaNS, String propName, int valueType)			throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertPropName(propName);		final XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName);		final XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, false, null);		if (propNode != null)		{			if (valueType != VALUE_STRING && propNode.getOptions().isCompositeProperty())			{				throw new XMPException("Property must be simple when a value type is requested",						XMPError.BADXPATH);			}			final Object value = evaluateNodeValue(valueType, propNode);			return new XMPProperty()			{				public Object getValue()				{					return value;				}				public PropertyOptions getOptions()				{					return propNode.getOptions();				}				public String getLanguage()				{					return null;				}				public String toString()				{					return value.toString();				}			};		}		else		{			return null;		}	}	/**	 * Returns a property, but the result value can be requested.	 * 	 * @see XMPMeta#getProperty(String, String)	 * @param schemaNS	 *            a schema namespace	 * @param propName	 *            a property name or path	 * @param valueType	 *            the type of the value, see VALUE_...	 * @return Returns the node value as an object according to the	 *         <code>valueType</code>.	 * @throws XMPException	 *             Collects any exception that occurs.	 */	protected Object getPropertyObject(String schemaNS, String propName, int valueType)			throws XMPException	{		ParameterAsserts.assertSchemaNS(schemaNS);		ParameterAsserts.assertPropName(propName);		final XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName);		final XMPNode propNode = XMPNodeUtils.findNode(tree, expPath, false, null);		if (propNode != null)		{			if (valueType != VALUE_STRING && propNode.getOptions().isCompositeProperty())			{				throw new XMPException("Property must be simple when a value type is requested",						XMPError.BADXPATH);			}			return evaluateNodeValue(valueType, propNode);		}		else		{			return null;		}	}	/**	 * @see XMPMeta#getPropertyBoolean(String, String)	 */	public Boolean getPropertyBoolean(String schemaNS, String propName) throws XMPException	{		return (Boolean) getPropertyObject(schemaNS, propName, VALUE_BOOLEAN);	}	/**	 * @throws XMPException	 * @see XMPMeta#setPropertyBoolean(String, String, boolean, PropertyOptions)	 */	public void setPropertyBoolean(String schemaNS, String propName, boolean propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, propValue ? TRUESTR : FALSESTR, options);	}		/**	 * @see XMPMeta#setPropertyBoolean(String, String, boolean)	 */	public void setPropertyBoolean(String schemaNS, String propName, boolean propValue)			throws XMPException	{		setProperty(schemaNS, propName, propValue ? TRUESTR : FALSESTR, null);	}		/**	 * @see XMPMeta#getPropertyInteger(String, String)	 */	public Integer getPropertyInteger(String schemaNS, String propName) throws XMPException	{		return (Integer) getPropertyObject(schemaNS, propName, VALUE_INTEGER);	}	/**	 * @see XMPMeta#setPropertyInteger(String, String, int, PropertyOptions)	 */	public void setPropertyInteger(String schemaNS, String propName, int propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, new Integer(propValue), options);	}		/**	 * @see XMPMeta#setPropertyInteger(String, String, int)	 */	public void setPropertyInteger(String schemaNS, String propName, int propValue)			throws XMPException	{		setProperty(schemaNS, propName, new Integer(propValue), null);	}		/**	 * @see XMPMeta#getPropertyLong(String, String)	 */	public Long getPropertyLong(String schemaNS, String propName) throws XMPException	{		return (Long) getPropertyObject(schemaNS, propName, VALUE_LONG);	}	/**	 * @see XMPMeta#setPropertyLong(String, String, long, PropertyOptions)	 */	public void setPropertyLong(String schemaNS, String propName, long propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, new Long(propValue), options);	}	/**	 * @see XMPMeta#setPropertyLong(String, String, long)	 */	public void setPropertyLong(String schemaNS, String propName, long propValue)			throws XMPException	{		setProperty(schemaNS, propName, new Long(propValue), null);	}		/**	 * @see XMPMeta#getPropertyDouble(String, String)	 */	public Double getPropertyDouble(String schemaNS, String propName) throws XMPException	{		return (Double) getPropertyObject(schemaNS, propName, VALUE_DOUBLE);	}	/**	 * @see XMPMeta#setPropertyDouble(String, String, double, PropertyOptions)	 */	public void setPropertyDouble(String schemaNS, String propName, double propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, new Double(propValue), options);	}		/**	 * @see XMPMeta#setPropertyDouble(String, String, double)	 */	public void setPropertyDouble(String schemaNS, String propName, double propValue)			throws XMPException	{		setProperty(schemaNS, propName, new Double(propValue), null);	}		/**	 * @see XMPMeta#getPropertyDate(String, String)	 */	public XMPDateTime getPropertyDate(String schemaNS, String propName) throws XMPException	{		return (XMPDateTime) getPropertyObject(schemaNS, propName, VALUE_DATE);	}	/**	 * @see XMPMeta#setPropertyDate(String, String, XMPDateTime,	 *      PropertyOptions)	 */	public void setPropertyDate(String schemaNS, String propName, XMPDateTime propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, propValue, options);	}		/**	 * @see XMPMeta#setPropertyDate(String, String, XMPDateTime)	 */	public void setPropertyDate(String schemaNS, String propName, XMPDateTime propValue)			throws XMPException	{		setProperty(schemaNS, propName, propValue, null);	}		/**	 * @see XMPMeta#getPropertyCalendar(String, String)	 */	public Calendar getPropertyCalendar(String schemaNS, String propName) throws XMPException	{		return (Calendar) getPropertyObject(schemaNS, propName, VALUE_CALENDAR);	}	/**	 * @see XMPMeta#setPropertyCalendar(String, String, Calendar,	 *      PropertyOptions)	 */	public void setPropertyCalendar(String schemaNS, String propName, Calendar propValue,			PropertyOptions options) throws XMPException	{		setProperty(schemaNS, propName, propValue, options);	}		/**	 * @see XMPMeta#setPropertyCalendar(String, String, Calendar)	 */	public void setPropertyCalendar(String schemaNS, String propName, Calendar propValue)			throws XMPException	{		setProperty(schemaNS, propName, propValue, null);	}	

⌨️ 快捷键说明

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