com.canoo.webtest.engine.xpath
Class XPathHelper

java.lang.Object
  extended by com.canoo.webtest.engine.xpath.XPathHelper

public class XPathHelper
extends Object

Helper class for a central XPath creation allowing to share variable, function and namespace contexts. TODO: cleanup to use plainly javax.xml.xpath.*

Author:
Marc Guillemot

Constructor Summary
XPathHelper()
          Initializes from the global functions, variables and namespaces.
 
Method Summary
protected  Object getByXPath(com.gargoylesoftware.htmlunit.Page _currentResp, String _xpath, boolean _onlyFirstResult)
           
protected  Object getDocument(com.gargoylesoftware.htmlunit.Page page)
          Gets the document object associated to the page that could be provided to the XPath for computations
 SimpleXPathFunctionResolver getFunctionContext()
          Gets the function resolver used during XPath evaluation for this webtest.
static Map<javax.xml.namespace.QName,Class<? extends org.apache.xpath.functions.Function>> getGlobalFunctions()
          Gets the registered global functions.
static Map<String,String> getGlobalNamespaces()
          Gets the registered global namespaces.
static Map<javax.xml.namespace.QName,Object> getGlobalVariables()
          Gets the registered global variables.
 SimpleNamespaceContext getNamespaceContext()
          Gets the namespace context used for namespace resolution during XPath evaluation for this webtest.
 SimpleXPathVariableResolver getVariableContext()
          Gets the variable context used for variable resolution (the $foo in an xpath expression) during XPath evaluation for this webtest.
static String quote(String value)
          Quotes the provided value, handling quotes and double quotes if needed to
static void registerGlobalFunction(String namespaceURI, String localName, Class<? extends org.apache.xpath.functions.Function> function)
          Registers a global function.
static void registerGlobalNamespace(String prefix, String namespaceURI)
          Registers a global namespace.
static void registerGlobalVariable(String namespaceURI, String localName, Object value)
          Registers a global variable.
 Object selectFirst(com.gargoylesoftware.htmlunit.Page _page, String _xpath)
           
 List<? extends Object> selectNodes(com.gargoylesoftware.htmlunit.Page _page, String _xpath)
           
 String stringValueOf(com.gargoylesoftware.htmlunit.Page _page, String _xpath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathHelper

public XPathHelper()
Initializes from the global functions, variables and namespaces.

Method Detail

registerGlobalVariable

public static void registerGlobalVariable(String namespaceURI,
                                          String localName,
                                          Object value)
Registers a global variable. Global variables are added to the list of variable of a webtest at the webtest start.

Parameters:
namespaceURI - the namespace URI of the function to be registered (null if none).
localName - the non-prefixed local portion of the function name to be registered
value - the variable to be registered

getGlobalVariables

public static Map<javax.xml.namespace.QName,Object> getGlobalVariables()
Gets the registered global variables.

Returns:
a synchronized map of (MemberKey, variable value)

getGlobalFunctions

public static Map<javax.xml.namespace.QName,Class<? extends org.apache.xpath.functions.Function>> getGlobalFunctions()
Gets the registered global functions.

Returns:
a synchronized map of (MemberKey, function)

getGlobalNamespaces

public static Map<String,String> getGlobalNamespaces()
Gets the registered global namespaces.

Returns:
a synchronized map of (prefix, namespaceURI)

registerGlobalFunction

public static void registerGlobalFunction(String namespaceURI,
                                          String localName,
                                          Class<? extends org.apache.xpath.functions.Function> function)
Registers a global function. Global functions are added to the list of functions of a webtest at the webtest start.

Parameters:
namespaceURI - the namespace URI of the function to be registered (null if none).
localName - the non-prefixed local portion of the function name to be registered
function - the function to be registered

registerGlobalNamespace

public static void registerGlobalNamespace(String prefix,
                                           String namespaceURI)
Registers a global namespace. Global namespaces are added to the list of namespaces of a webtest at the webtest start.

Parameters:
prefix - the namespace prefix to resolve
namespaceURI - the namespace URI

getFunctionContext

public SimpleXPathFunctionResolver getFunctionContext()
Gets the function resolver used during XPath evaluation for this webtest.

Returns:
the context

getNamespaceContext

public SimpleNamespaceContext getNamespaceContext()
Gets the namespace context used for namespace resolution during XPath evaluation for this webtest.

Returns:
the context

getVariableContext

public SimpleXPathVariableResolver getVariableContext()
Gets the variable context used for variable resolution (the $foo in an xpath expression) during XPath evaluation for this webtest.

Returns:
the context

getDocument

protected Object getDocument(com.gargoylesoftware.htmlunit.Page page)
Gets the document object associated to the page that could be provided to the XPath for computations

Parameters:
page - the page
Returns:
the "document"

stringValueOf

public String stringValueOf(com.gargoylesoftware.htmlunit.Page _page,
                            String _xpath)
                     throws javax.xml.xpath.XPathExpressionException
Throws:
javax.xml.xpath.XPathExpressionException

selectNodes

public List<? extends Object> selectNodes(com.gargoylesoftware.htmlunit.Page _page,
                                          String _xpath)
                                   throws javax.xml.xpath.XPathExpressionException
Throws:
javax.xml.xpath.XPathExpressionException

selectFirst

public Object selectFirst(com.gargoylesoftware.htmlunit.Page _page,
                          String _xpath)
                   throws javax.xml.xpath.XPathExpressionException
Throws:
javax.xml.xpath.XPathExpressionException

getByXPath

protected Object getByXPath(com.gargoylesoftware.htmlunit.Page _currentResp,
                            String _xpath,
                            boolean _onlyFirstResult)
                     throws javax.xml.xpath.XPathExpressionException
Throws:
javax.xml.xpath.XPathExpressionException

quote

public static String quote(String value)
Quotes the provided value, handling quotes and double quotes if needed to

Parameters:
value - the value to quote
Returns:
the quoted value usable in XPath expression

Copyright © 2001-2007 Canoo Engineering AG, Basel. All rights reserved.