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

📄 xmpcorecoverage.java

📁 flash xmp sdk,flash官方SDK
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * @throws XMPException Forwards exceptions	 */	private static void coverLinefeedValues() throws XMPException	{		writeMajorLabel ("Test CR and LF in values");				String valueWithCR		= "ASCII \r CR";		String valueWithLF		= "ASCII \n LF";		String valueWithCRLF	= "ASCII \r\n CRLF";			XMPMeta meta = XMPMetaFactory.parseFromString(NEWLINE_RDF);			meta.setProperty (NS2, "HasCR", valueWithCR);		meta.setProperty (NS2, "HasLF", valueWithLF);		meta.setProperty (NS2, "HasCRLF", valueWithCRLF);			String result = XMPMetaFactory.serializeToString(meta, new SerializeOptions()				.setOmitPacketWrapper(true));		println(result);				String hasCR = meta.getPropertyString (NS1, "HasCR");		String hasCR2 = meta.getPropertyString (NS2, "HasCR");		String hasLF = meta.getPropertyString (NS1, "HasLF");    		String hasLF2 = meta.getPropertyString (NS2, "HasLF");		String hasCRLF = meta.getPropertyString (NS1, "HasCRLF");		String hasCRLF2 = meta.getPropertyString (NS2, "HasCRLF");		if (hasCR.equals(valueWithCR)  &&  hasCR2.equals(valueWithCR)  &&			hasLF.equals(valueWithLF)  &&  hasLF2.equals(valueWithLF)  &&			hasCRLF.equals(valueWithCRLF)  &&  hasCRLF2.equals(valueWithCRLF))		{			println();			println("\n## HasCR and HasLF and HasCRLF correctly retrieved\n");		}	}				/**	 * Covers the serialization of an <code>XMPMeta</code> object with different options.	 * @throws Exception Forwards exceptions 	 */	private static void coverSerialization() throws Exception	{		writeMajorLabel ("Test serialization with various options");		XMPMeta meta = XMPMetaFactory.parseFromString(SIMPLE_RDF);		meta.setProperty (NS2, "Another", "Something in another schema");		meta.setProperty (NS2, "Yet/pdf:More", "Yet more in another schema");		printXMPMeta (meta, "Parse simple RDF, serialize with various options");		writeMinorLabel ("Default serialize");		println(XMPMetaFactory.serializeToString(meta, null));		writeMinorLabel ("Compact RDF, no packet serialize");		println(XMPMetaFactory.serializeToString(meta, new SerializeOptions().setUseCompactFormat(				true).setOmitPacketWrapper(true)));		writeMinorLabel ("Read-only serialize");		println(XMPMetaFactory.serializeToString(meta, new SerializeOptions()				.setReadOnlyPacket(true)));		writeMinorLabel ("Alternate newline serialize");		println(XMPMetaFactory.serializeToString(meta, new SerializeOptions().setNewline(				"<--newline-->\n").setOmitPacketWrapper(true)));		writeMinorLabel ("Alternate indent serialize");		println(XMPMetaFactory.serializeToString(meta, new SerializeOptions().setIndent("-->")				.setBaseIndent(5).setOmitPacketWrapper(true)));		writeMinorLabel ("Small padding serialize");		println(XMPMetaFactory.serializeToString(meta, new SerializeOptions().setPadding(10)));		writeMinorLabel ("Serialize with exact packet size");		int s = XMPMetaFactory.serializeToBuffer(meta, new SerializeOptions()				.setReadOnlyPacket(true)).length;		println ("Minimum packet size is " + s + " bytes\n");		// with the flag "exact packet size" the padding becomes the overall length of the packet		byte[] buffer = XMPMetaFactory.serializeToBuffer(meta, new SerializeOptions()				.setExactPacketLength(true).setPadding(s));		println(new String(buffer, "UTF-8"));		try		{			XMPMetaFactory.parseFromString(XMPMetaFactory.serializeToString(meta,					new SerializeOptions().setExactPacketLength(true).setPadding(s - 1)));		}		catch (XMPException e)		{			println("\nExact packet size smaller than minimal packet length - " +				"threw XMPException #" + e.getErrorCode() + " :   " + e.getMessage());		}	}			/**	 * Cover different use cases of the <code>XMPIterator</code>. 	 * @throws XMPException Forwards exceptions	 */	private static void coverIterator() throws XMPException	{		writeMajorLabel ("Test iteration methods");			XMPMeta meta = XMPMetaFactory.parseFromString(RDF_COVERAGE);		meta.setProperty (NS2, "Prop", "Prop value");		meta.appendArrayItem (NS2, "Bag", new PropertyOptions().setArray(true),			"BagItem 2", null);		meta.appendArrayItem(NS2, "Bag", "BagItem 1");		meta.appendArrayItem(NS2, "Bag", "BagItem 3");			printXMPMeta (meta, "Parse \"coverage\" RDF, add Bag items out of order");			writeMinorLabel ("Default iteration");		for (XMPIterator it = meta.iterator(); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}				writeMinorLabel ("Iterate omitting qualifiers");		for (XMPIterator it = meta.iterator(new IteratorOptions().setOmitQualifiers(true)); it				.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}			writeMinorLabel("Iterate with just leaf names");		for (XMPIterator it = meta.iterator(new IteratorOptions().setJustLeafname(true)); it				.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}		writeMinorLabel("Iterate with just leaf nodes");		for (XMPIterator it = meta.iterator(new IteratorOptions().setJustLeafnodes(true)); it				.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}		writeMinorLabel("Iterate just the schema nodes");		for (XMPIterator it = meta.iterator(new IteratorOptions().setJustChildren(true)); it				.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}			writeMinorLabel("Iterate the ns2: namespace");		for (XMPIterator it = meta.iterator(NS2, null, null); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}		writeMinorLabel("Start at ns2:Bag");		for (XMPIterator it = meta.iterator(NS2, "Bag", null); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}		writeMinorLabel("Start at ns2:NestedStructProp/ns1:Outer");		for (XMPIterator it = meta.iterator(NS2, "NestedStructProp/ns1:Outer", null); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}		writeMinorLabel("Iterate an empty namespace");		for (XMPIterator it = meta.iterator("ns:Empty", null, null); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}				writeMinorLabel("Iterate the top of the ns2: namespace with just leaf names");		for (XMPIterator it = meta.iterator(NS2, null, new IteratorOptions().setJustChildren(true)				.setJustLeafname(true)); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}		writeMinorLabel("Iterate the top of the ns2: namespace with just leaf nodes");		for (XMPIterator it = meta.iterator(NS2, null, new IteratorOptions().setJustChildren(true)				.setJustLeafnodes(true)); it.hasNext();)		{			XMPPropertyInfo prop = (XMPPropertyInfo) it.next();			printPropertyInfo(prop);		}	}	/**	 * XPath composition utilities using the <code>XMPPathFactory</code>.	 * @throws XMPException Forwards exceptions	 */	private static void coverPathCreation() throws XMPException	{		writeMajorLabel ("XPath composition utilities");		XMPMeta meta = XMPMetaFactory.create(); 				meta.appendArrayItem(NS1, "ArrayProp", new PropertyOptions().setArray(true), 			"Item 1", null);				String path = XMPPathFactory.composeArrayItemPath("ArrayProp", 2);		println ("composeArrayItemPath ArrayProp[2] =   " + path);		meta.setProperty (NS1, path, "new ns1:ArrayProp[2] value");		path = "StructProperty";		path += XMPPathFactory.composeStructFieldPath(NS2, "Field3");		println ("composeStructFieldPath StructProperty/ns2:Field3 =   " + path);		meta.setProperty (NS1, path, "new ns1:StructProp/ns2:Field3 value");		path = "QualProp";		path += XMPPathFactory.composeQualifierPath(NS2, "Qual");		println ("composeStructFieldPath QualProp/?ns2:Qual =   " + path);		meta.setProperty (NS1, path, "new ns1:QualProp/?ns2:Qual value");		meta.setLocalizedText(NS1, "AltTextProp", null, "en-US", "initival value");		path = "AltTextProp";		path += XMPPathFactory.composeQualifierPath(XMPConst.NS_XML, "lang");		println ("composeQualifierPath ns1:AltTextProp/?xml:lang =   " + path);		meta.setProperty (NS1, path, "new ns1:AltTextProp/?xml:lang value");		printXMPMeta (meta, "Modified simple RDF");	}		/**	 * Date/Time utilities	 */	private static void coverDateTime()	{		writeMajorLabel ("Test date/time utilities and special values");			XMPDateTime	date1	= XMPDateTimeFactory.create(2000, 1, 31, 12, 34, 56, -1);		date1.setTimeZone(TimeZone.getTimeZone("PST"));		XMPDateTime	date2	= XMPDateTimeFactory.create(0, 0, 0, 0, 0, 0, 0);		Calendar cal = new GregorianCalendar(2007, 1, 28);		XMPDateTime	date3	= XMPDateTimeFactory.createFromCalendar(cal);		XMPDateTime currentDateTime = XMPDateTimeFactory.getCurrentDateTime();		println("Print date 2000 Jan 31 12:34:56 PST =   " + date1.toString());		println("Print zero date =   " + date2.toString());		println("Print date created by a calendar =   " + date3.toString());		println("Print current date =   " + currentDateTime);		println();	}				// ---------------------------------------------------------------------------------------------	// Utilities for this example	// ---------------------------------------------------------------------------------------------		/**	 * Print the content of an XMPMeta object a headline and its name.	 * @param meta an <code>XMPMeta</code> object	 * @param title the headline	 */	private static void printXMPMeta(XMPMeta meta, String title)	{		String name = meta.getObjectName();		if (name != null  &&  name.length() > 0)		{			println(title + " (Name: '" + name + "'):");		}		else		{			println(title + ":");		}		println(meta.dumpObject());		println();	}	/**	 * @param prop an <code>XMPPropertyInfo</code> from the <code>XMPIterator</code>.	 */	private static void printPropertyInfo(XMPPropertyInfo prop)	{		println("NS (" + prop.getNamespace() + ")   PATH (" + prop.getPath() + ")   VALUE ("				+ prop.getValue() + ")  OPTIONS (" + prop.getOptions().getOptionsString() + ")");	}		/**	 * Dump the alias list to the output.	 */	private static void dumpAliases()	{		Map aliases;		aliases = registry.getAliases();		for (Iterator it = aliases.keySet().iterator(); it.hasNext();)		{			String qname = (String) it.next();			XMPAliasInfo aliasInfo = (XMPAliasInfo) aliases.get(qname);			println("" + qname + "   --->   " + aliasInfo);		}		println();	}				/**	 * Writes a major headline to the output.	 * @param title the headline	 */	private static void writeMajorLabel (String title)	{		println();		println("// =============================================================================");		println("// " + title);		println("// =============================================================================");		println();	}		/**	 * Writes a minor headline to the output.	 * @param title the headline	 */	private static void writeMinorLabel (String title)	{		println();		println ("// -----------------------------------------------------------------------------"			.substring(0, title.length() + 3));		println ("// " + title);		println();	}		/**	 * Prints a string message to both log file and system out.	 * @param message the message	 */	private static void println(String message)	{		System.out.println(message);		log.println(message);	}		/**	 * Prints a newline to both log file and system out.	 */	private static void println()	{		println("");	}}

⌨️ 快捷键说明

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