public abstract class XPathRule
extends java.lang.Object
XPath
axes. Each
kind of rule has an apply(Content)
method, which applies the
rule to a given context node, and returns a list of nodes, possibly empty,
that satisfy the rule. A compiled XPath consists of a list of XPathRules.
A rule may simply navigate to the target node set, by completing a step
along one of the supported XPath
axes. More commonly, a rule will
apply one or more Filter
constraints to the target node set. The
various kinds of Filter implement the node test (for the desired node-type),
or a more general predicate on the name or value of the node, or even a
sophisticated restriction on the dependent attributes or children of the
desired node.
Whereas each rule typically returns a set of matching nodes, XPathRule
supports the ability to select a single node from the matching set, at a
given position. The position is indexed either from the front, using a
positive integer 1..n, or indexed from the back, using a negative integer
-1..-n. The position zero indicates the last position in the matching list
of nodes. A position restriction is always applied last, after the rule's
other filters have determined the matching list. A consequence of this is
that complex XPath patterns that add further predicates in the same step,
after a position restriction, must be split over two XPathRules. This is
handled automatically by XPath
, when it compiles the pattern.
Modifier and Type | Field and Description |
---|---|
private IndexFilter |
counter
The IndexFilter used to select one from a list of results.
|
protected Filter |
filter
The filter used to restrict the current context node.
|
Modifier | Constructor and Description |
---|---|
protected |
XPathRule()
Creates a default XPathRule that accepts any legal XPath context node.
|
protected |
XPathRule(Filter restriction)
Creates an XPathRule that accepts only nodes restricted by a filter.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<Content> |
apply(Content context)
Applies this rule to the context node, returning any matching nodes.
|
void |
broaden(Filter broadening)
Broadens the current applicable contexts by adding a Filter.
|
Filter |
getFilter()
Returns the filter being used by this XPathRule.
|
void |
restrict(Filter restriction)
Restricts the current applicable contexts by adding a Filter.
|
java.lang.String |
toString()
Returns a pretty representation of this XPathRule.
|
protected Filter filter
private IndexFilter counter
protected XPathRule()
protected XPathRule(Filter restriction)
restriction
- a restriction on the context node.public Filter getFilter()
public java.util.List<Content> apply(Content context)
context
- the current node, known as the context.public void restrict(Filter restriction)
restriction
- the extra restriction to apply.public void broaden(Filter broadening)
broadening
- the alternative restriction to apply.public java.lang.String toString()
toString
in class java.lang.Object