Package repast.simphony.integration
Class JXPathUtils
java.lang.Object
repast.simphony.integration.JXPathUtils
Utility methods for working with JXPath.
- Author:
- Jerry Vos
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.commons.jxpath.JXPathContext
createContext
(Object rootObj, boolean lenient) Creates a context with the specified object as its root and the specified leniency.static org.apache.commons.jxpath.JXPathContext
createRootContext
(Object obj, boolean lenient) Creates a context for the root of a data file.static String
When doing xpath against beans we need to reference the root with /fileDef, but to be consistent with the DOM code we convert FilDef to fileDef.static org.apache.commons.jxpath.JXPathContext
getContext
(org.apache.commons.jxpath.JXPathContext rootContext, org.apache.commons.jxpath.JXPathContext curContext, String path) If the path begins with a '/' then the root context is returned, otherwise curContext is.static Object
getXPathNode
(org.apache.commons.jxpath.JXPathContext rootContext, org.apache.commons.jxpath.JXPathContext curContext, String path) Retrieves a value from a context (which depends on the path) based on the xpath expression and returns it.static List<?>
getXPathNodes
(org.apache.commons.jxpath.JXPathContext rootContext, org.apache.commons.jxpath.JXPathContext curContext, String path) Retrieves a set of nodes from a context (which depends on the path) based on the xpath expression and returns it.
-
Field Details
-
XPATH_FILE_DEF_CORRECT
The correct representation of the root FileDef tag (/fileDef) according to what JXPath requires. -
XPATH_FILE_DEF_WRONG
The normal (default) FileDef string.
-
-
Constructor Details
-
JXPathUtils
public JXPathUtils()
-
-
Method Details
-
createContext
public static org.apache.commons.jxpath.JXPathContext createContext(Object rootObj, boolean lenient) Creates a context with the specified object as its root and the specified leniency.- Parameters:
rootObj
- the object at the root of the contextlenient
- whether the context is lenient about xpath errrors or not- Returns:
- a newly created context
-
createRootContext
public static org.apache.commons.jxpath.JXPathContext createRootContext(Object obj, boolean lenient) Creates a context for the root of a data file. This wraps the specified object in a FileDef object so that xpath strings like "/FileDef/..." work correctly.- Parameters:
obj
- the object to return from "/FileDef" xpath stringslenient
- whether to be lenient about xpath errors- Returns:
- the newly created context
-
getContext
public static org.apache.commons.jxpath.JXPathContext getContext(org.apache.commons.jxpath.JXPathContext rootContext, org.apache.commons.jxpath.JXPathContext curContext, String path) If the path begins with a '/' then the root context is returned, otherwise curContext is. Hopefully in the future this method will also handle higher nested levels of contexts and relative paths in contexts, but as of now it does not.- Parameters:
rootContext
- the context to be returned for finding from rootcurContext
- the context to be returned for normal (non-rooted) checkingpath
- the xpath expression- Returns:
- the context as specified
-
fixPath
When doing xpath against beans we need to reference the root with /fileDef, but to be consistent with the DOM code we convert FilDef to fileDef.- Parameters:
path
- the path to possibly convert- Returns:
- the result of replacing
XPATH_FILE_DEF_WRONG
withXPATH_FILE_DEF_CORRECT
-
getXPathNode
public static Object getXPathNode(org.apache.commons.jxpath.JXPathContext rootContext, org.apache.commons.jxpath.JXPathContext curContext, String path) Retrieves a value from a context (which depends on the path) based on the xpath expression and returns it.- Parameters:
rootContext
- the root contextcurContext
- the current contextpath
- the xpath expression- Returns:
- the result of applying the xpath expression to the context returned by
getContext(JXPathContext, JXPathContext, String)
- See Also:
-
getXPathNodes
public static List<?> getXPathNodes(org.apache.commons.jxpath.JXPathContext rootContext, org.apache.commons.jxpath.JXPathContext curContext, String path) Retrieves a set of nodes from a context (which depends on the path) based on the xpath expression and returns it.- Parameters:
rootContext
- the root contextcurContext
- the current contextpath
- the xpath expression- Returns:
- the result of applying the xpath expression to the context returned by
getContext(JXPathContext, JXPathContext, String)
- See Also:
-