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

📄 xpathmanager.java

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

import org.jawin.browser.xsl.TransformationException;

import org.apache.xpath.XPathAPI;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * A singleton instance that can be used to query a DOM tree
 * or an XML String for a set of nodes
 *
 * <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 XPathManager
{
	private static XPathManager instance = null;

	private XPathManager()
	{
	}

	public static synchronized void initialize()
	{
		instance = new XPathManager();
	}

	public static XPathManager getInstance()
	{
		if (instance == null)
		{
			throw new IllegalStateException("XPathManager.getInstance() XPathManager was not initialized");
		}

		return instance;
	}

	/**
	 * Use XPath to evaluate a String from the provided node
	 *
	 * @param node the node to query
	 * @param xpath the xpath statement to use
	 * @return a String evaluation of the node
	 * @throws TransformationException thrown if something goes wrong
	 */
	public String eval(Node node, String xpath) throws TransformationException
	{
		String result = null;

		try
		{
			result = XPathAPI.eval(node, xpath).toString();
		}
		catch (Exception e)
		{
			throw new TransformationException("XPathManager.eval() failed to evaluate String using xpath: " + xpath, e);
		}

		return result;
	}

	/**
	 * Evaluate the node into a node list
	 * @param node the node to evaluate
	 * @param xpath the xpath to apply
	 * @return a node list of nodes that match the requested xpath
	 * @throws TransformationException thrown if something goes wrong
	 */
	public NodeList evalNodeList(Node node, String xpath) throws TransformationException
	{
		NodeList result = null;

		try
		{
			result = XPathAPI.selectNodeList(node, xpath);
		}
		catch (Exception e)
		{
			throw new TransformationException("XPathManager.evalNodeList() failed to evaluate NodeList using xpath: " + xpath, e);
		}

		return result;
	}


}

⌨️ 快捷键说明

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