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

📄 popupactionconfigparser.java

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

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;

/**
 * Parses the popup action configuration file and stores the configurations
 * in the PopupManager, so that right clicks on the type info tree can have
 * configurable context sensitive popup menus.
 *
 * <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 PopupActionConfigParser 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;

	/**
	 * The current PopupActionConfig
	 */
	private PopupActionConfig currentConfig = null;

	/**
	 * The current PopupAction
	 */
	private PopupAction currentAction = null;


	public PopupActionConfigParser()
	{
		try
		{
			xmlReader = XMLReaderFactory.createXMLReader(parserName);
			xmlReader.setContentHandler(this);
		}
		catch (Exception e)
		{
			Log.getInstance().exception("PopupActionConfigParser() failed to create SAX parser, no popup menu items will be available", e);
		}
	}

	/**
	 * Parse the menu config file
	 *
	 * @param configFile
	 */
	public void parsePopupActionConfig(String configFile)
	{
		FileInputStream fileIn = null;

		try
		{
			fileIn = new FileInputStream(configFile);
			InputSource in = new InputSource(fileIn);
			xmlReader.parse(in);
		}
		catch (Exception e)
		{
			Log.getInstance().exception("PopupActionConfigParser.parsePopupActionConfig() failed to parse popup action config file: " + configFile, 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
	{
		PopupManager.getInstance().clearConfig();
		currentConfig = null;
		currentAction = null;
	}

	/**
	 * Fired when an 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("basedata"))
		{
			String baseDataClass = getAttribute("class", attributes);
			currentConfig = new PopupActionConfig(baseDataClass);
			PopupManager.getInstance().addConfig(currentConfig);
			return;
		}

		if (qualifiedName.equals("action"))
		{
			String display = getAttribute("display", attributes);
			String actionClass = getAttribute("class", attributes);

			try
			{
				currentAction = (PopupAction) Class.forName(actionClass).newInstance();
				currentAction.setDisplay(display);

				if (currentConfig != null)
				{
					currentConfig.addPoupAction(currentAction);
				}
			}
			catch (Exception e)
			{
				Log.getInstance().exception("PopupActionConfigParser.startElement() failed to craete instance of PopupAction: " + actionClass, e);
			}

			return;
		}

		if (qualifiedName.equals("param"))
		{
			String name = getAttribute("name", attributes);
			String value = getAttribute("value", attributes);

			if (currentAction != null)
			{
				currentAction.addParam(name, value);
			}
		}
	}

	/**
	 * 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("PopupActionConfigParser.getAttribute() a required attribute was missing: " + name);
		}

		return value;
	}

}

⌨️ 快捷键说明

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