|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.xpath.compiler.XPathParser
Tokenizes and parses XPath expressions. This should really be named XPathParserImpl, and may be renamed in the future.
Field Summary | |
static String |
CONTINUE_AFTER_FATAL_ERROR
|
protected static int |
FILTER_MATCH_FAILED
Results from checking FilterExpr syntax |
protected static int |
FILTER_MATCH_PREDICATES
|
protected static int |
FILTER_MATCH_PRIMARY
|
private javax.xml.transform.ErrorListener |
m_errorListener
The error listener where syntax errors are to be sent. |
(package private) PrefixResolver |
m_namespaceContext
The prefix resolver to map prefixes to namespaces in the OpMap. |
private OpMap |
m_ops
The XPath to be processed. |
(package private) int |
m_queueMark
The position in the token queue is tracked by m_queueMark. |
(package private) javax.xml.transform.SourceLocator |
m_sourceLocator
The source location of the XPath. |
(package private) String |
m_token
The next token in the pattern. |
(package private) char |
m_tokenChar
The first char in m_token, the theory being that this is an optimization because we won't have to do charAt(0) as often. |
Constructor Summary | |
XPathParser(javax.xml.transform.ErrorListener errorListener,
javax.xml.transform.SourceLocator sourceLocator)
The parser constructor. |
Method Summary | |
protected boolean |
AbbreviatedNodeTestStep(boolean isLeadingSlashPermitted)
AbbreviatedNodeTestStep ::= '@'? |
protected int |
AdditiveExpr(int addPos)
This has to handle construction of the operations so that they are evaluated in pre-fix order. |
protected void |
AndExpr()
AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr |
(package private) void |
appendOp(int length,
int op)
Insert room for operation. |
protected void |
Argument()
Argument ::= Expr |
private void |
assertion(boolean b,
String msg)
Notify the user of an assertion error, and probably throw an exception. |
protected int |
AxisName()
Basis ::= AxisName '::' NodeTest | AbbreviatedBasis |
protected void |
Basis()
Basis ::= AxisName '::' NodeTest | AbbreviatedBasis |
protected void |
BooleanExpr()
StringExpr ::= Expr |
private void |
consumeExpected(char expected)
Consume an expected token, throwing an exception if it isn't there. |
private void |
consumeExpected(String expected)
Consume an expected token, throwing an exception if it isn't there. |
protected String |
dumpRemainingTokenQueue()
Dump the remaining token queue. |
protected int |
EqualityExpr(int addPos)
|
(package private) void |
error(String msg,
Object[] args)
Notify the user of an error, and probably throw an exception. |
protected void |
Expr()
Expr ::= OrExpr |
protected int |
FilterExpr()
FilterExpr ::= PrimaryExpr | FilterExpr Predicate |
protected boolean |
FunctionCall()
FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? |
javax.xml.transform.ErrorListener |
getErrorListener()
Return the current error listener. |
(package private) int |
getFunctionToken(String key)
Given a string, return the corresponding function token. |
private String |
getTokenRelative(int i)
Retrieve a token relative to the current token. |
protected void |
IdKeyPattern()
IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' (Also handle doc()) |
void |
initMatchPattern(Compiler compiler,
String expression,
PrefixResolver namespaceContext)
Given an string, init an XPath object for pattern matches, in order that a parse doesn't have to be done each time the expression is evaluated. |
void |
initXPath(Compiler compiler,
String expression,
PrefixResolver namespaceContext)
Given an string, init an XPath object for selections, in order that a parse doesn't have to be done each time the expression is evaluated. |
(package private) void |
insertOp(int pos,
int length,
int op)
Insert room for operation. |
protected void |
Literal()
The value of the Literal is the sequence of characters inside the " or ' characters>. |
protected void |
LocationPath()
LocationPath ::= RelativeLocationPath | AbsoluteLocationPath |
protected void |
LocationPathPattern()
LocationPathPattern ::= '/' RelativePathPattern? |
(package private) boolean |
lookahead(char c,
int n)
Look ahead of the current token in order to make a branching decision. |
private boolean |
lookahead(String s,
int n)
Look ahead of the current token in order to make a branching decision. |
private boolean |
lookbehind(char c,
int n)
Look behind the first character of the current token in order to make a branching decision. |
private boolean |
lookbehindHasToken(int n)
look behind the current token in order to see if there is a useable token. |
protected int |
MultiplicativeExpr(int addPos)
This has to handle construction of the operations so that they are evaluated in pre-fix order. |
protected void |
NCName()
NCName ::= (Letter | '_') (NCNameChar) NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender |
private void |
nextToken()
Retrieve the next token from the command and store it in m_token string. |
protected void |
NodeTest(int axesType)
NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')' |
protected void |
Number()
Number ::= [0-9]+(' |
protected void |
NumberExpr()
NumberExpr ::= Expr |
protected void |
OrExpr()
OrExpr ::= AndExpr | OrExpr 'or' AndExpr |
protected void |
PathExpr()
PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath |
protected void |
Pattern()
Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern |
protected void |
Predicate()
Predicate ::= '[' PredicateExpr ']' |
protected void |
PredicateExpr()
PredicateExpr ::= Expr |
private void |
prevToken()
Retrieve the previous token from the command and store it in m_token string. |
protected boolean |
PrimaryExpr()
PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall |
protected void |
QName()
QName ::= (Prefix ':')? |
protected int |
RelationalExpr(int addPos)
. |
protected boolean |
RelativeLocationPath()
RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath |
protected void |
RelativePathPattern()
RelativePathPattern ::= StepPattern | RelativePathPattern '/' StepPattern | RelativePathPattern '//' StepPattern |
void |
setErrorHandler(javax.xml.transform.ErrorListener handler)
Allow an application to register an error event handler, where syntax errors will be sent. |
protected boolean |
Step()
Step ::= Basis Predicate | AbbreviatedStep |
protected boolean |
StepPattern(boolean isLeadingSlashPermitted)
StepPattern ::= AbbreviatedNodeTestStep |
protected void |
StringExpr()
StringExpr ::= Expr |
(package private) boolean |
tokenIs(char c)
Check whether m_tokenChar==c. |
(package private) boolean |
tokenIs(String s)
Check whether m_token matches the target string. |
protected void |
UnaryExpr()
UnaryExpr ::= UnionExpr | '-' UnaryExpr |
protected void |
UnionExpr()
The context of the right hand side expressions is the context of the left hand side expression. |
(package private) void |
warn(String msg,
Object[] args)
Warn the user of a problem. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String CONTINUE_AFTER_FATAL_ERROR
private OpMap m_ops
transient String m_token
transient char m_tokenChar
int m_queueMark
protected static final int FILTER_MATCH_FAILED
protected static final int FILTER_MATCH_PRIMARY
protected static final int FILTER_MATCH_PREDICATES
PrefixResolver m_namespaceContext
private javax.xml.transform.ErrorListener m_errorListener
javax.xml.transform.SourceLocator m_sourceLocator
Constructor Detail |
public XPathParser(javax.xml.transform.ErrorListener errorListener, javax.xml.transform.SourceLocator sourceLocator)
Method Detail |
public void initXPath(Compiler compiler, String expression, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException
compiler
- The compiler object.expression
- A string conforming to the XPath grammar.namespaceContext
- An object that is able to resolve prefixes in
the XPath to namespaces.
javax.xml.transform.TransformerException
public void initMatchPattern(Compiler compiler, String expression, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException
compiler
- The XPath object to be initialized.expression
- A String representing the XPath.namespaceContext
- An object that is able to resolve prefixes in
the XPath to namespaces.
javax.xml.transform.TransformerException
public void setErrorHandler(javax.xml.transform.ErrorListener handler)
handler
- Reference to error listener where syntax errors will be
sent.public javax.xml.transform.ErrorListener getErrorListener()
final boolean tokenIs(String s)
s
- A string reference or null.
final boolean tokenIs(char c)
c
- A character to be tested.
final boolean lookahead(char c, int n)
c
- the character to be tested for.n
- number of tokens to look ahead. Must be
greater than 1.
private final boolean lookbehind(char c, int n)
c
- the character to compare it to.n
- number of tokens to look behind. Must be
greater than 1. Note that the look behind terminates
at either the beginning of the string or on a '|'
character. Because of this, this method should only
be used for pattern matching.
private final boolean lookbehindHasToken(int n)
n
- number of tokens to look behind. Must be
greater than 1. Note that the look behind terminates
at either the beginning of the string or on a '|'
character. Because of this, this method should only
be used for pattern matching.
private final boolean lookahead(String s, int n)
s
- the string to compare it to.n
- number of tokens to lookahead. Must be
greater than 1.
private final void nextToken()
private final String getTokenRelative(int i)
i
- Position relative to current token.
private final void prevToken()
private final void consumeExpected(String expected) throws javax.xml.transform.TransformerException
expected
- The string to be expected.
javax.xml.transform.TransformerException
private final void consumeExpected(char expected) throws javax.xml.transform.TransformerException
expected
- the character to be expected.
javax.xml.transform.TransformerException
void warn(String msg, Object[] args) throws javax.xml.transform.TransformerException
msg
- An error msgkey that corresponds to one of the constants found
in XPATHErrorResources
, which is
a key for a format string.args
- An array of arguments represented in the format string, which
may be null.
javax.xml.transform.TransformerException
- if the current ErrorListoner determines to
throw an exception.private void assertion(boolean b, String msg)
b
- If false, a runtime exception will be thrown.msg
- The assertion message, which should be informative.
RuntimeException
- if the b argument is false.void error(String msg, Object[] args) throws javax.xml.transform.TransformerException
msg
- An error msgkey that corresponds to one of the constants found
in XPATHErrorResources
, which is
a key for a format string.args
- An array of arguments represented in the format string, which
may be null.
javax.xml.transform.TransformerException
- if the current ErrorListoner determines to
throw an exception.protected String dumpRemainingTokenQueue()
final int getFunctionToken(String key)
key
- A local name of a function.
FunctionTable
, but may
be a value installed by an external module.void insertOp(int pos, int length, int op)
pos
- The position where the op is to be inserted.length
- The length of the operation space in the op map.op
- The op code to the inserted.void appendOp(int length, int op)
length
- The length of the operation.op
- The op code to the inserted.protected void Expr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void OrExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void AndExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected int EqualityExpr(int addPos) throws javax.xml.transform.TransformerException
addPos
- Position where expression is to be added, or -1 for append.
javax.xml.transform.TransformerException
protected int RelationalExpr(int addPos) throws javax.xml.transform.TransformerException
addPos
- Position where expression is to be added, or -1 for append.
javax.xml.transform.TransformerException
protected int AdditiveExpr(int addPos) throws javax.xml.transform.TransformerException
addPos
- Position where expression is to be added, or -1 for append.
javax.xml.transform.TransformerException
protected int MultiplicativeExpr(int addPos) throws javax.xml.transform.TransformerException
addPos
- Position where expression is to be added, or -1 for append.
javax.xml.transform.TransformerException
protected void UnaryExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void StringExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void BooleanExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void NumberExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void UnionExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void PathExpr() throws javax.xml.transform.TransformerException
XSLProcessorException
- thrown if the active ProblemListener and XPathContext decide
the error condition is severe enough to halt processing.
javax.xml.transform.TransformerException
protected int FilterExpr() throws javax.xml.transform.TransformerException
XSLProcessorException
- thrown if the active ProblemListener and XPathContext decide
the error condition is severe enough to halt processing.
javax.xml.transform.TransformerException
protected boolean PrimaryExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void Argument() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected boolean FunctionCall() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void LocationPath() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected boolean RelativeLocationPath() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected boolean Step() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void Basis() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected int AxisName() throws javax.xml.transform.TransformerException
Keywords
.
javax.xml.transform.TransformerException
protected void NodeTest(int axesType) throws javax.xml.transform.TransformerException
axesType
- FROM_XXX axes type, found in Keywords
.
javax.xml.transform.TransformerException
protected void Predicate() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void PredicateExpr() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void QName() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void NCName()
protected void Literal() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void Number() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void Pattern() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void LocationPathPattern() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void IdKeyPattern() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected void RelativePathPattern() throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected boolean StepPattern(boolean isLeadingSlashPermitted) throws javax.xml.transform.TransformerException
isLeadingSlashPermitted
- a boolean indicating whether a slash can
appear at the start of this step
javax.xml.transform.TransformerException
protected boolean AbbreviatedNodeTestStep(boolean isLeadingSlashPermitted) throws javax.xml.transform.TransformerException
isLeadingSlashPermitted
- a boolean indicating whether a slash can
appear at the start of this step
javax.xml.transform.TransformerException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |