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

📄 metamorphoses.java

📁 METAmorphoses is a system for flexible and easy-to-use generation of RDF metadata directly from a re
💻 JAVA
字号:
package cz.cvut.felk.cs.metamorphoses;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.HashMap;import java.util.Map;import java.util.StringTokenizer;import com.martiansoftware.jsap.FlaggedOption;import com.martiansoftware.jsap.JSAP;import com.martiansoftware.jsap.JSAPException;import com.martiansoftware.jsap.JSAPResult;import com.martiansoftware.jsap.UnflaggedOption;import cz.cvut.felk.cs.metamorphoses.mapping.MappingProcessorException;import cz.cvut.felk.cs.metamorphoses.template.TemplateProcessor;import cz.cvut.felk.cs.metamorphoses.template.TemplateProcessorException;/** * This class is to run METAmorphoses as a standalone Java application *  * @author martin */public class Metamorphoses {	/**	 * The main method	 * 	 * @param args	 *            an array of command line arguments	 */	public static void main(String[] args) throws TemplateProcessorException,			MappingProcessorException {		// map.put("username", "muller");		// map.put("id", "98843");		// map.put("id", "16067");		JSAP jsap = new JSAP();		try {			jsap.registerParameter(new UnflaggedOption("template",					JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED,					JSAP.NOT_GREEDY, "A path to a particular template file."));			jsap.registerParameter(new FlaggedOption(							"variables",							JSAP.STRING_PARSER,							JSAP.NO_DEFAULT,							JSAP.NOT_REQUIRED,							'l',							JSAP.NO_LONGFLAG,							"A list of variables required by the processed template. \nFormat: comma separated list of pairs 'variableName=variableValue'"));			jsap.registerParameter(new UnflaggedOption("output",					JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,					JSAP.NOT_GREEDY, "An output RDF file."));		} catch (JSAPException e1) {			System.err.println("Error in command line arguments parsing.");			e1.printStackTrace();		}		JSAPResult config = jsap.parse(args);		if (!config.success()) {			System.err.println();			// print out specific error messages describing the problems			// with the command line, THEN print usage, THEN print full			// help. This is called "beating the user with a clue stick."			for (java.util.Iterator errs = config.getErrorMessageIterator(); errs					.hasNext();) {				System.err.println("Error: " + errs.next());			}						System.err.println();			System.err.println("Usage: java -jar metamorphoses-v0.2.5.jar");			System.err.println("                " + jsap.getUsage());			System.err.println();			System.err.println(jsap.getHelp());			System.exit(1);		}		String templateFileName = config.getString("template");		String variables = config.getString("variables");		String outputFileName = config.getString("output");				OutputStream outputStream = System.out;		if (outputFileName != null) {			try {				outputStream = new FileOutputStream(outputFileName);			} catch (IOException e) {				throw new TemplateProcessorException("Output file '"						+ outputFileName + "' could not be created.", e);			}		} 				try {			File file = new File(templateFileName);			InputStream is = new FileInputStream(file);			Map map = new HashMap();			if (variables != null) {				StringTokenizer st = new StringTokenizer(variables, ",");				StringTokenizer tmpSt;				while (st.hasMoreTokens()) {					String pair = st.nextToken();					tmpSt = new StringTokenizer(pair, "=");					String varName = tmpSt.nextToken();					// String value = tmpSt.nextToken();					if (tmpSt.hasMoreTokens()) {						String varValue = tmpSt.nextToken();						map.put(varName, varValue);					}				}			}			TemplateProcessor tp = new TemplateProcessor(is, outputStream, map);			tp.parse();		} catch (IOException e) {			throw new TemplateProcessorException("Template file '"					+ templateFileName + "' was not found.", e);		} catch (TemplateProcessorException e) {			// System.out.println(e.getMessage());			throw e;		}		/*if (outputFileName != null) {			try {				String s = null;				BufferedReader in = new BufferedReader(new StringReader(						outputRdf));				PrintWriter out = new PrintWriter(new BufferedWriter(						new FileWriter(outputFileName)));				while ((s = in.readLine()) != null)					out.println(s);				out.close();			} catch (IOException e) {				throw new TemplateProcessorException("Output file '"						+ outputFileName + "' could not be created.", e);			}		} else {			System.out.print(outputRdf);		}*/		/*		 * System.out.println("\nMETAmorphoses - template processor");		 * System.out.println("----------------------------------"); System.out		 * .println("Usage: java		 * cz/cvut/felk/cs/metamorphoses/template/TemplateProcessor templateFile		 * [listOfVariables]"); System.out.println("");		 * System.out.println("Where:"); System.out .println(" - 'templateFile'		 * is a path to a particular template file"); System.out .println(" -		 * 'listOfVariables' is comma separated list of pairs		 * 'variableName=variableValue'"); System.out.println(""); System.out		 * .println("Example: \n" + " java		 * cz/cvut/felk/cs/metamorphoses/template/TemplateProcessor		 * /path/to/templatefile.xml firstname=John,surname=Smith\n");		 */	}}

⌨️ 快捷键说明

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