|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jdom.contrib.input.scanner.XPathMatcher
The base class for all XPath matchers used by
ElementScanner
.
This class also plays the role of factory for concrete
implementations: The system property
"org.jdom.XPathMatcher.class
" shall contain the
fully-qualified name of a concrete subclass of XPatchMatcher with
a public two argument constructor
. If this
property is not defined, the default concrete implementation
(supporting only node matching patterns) will be used.
As the default implementation relies on Perl5-like regular expression to match nodes, any regular expression can be used as "XPath expression" with the restriction that any '*' character be escaped (i.e. preceded with a '\' character).
Constructor Summary | |
protected |
XPathMatcher(java.lang.String expression,
ElementListener listener)
Default constructor, protected on purpose. |
Method Summary | |
java.lang.String |
getExpression()
Returns the XPath expression this matcher matches. |
ElementListener |
getListener()
Returns the element listener associated to this matcher object. |
protected static java.lang.String |
getPathPatternAsRE(java.lang.String expr)
Extracts the node matching pattern part from an XPath expression and converts it into a Perl5-like regular expression. |
protected static java.lang.String |
getTestPattern(java.lang.String expr)
Extracts the test part from an XPath expression. |
static boolean |
isDebug()
Returns whether debug traces are active. |
abstract boolean |
match(java.lang.String path,
org.xml.sax.Attributes attrs)
Tries to match an element path and attributes with the XPath expression this matcher matches. |
abstract boolean |
match(java.lang.String path,
org.jdom.Element elt)
Tries to match an element with the XPath expression this matcher matches. |
static XPathMatcher |
newXPathMatcher(java.lang.String expression,
ElementListener listener)
Creates a new XPath matcher matching the specified XPath expression. |
static void |
setDebug(boolean value)
Activates or deactivates debug traces on the process standard output. |
static void |
setXPathMatcherClass(java.lang.Class aClass)
Sets the concrete XPathMatcher subclass to be used when allocating XPathMatcher instances. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
protected XPathMatcher(java.lang.String expression, ElementListener listener) throws org.jdom.JDOMException
expression
- the XPath-like expression to match.listener
- the element listener to notify when an
element matches the expression.Method Detail |
public java.lang.String getExpression()
public ElementListener getListener()
public abstract boolean match(java.lang.String path, org.xml.sax.Attributes attrs)
This method is invoked when processing the
startElement
SAX event.
Note: The default implementation ignores the attributes.
path
- the path to the element.attrs
- the SAX attributes of the element.true
is the element matches the XPath
expression, false
otherwise.public abstract boolean match(java.lang.String path, org.jdom.Element elt)
This method is invoked when processing the
endElement
SAX event. It allows matching on
data not part of the startElement
event such
as the presence of child elements.
Note: The default implementation always
returns true
as it only supports filtering on
the node path.
path
- the path to the element.elt
- the JDOM element.true
is the element matches the XPath
expression, false
otherwise.protected static java.lang.String getPathPatternAsRE(java.lang.String expr) throws org.jdom.JDOMException
expr
- an XPath expression.expression
is invalid.protected static java.lang.String getTestPattern(java.lang.String expr) throws org.jdom.JDOMException
expr
- an XPath expression.null
if no test was specified.expression
is invalid.public static void setDebug(boolean value)
value
- whether to activate debug traces.public static boolean isDebug()
true
if debug traces are active;
false
otherwise.public static void setXPathMatcherClass(java.lang.Class aClass) throws java.lang.IllegalArgumentException, org.jdom.JDOMException
aClass
- the concrete subclass of XPathMatcher.aClass
is
null
.aClass
is
not a concrete subclass
of XPathMatcher.public static final XPathMatcher newXPathMatcher(java.lang.String expression, ElementListener listener) throws org.jdom.JDOMException
expression
- the XPath-like expression to match.listener
- the element listener to notify when an
element matches the expression.expression
is invalid.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |