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

📄 codegenconfigparser.java

📁 java 调用windows的api
💻 JAVA
字号:
package org.jawin.browser.codegen;

import org.xml.sax.ext.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

import java.io.*;

import org.jawin.browser.config.ConfigManager;
import org.jawin.browser.log.Log;

/**
 * SAX parse out the code gen configuration file, populating the
 * CodeGenConfigManager singleton with configuration which is used
 * to generate a suite of classes for a selected subset of a type library.
 *
 * <p>Title: Jawin Code Generation GUI</p>
 * <p>Description: GUI for exploring type libraries and generating Java code</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Open Source Incentive</p>
 *
 * @author Josh Passenger
 * @version 1.0
 */

public class CodeGenConfigParser extends DefaultHandler
{
	/**
	 * The Sax parser class to use
	 */
	private String parserName = ConfigManager.getInstance().getString("sax.parser", "org.apache.xerces.parsers.SAXParser");

	/**
	 * The parser that will actually pasre the document
	 */
	private XMLReader xmlReader = null;


	public CodeGenConfigParser()
	{
		try
		{
			xmlReader = XMLReaderFactory.createXMLReader(parserName);
			xmlReader.setContentHandler(this);
		}
		catch (Exception e)
		{
			Log.getInstance().exception("CodeGenConfigParser() failed to create SAX parser, no code config is available", e);
		}
	}

	/**
	 * @todo implement config file parsing and throw SaxException
	 *
	 * @param codeGenConfigFile
	 */
	public void parseCodeGenConfig(String codeGenConfigFile)
	{
		FileInputStream fileIn = null;

		try
		{
			fileIn = new FileInputStream(codeGenConfigFile);
			InputSource in = new InputSource(fileIn);
			xmlReader.parse(in);
		}
		catch (Exception e)
		{
			Log.getInstance().exception("CodeGenConfigParser.parseCodeGenConfig() failed to parse code gen config file: " + codeGenConfigFile, e);
		}
		finally
		{
			if (fileIn != null)
			{
				try
				{
					fileIn.close();
				}
				catch (Exception e)
				{

				}
			}
		}
	}

	/**
	 * Fired when the start of a doucment is encountered
	 *
	 * @throws SAXException thrown if something goes wrong
	 */
	public void startDocument() throws SAXException
	{
		CodeGenConfigManager.getInstance().clearConfig();
	}

	/**
	 * Fired when a n element is started
	 * @param uri
	 * @param localName
	 * @param qualifiedName
	 * @param attributes
	 * @throws SAXException
	 */
	public void startElement(String uri, String localName, String qualifiedName, Attributes attributes) throws SAXException
	{
		if (qualifiedName.equals("task"))
		{
			String name = getAttribute("name", attributes);
			String xpath = getAttribute("xpath", attributes);
			String stylesheet = getAttribute("stylesheet", attributes);
			String fileNameXPath = getAttribute("fileNameXPath", attributes);
			String packageNameXPath = getAttribute("packageNameXPath", attributes);
			String saveDirectoryXPath = getAttribute("saveDirectoryXPath", attributes);
			String javaEncodingXPath = getAttribute("javaEncodingXPath", attributes);
			String imageName = getAttribute("icon", attributes);
			CodeGenConfig config = new CodeGenConfig(name, xpath, fileNameXPath,
				packageNameXPath, saveDirectoryXPath, javaEncodingXPath, stylesheet, imageName);
			CodeGenConfigManager.getInstance().addCodeGenConfig(config);
		}
	}

	/**
	 * Fetches the value of a required attribute
	 *
	 * @param name the name of the attribute to fetch
	 * @param attributes the attributes on the node
	 * @return the value of the named attribute
	 * @throws SAXException thrown if the attribute does not exist
	 */
	private String getAttribute(String name, Attributes attributes) throws SAXException
	{
		String value = attributes.getValue(name);

		if (value == null || value.equals(""))
		{
			throw new SAXException("CodeGenConfigParser.getAttribute() a required attribute was missing: " + name);
		}

		return value;
	}

}

⌨️ 快捷键说明

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