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

📄 codecompletionparser.java

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

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;

/**
 * <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 CodeCompletionParser 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;

	private CodeCompletionListModel model = null;

	private CodeCompletionConfig currentConfig = null;

	private StringBuffer buffer = new StringBuffer();


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

	/**
	 * @todo implement config file parsing and throw SaxException
	 *
	 * @param configFile
	 */
	public CodeCompletionListModel parseConfig(String configFile)
	{
		FileInputStream fileIn = null;

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

				}
			}
		}

		return model;
	}

	/**
	 * Fired when the start of a doucment is encountered
	 *
	 * @throws SAXException thrown if something goes wrong
	 */
	public void startDocument() throws SAXException
	{
		model = new CodeCompletionListModel();
	}

	/**
	 * 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("item"))
		{
			buffer.setLength(0);
			String name = getAttribute("name", attributes);
			currentConfig = new CodeCompletionConfig(name, "");
			model.addConfig(currentConfig);
		}
	}

	public void endElement(String uri, String localName, String qualifiedName) throws SAXException
	{
		if (qualifiedName.equals("item"))
		{
			currentConfig.setCode(buffer.toString());
			buffer.setLength(0);
		}
	}

	/**
	 * 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;
	}

	public void characters(char [] chars, int start, int length) throws SAXException
	{
		buffer.append(chars, start, length);
	}

}

⌨️ 快捷键说明

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