|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.cdmckay.coffeedom.xpath.XPath
public abstract class XPath
A utility class for performing XPath calls on CoffeeDOM nodes, with a factory interface for obtaining a first XPath
instance. Users operate against this class while XPath vendors can plug-in implementations underneath. Users can
choose an implementation using either setXPathClass(Class)
or the system property
"org.cdmckay.coffeedom.xpath.class".
Field Summary | |
---|---|
static String |
COFFEEDOM_OBJECT_MODEL_URI
The string passable to the JAXP 1.3 XPathFactory isObjectModelSupported() method to query an XPath engine regarding its support for CoffeeDOM. |
Constructor Summary | |
---|---|
XPath()
|
Method Summary | |
---|---|
abstract void |
addNamespace(Namespace namespace)
Adds a namespace definition to the list of namespaces known of this XPath expression. |
void |
addNamespace(String prefix,
String uri)
Adds a namespace definition (prefix and URI) to the list of namespaces known of this XPath expression. |
abstract String |
getXPath()
Returns the wrapped XPath expression as a string. |
static XPath |
newInstance(String path)
Creates a new XPath wrapper object, compiling the specified XPath expression. |
abstract Number |
numberValueOf(Object context)
Returns the number value of the first node selected by applying the wrapped XPath expression to the given context. |
abstract List<Object> |
selectNodes(Object context)
Evaluates the wrapped XPath expression and returns the list of selected items. |
static List |
selectNodes(Object context,
String path)
Evaluates an XPath expression and returns the list of selected items. |
abstract Object |
selectSingleNode(Object context)
Evaluates the wrapped XPath expression and returns the first entry in the list of selected nodes (or atomics). |
static Object |
selectSingleNode(Object context,
String path)
Evaluates the wrapped XPath expression and returns the first entry in the list of selected nodes (or atomics). |
abstract void |
setVariable(String name,
Object value)
Defines an XPath variable and sets its value. |
static void |
setXPathClass(Class<?> clazz)
Sets the concrete XPath subclass to use when allocating XPath instances. |
abstract String |
valueOf(Object context)
Returns the string value of the first node selected by applying the wrapped XPath expression to the given context. |
protected Object |
writeReplace()
[Serialization support] Returns the alternative object to write to the stream when serializing this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String COFFEEDOM_OBJECT_MODEL_URI
Constructor Detail |
---|
public XPath()
Method Detail |
---|
public static XPath newInstance(String path) throws CoffeeDOMException
path
- the XPath expression to wrap.
CoffeeDOMException
- if the XPath expression is invalid.public static void setXPathClass(Class<?> clazz) throws CoffeeDOMException
clazz
- the concrete subclass of XPath.
IllegalArgumentException
- if clazz
is null
.
CoffeeDOMException
- if clazz
is not a concrete subclass of XPath.public abstract List<Object> selectNodes(Object context) throws CoffeeDOMException
context
- the node to use as context for evaluating the XPath expression.
Element
, Attribute
, Text
,
CDATA
, Comment
, ProcessingInstruction
, Boolean, Double, or String.
CoffeeDOMException
- if the evaluation of the XPath expression on the specified context
failed.public abstract Object selectSingleNode(Object context) throws CoffeeDOMException
context
- the node to use as context for evaluating the XPath expression.
Element
, Attribute
, Text
, CDATA
, Comment
, ProcessingInstruction
, Boolean, Double, String, or null
if
no item was selected.
CoffeeDOMException
- if the evaluation of the XPath expression on the specified context
failed.public abstract String valueOf(Object context) throws CoffeeDOMException
context
- the element to use as context for evaluating the XPath expression.
CoffeeDOMException
- if the XPath expression is invalid or its evaluation on the specified
context failed.public abstract Number numberValueOf(Object context) throws CoffeeDOMException
context
- the element to use as context for evaluating the XPath expression.
null
if no node was selected or the special value Double.NaN
(Not-a-Number) if the selected value can not be converted into a number value.
CoffeeDOMException
- if the XPath expression is invalid or its evaluation on the specified
context failed.public abstract void setVariable(String name, Object value)
name
- the variable name.value
- the variable value.
IllegalArgumentException
- if name
is not a valid XPath variable name or if the value type is
not supported by the underlying implementationpublic abstract void addNamespace(Namespace namespace)
Note: In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI.
namespace
- the namespace.public void addNamespace(String prefix, String uri)
Note: In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI.
prefix
- the namespace prefix.uri
- the namespace URI.
IllegalNameException
- if the prefix or uri are null or empty strings or if they contain illegal
characters.public abstract String getXPath()
public static List selectNodes(Object context, String path) throws CoffeeDOMException
Note: This method
should not be used when the same XPath expression needs to be applied several times (on the same or different
contexts) as it requires the expression to be compiled before being evaluated. In such cases, newInstance(String)
allocating} an XPath wrapper instance and evaluating
it several times is way more efficient.
context
- the node to use as context for evaluating the XPath expression.path
- the XPath expression to evaluate.
Element
, Attribute
, Text
,
CDATA
, Comment
, ProcessingInstruction
, Boolean, Double, or String.
CoffeeDOMException
- if the XPath expression is invalid or its evaluation on the specified
context failed.public static Object selectSingleNode(Object context, String path) throws CoffeeDOMException
Note: This method should not be used when the same XPath expression needs to be applied
several times (on the same or different contexts) as it requires the expression to be compiled before being
evaluated. In such cases, newInstance(String)
allocating} an XPath wrapper instance and evaluating
it several times is way more efficient.
context
- the element to use as context for evaluating the XPath expression.path
- the XPath expression to evaluate.
Element
, Attribute
, Text
, CDATA
, Comment
, ProcessingInstruction
, Boolean, Double, String, or null
if
no item was selected.
CoffeeDOMException
- if the XPath expression is invalid or its evaluation on the specified
context failed.protected final Object writeReplace() throws ObjectStreamException
Note: Subclasses are not allowed to override this method to ensure valid serialization of all implementations.
ObjectStreamException
- never.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |