Top Description Fields Constructors Methods
org.dom4j.xpath

public Class DefaultXPath

extends Object
implements XPath, NodeFilter, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.dom4j.NodeFilter, org.dom4j.XPath
Imports
java.io.Serializable, java.util.Collections, .Comparator, .HashMap, .HashSet, .Iterator, .List, .Map, org.dom4j.InvalidXPathException, .Node, .NodeFilter, .XPathException, org.jaxen.FunctionContext, .JaxenException, .NamespaceContext, .SimpleNamespaceContext, .VariableContext, .XPath, org.jaxen.dom4j.Dom4jXPath

Default implementation of org.dom4j.XPathwhich uses the Jaxen project.

Authors
bob mcwhirter, James Strachan

Field Summary

Modifier and TypeField and Description
private NamespaceContext
private String
private XPath

Constructor Summary

AccessConstructor and Description
public
DefaultXPath(String
DOCUMENT ME!
text
)

Construct an XPath

Method Summary

Modifier and TypeMethod and Description
public boolean
booleanValueOf(Object
The node, nodeset or Context object for evaluation. This value can be null
context
)

Implements org.dom4j.XPath.booleanValueOf.

Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context.
public Object
evaluate(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Implements org.dom4j.XPath.evaluate.

evaluate evaluates an XPath expression and returns the result as an Object.
protected Object

Returns:

the node expression used for sorting comparisons
getCompareValue
(Node
DOCUMENT ME!
node
)

DOCUMENT ME!

public FunctionContext
public NamespaceContext
public String

Returns:

The XPath string
getText
()

Implements org.dom4j.XPath.getText.

Retrieve the textual XPath string used to initialize this Object
public VariableContext
protected void
public boolean
matches(Node
DOCUMENT ME!
node
)

Implements org.dom4j.XPath.matches, org.dom4j.NodeFilter.matches.

matches returns true if the given node matches the XPath expression.
public Number
numberValueOf(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Implements org.dom4j.XPath.numberValueOf.

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results is a number, or null if the result is not a number.
protected static XPath
parse(String text)

protected void
removeDuplicates(List<Node>
DOCUMENT ME!
list
,
Map<Node, Object>
DOCUMENT ME!
sortValues
)

Removes items from the list which have duplicate values

public List<Node>
selectNodes(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Implements org.dom4j.XPath.selectNodes.

selectNodes performs this XPath expression on the given Nodeor Listof Nodes instances appending all the results together into a single list.
public List<Node>
selectNodes(Object
is either a node or a list of nodes on which to evalute the XPath
context
,
XPath
is the XPath expression to sort by
sortXPath
)

Implements org.dom4j.XPath.selectNodes.

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.
public List<Node>
selectNodes(Object
is either a node or a list of nodes on which to evalute the XPath
context
,
XPath
is the XPath expression to sort by
sortXPath
,
boolean
specifies whether or not duplicate values of the sort expression are allowed. If this parameter is true then only distinct sort expressions values are included in the result
distinct
)

Implements org.dom4j.XPath.selectNodes.

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.
public Object
selectObject(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Implements org.dom4j.XPath.selectObject.

selectObject evaluates an XPath expression and returns the result as an Object.
public Node
selectSingleNode(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Implements org.dom4j.XPath.selectSingleNode.

selectSingleNode evaluates this XPath expression on the given Nodeor Listof Nodes and returns the result as a single Node instance.
public void
setFunctionContext(FunctionContext
DOCUMENT ME!
functionContext
)

Implements org.dom4j.XPath.setFunctionContext.

Sets the function context to be used when evaluating XPath expressions
public void
setNamespaceContext(NamespaceContext
DOCUMENT ME!
namespaceContext
)

Implements org.dom4j.XPath.setNamespaceContext.

Sets the namespace context to be used when evaluating XPath expressions
public void
setNamespaceURIs(Map<String, String>
the map containing the namespace mappings
map
)

Implements org.dom4j.XPath.setNamespaceURIs.

Sets the current NamespaceContext from a Map where the keys are the String namespace prefixes and the values are the namespace URIs.
protected void
public void
setVariableContext(VariableContext
DOCUMENT ME!
variableContext
)

Implements org.dom4j.XPath.setVariableContext.

Sets the variable context to be used when evaluating XPath expressions
public void
sort(List<Node>
is the list of Nodes to sort
list
)

Implements org.dom4j.XPath.sort.

sort sorts the given List of Nodes using this XPath expression as a Comparator.

public void
sort(List<Node>
is the list of Nodes to sort
list
,
boolean
if true then duplicate values (using the sortXPath for comparisions) will be removed from the List
distinct
)

Implements org.dom4j.XPath.sort.

sort sorts the given List of Nodes using this XPath expression as a Comparatorand optionally removing duplicates.

protected void
sort(List<Node>
DOCUMENT ME!
list
,
final Map<Node, Object>
DOCUMENT ME!
sortValues
)

Sorts the list based on the sortValues for each node

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String
valueOf(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Implements org.dom4j.XPath.valueOf.

valueOf evaluates this XPath expression and returns the textual representation of the results using the XPath string() function.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

namespaceContextback to summary
private NamespaceContext namespaceContext
textback to summary
private String text
xpathback to summary
private XPath xpath

Constructor Detail

DefaultXPathback to summary
public DefaultXPath(String text) throws InvalidXPathException

Construct an XPath

Parameters
text:String

DOCUMENT ME!

Exceptions
InvalidXPathException:
DOCUMENT ME!

Method Detail

booleanValueOfback to summary
public boolean booleanValueOf(Object context)

Implements org.dom4j.XPath.booleanValueOf.

Doc from org.dom4j.XPath.booleanValueOf.

Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context. The boolean-value of the expression is determined per the boolean(..) core function as defined in the XPath specification. This means that an expression that selects zero nodes will return false, while an expression that selects one-or-more nodes will return true.

Parameters
context:Object

The node, nodeset or Context object for evaluation. This value can be null

Returns:boolean

The boolean-value interpretation of this expression.

evaluateback to summary
public Object evaluate(Object context)

Implements org.dom4j.XPath.evaluate.

Doc from org.dom4j.XPath.evaluate.

evaluate evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of Nodeinstances, a Nodeinstance, a String or a Numberinstance depending on the XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Object

the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.

getCompareValueback to summary
protected Object getCompareValue(Node node)

DOCUMENT ME!

Parameters
node:Node

DOCUMENT ME!

Returns:Object

the node expression used for sorting comparisons

getFunctionContextback to summary
public FunctionContext getFunctionContext()

Implements org.dom4j.XPath.getFunctionContext.

Doc from org.dom4j.XPath.getFunctionContext.

DOCUMENT ME!

Returns:FunctionContext

the current function context

getNamespaceContextback to summary
public NamespaceContext getNamespaceContext()

Implements org.dom4j.XPath.getNamespaceContext.

Doc from org.dom4j.XPath.getNamespaceContext.

DOCUMENT ME!

Returns:NamespaceContext

the current namespace context

getTextback to summary
public String getText()

Implements org.dom4j.XPath.getText.

Retrieve the textual XPath string used to initialize this Object

Returns:String

The XPath string

getVariableContextback to summary
public VariableContext getVariableContext()

Implements org.dom4j.XPath.getVariableContext.

Doc from org.dom4j.XPath.getVariableContext.

DOCUMENT ME!

Returns:VariableContext

the current variable context

handleJaxenExceptionback to summary
protected void handleJaxenException(JaxenException exception) throws XPathException
matchesback to summary
public boolean matches(Node node)

Implements org.dom4j.XPath.matches, org.dom4j.NodeFilter.matches.

Doc from org.dom4j.XPath.matches.

matches returns true if the given node matches the XPath expression. To be more precise when evaluating this XPath expression on the given node the result set must include the node.

Parameters
node:Node

DOCUMENT ME!

Returns:boolean

true if the given node matches this XPath expression

numberValueOfback to summary
public Number numberValueOf(Object context)

Implements org.dom4j.XPath.numberValueOf.

Doc from org.dom4j.XPath.numberValueOf.

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results is a number, or null if the result is not a number.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Number

the numeric result of the XPath expression or null if the result is not a number.

parseback to summary
protected static XPath parse(String text)
removeDuplicatesback to summary
protected void removeDuplicates(List<Node> list, Map<Node, Object> sortValues)

Removes items from the list which have duplicate values

Parameters
list:List<Node>

DOCUMENT ME!

sortValues:Map<Node, Object>

DOCUMENT ME!

selectNodesback to summary
public List<Node> selectNodes(Object context)

Implements org.dom4j.XPath.selectNodes.

Doc from org.dom4j.XPath.selectNodes.

selectNodes performs this XPath expression on the given Nodeor Listof Nodes instances appending all the results together into a single list.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:List<Node>

the results of all the XPath evaluations as a single list

selectNodesback to summary
public List<Node> selectNodes(Object context, XPath sortXPath)

Implements org.dom4j.XPath.selectNodes.

Doc from org.dom4j.XPath.selectNodes.

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

sortXPath:XPath

is the XPath expression to sort by

Returns:List<Node>

a list of Node instances

selectNodesback to summary
public List<Node> selectNodes(Object context, XPath sortXPath, boolean distinct)

Implements org.dom4j.XPath.selectNodes.

Doc from org.dom4j.XPath.selectNodes.

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

sortXPath:XPath

is the XPath expression to sort by

distinct:boolean

specifies whether or not duplicate values of the sort expression are allowed. If this parameter is true then only distinct sort expressions values are included in the result

Returns:List<Node>

a list of Node instances

selectObjectback to summary
public Object selectObject(Object context)

Implements org.dom4j.XPath.selectObject.

Doc from org.dom4j.XPath.selectObject.

selectObject evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of Nodeinstances, a Nodeinstance, a String or a Numberinstance depending on the XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Object

the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.

selectSingleNodeback to summary
public Node selectSingleNode(Object context)

Implements org.dom4j.XPath.selectSingleNode.

Doc from org.dom4j.XPath.selectSingleNode.

selectSingleNode evaluates this XPath expression on the given Nodeor Listof Nodes and returns the result as a single Node instance.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Node

a single matching Node instance

setFunctionContextback to summary
public void setFunctionContext(FunctionContext functionContext)

Implements org.dom4j.XPath.setFunctionContext.

Doc from org.dom4j.XPath.setFunctionContext.

Sets the function context to be used when evaluating XPath expressions

Parameters
functionContext:FunctionContext

DOCUMENT ME!

setNamespaceContextback to summary
public void setNamespaceContext(NamespaceContext namespaceContext)

Implements org.dom4j.XPath.setNamespaceContext.

Doc from org.dom4j.XPath.setNamespaceContext.

Sets the namespace context to be used when evaluating XPath expressions

Parameters
namespaceContext:NamespaceContext

DOCUMENT ME!

setNamespaceURIsback to summary
public void setNamespaceURIs(Map<String, String> map)

Implements org.dom4j.XPath.setNamespaceURIs.

Doc from org.dom4j.XPath.setNamespaceURIs.

Sets the current NamespaceContext from a Map where the keys are the String namespace prefixes and the values are the namespace URIs. For example:

Map uris = new HashMap();
uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
uris.put("m", "urn:xmethodsBabelFish");
XPath xpath = document
        .createXPath("SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish");
xpath.setNamespaceURIs(uris);
Node babelfish = xpath.selectSingleNode(document);
Parameters
map:Map<String, String>

the map containing the namespace mappings

setNSContextback to summary
protected void setNSContext(Object context)
setVariableContextback to summary
public void setVariableContext(VariableContext variableContext)

Implements org.dom4j.XPath.setVariableContext.

Doc from org.dom4j.XPath.setVariableContext.

Sets the variable context to be used when evaluating XPath expressions

Parameters
variableContext:VariableContext

DOCUMENT ME!

sortback to summary
public void sort(List<Node> list)

Implements org.dom4j.XPath.sort.

sort sorts the given List of Nodes using this XPath expression as a Comparator.

Parameters
list:List<Node>

is the list of Nodes to sort

sortback to summary
public void sort(List<Node> list, boolean distinct)

Implements org.dom4j.XPath.sort.

sort sorts the given List of Nodes using this XPath expression as a Comparatorand optionally removing duplicates.

Parameters
list:List<Node>

is the list of Nodes to sort

distinct:boolean

if true then duplicate values (using the sortXPath for comparisions) will be removed from the List

sortback to summary
protected void sort(List<Node> list, final Map<Node, Object> sortValues)

Sorts the list based on the sortValues for each node

Parameters
list:List<Node>

DOCUMENT ME!

sortValues:Map<Node, Object>

DOCUMENT ME!

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

valueOfback to summary
public String valueOf(Object context)

Implements org.dom4j.XPath.valueOf.

Doc from org.dom4j.XPath.valueOf.

valueOf evaluates this XPath expression and returns the textual representation of the results using the XPath string() function.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:String

the string representation of the results of the XPath expression