Java Code Examples for org.jaxen.XPath#evaluate()

The following examples show how to use org.jaxen.XPath#evaluate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JaxenNsAwareXPathExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public NodeList selectNodeList(Node contextNode, String expression) throws JRException
{
	try
	{
		XPath xpath = getXPath(contextNode, expression);
		Object object = xpath.evaluate(contextNode);
		List<Object> nodes;
		if (object instanceof List<?>)
		{
			nodes = (List<Object>) object;
		}
		else
		{
			nodes = new ArrayList<Object>();
			nodes.add(object);
		}
		return new NodeListWrapper(nodes);
	}
	catch (JaxenException e)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_XPATH_SELECTION_FAILURE,
				new Object[]{expression},
				e);
	}		
}
 
Example 2
Source File: JaxenNsAwareXPathExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object selectObject(Node contextNode, String expression) throws JRException
{
	try
	{
		XPath xpath = getXPath(contextNode, expression);
		Object object = xpath.evaluate(contextNode);
		Object value;
		if (object instanceof List<?>)
		{
			List<?> list = (List<?>) object;
			if (list.isEmpty())
			{
				value = null;
			}
			else
			{
				value = list.get(0);
			}
		}
		else if (object instanceof Number || object instanceof Boolean)
		{
			value = object;
		}
		else
		{
			value = object.toString();
		}
		return value;
	}
	catch (JaxenException e)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_XPATH_SELECTION_FAILURE,
				new Object[]{expression},
				e);
	}
}
 
Example 3
Source File: JaxenXPathExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public NodeList selectNodeList(Node contextNode, String expression) throws JRException
{
	try
	{
		XPath xpath = getXPath(expression);
		Object object = xpath.evaluate(contextNode);
		List<Object> nodes;
		if (object instanceof List<?>)
		{
			nodes = (List<Object>) object;
		}
		else
		{
			nodes = new ArrayList<Object>();
			nodes.add(object);
		}
		return new NodeListWrapper(nodes);
	}
	catch (JaxenException e)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_XPATH_SELECTION_FAILURE,
				new Object[]{expression},
				e);
	}		
}
 
Example 4
Source File: JaxenXPathExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object selectObject(Node contextNode, String expression) throws JRException
{
	try
	{
		XPath xpath = new DOMXPath(expression);
		Object object = xpath.evaluate(contextNode);
		Object value;
		if (object instanceof List<?>)
		{
			List<?> list = (List<?>) object;
			if (list.isEmpty())
			{
				value = null;
			}
			else
			{
				value = list.get(0);
			}
		}
		else if (object instanceof Number || object instanceof Boolean)
		{
			value = object;
		}
		else
		{
			value = object.toString();
		}
		return value;
	}
	catch (JaxenException e)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_XPATH_SELECTION_FAILURE,
				new Object[]{expression},
				e);
	}
}