public class XPathCompiler
extends java.lang.Object
The programmer does not have to construct an XPathCompiler, since this is
handled internally by XPath, and the compiler is released when the XPath
no longer has need for it. XPathCompiler uses a StringReader to scan the
XPath query pattern one character at a time. It parses the query pattern
in segments, creating one pattern-matching XPathRule for each segment.
Later, when asked to match()
itself against some XML Content,
the XPath object will invoke these rules.
Modifier and Type | Field and Description |
---|---|
private int |
lastChar
The last character read from the XPath query pattern, as an integer.
|
private java.io.StringReader |
scanner
The StringReader that reads characters one at a time from the XPath
query pattern.
|
private java.util.LinkedList<XPathRule> |
xpathRules
The compiled XPath pattern, as a list of XPathRule objects.
|
private java.lang.String |
xpathString
The original XPath query pattern, as a String.
|
Constructor and Description |
---|
XPathCompiler()
Creates an XPathCompiler.
|
Modifier and Type | Method and Description |
---|---|
private void |
addFilter(Filter filter)
Adds an extra restricting Filter to the last XPathRule that was
compiled.
|
private void |
addRule(XPathRule rule)
Adds an extra XPathRule rule to the current list of XPathRules,
representing the next segment of the XPath.
|
private void |
compileAttribute()
Compiles an attribute-axis pattern.
|
private void |
compileChildOrContent()
Compiles a child-axis pattern for a child element or some other kind
of content.
|
private void |
compileContent(java.lang.String selector)
Compiles a child-axis pattern for general kinds of content.
|
private void |
compileDescendantsOrSelf()
Compiles a descendants-or-self-axis pattern.
|
private void |
compileNestedXPath(java.lang.String pattern)
Compiles a nested XPath query pattern embedded in an XPath predicate
expression.
|
private void |
compileNextSegment()
Compiles the next segment of the XPath query pattern.
|
private void |
compileParentOrSelf()
Compiles a parent-axis or self-axis pattern.
|
void |
compilePattern(java.lang.String pattern)
Compiles a fresh XPath query pattern, storing the result as a list
of XPathRules.
|
private void |
compilePosition(java.lang.String selector)
Compiles a position predicate to select the element at an index.
|
private void |
compilePredicate()
Compiles an XPath predicate expression in [...] brackets.
|
java.lang.String |
getPattern()
Returns the last XPath query pattern submitted to this compiler.
|
java.util.List<XPathRule> |
getRules()
Returns the last list of XPathRules compiled by this compiler.
|
private int |
parseDigitToken()
Parses a positive or negative digit token.
|
private java.lang.String |
parseNameToken()
Parses an XML name token.
|
private java.lang.String |
parseNestedPattern(java.lang.String token)
Extracts a nested query pattern that was enclosed in "[...]" brackets.
|
private java.lang.String |
parseOperatorToken()
Parses an operator symbol, one of six supported comparison operators.
|
private java.lang.String |
parseValueString()
Parses a value expression.
|
private void |
skipSpace()
Skips whitespace characters.
|
private void |
syntaxError(java.lang.String message)
Reports a syntax error, when badly-formed XPath syntax is detected.
|
private java.lang.String xpathString
private java.util.LinkedList<XPathRule> xpathRules
XPathRule.
private java.io.StringReader scanner
private int lastChar
public XPathCompiler()
public java.lang.String getPattern()
public java.util.List<XPathRule> getRules()
public void compilePattern(java.lang.String pattern) throws SyntaxError
pattern
- an XPath query pattern.SyntaxError
- if the XPath query pattern syntax is faulty.private void syntaxError(java.lang.String message) throws SyntaxError
message
- the error message.SyntaxError
- always.private void addFilter(Filter filter)
filter
- the Filter.private void addRule(XPathRule rule)
rule
- the XPathRule to add.private void compileNextSegment() throws SyntaxError, java.io.IOException
SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compileDescendantsOrSelf()
private void compileParentOrSelf() throws SyntaxError, java.io.IOException
SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compileAttribute() throws SyntaxError, java.io.IOException
SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compileChildOrContent() throws SyntaxError, java.io.IOException
SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compileContent(java.lang.String selector) throws SyntaxError, java.io.IOException
selector
- the name of the selector-function.SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compilePosition(java.lang.String selector) throws SyntaxError, java.io.IOException
selector
- a position-selector.SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compilePredicate() throws SyntaxError, java.io.IOException
SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private void compileNestedXPath(java.lang.String pattern)
pattern
- the nested query pattern.private java.lang.String parseNestedPattern(java.lang.String token) throws SyntaxError, java.io.IOException
token
- the first token of the nested pattern.SyntaxError
- if the XPath syntax is faulty.java.io.IOException
- if the String scanner fails.private java.lang.String parseOperatorToken() throws SyntaxError, java.io.IOException
SyntaxError
- if the operator token is malformed.java.io.IOException
- if the String scanner fails.private java.lang.String parseNameToken() throws SyntaxError, java.io.IOException
SyntaxError
- if the name token is malformed.java.io.IOException
- if the String scanner fails.private int parseDigitToken() throws SyntaxError, java.io.IOException
SyntaxError
- if the digit token is malformed.java.io.IOException
- if the String scanner fails.private java.lang.String parseValueString() throws SyntaxError, java.io.IOException
SyntaxError
- if the operator token is malformed.java.io.IOException
- if the String scanner fails.private void skipSpace() throws java.io.IOException
java.io.IOException
- if the String scanner fails.