|
|||||||||
| Home >> All >> org >> apache >> xpath >> [ compiler overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.xpath.compiler
Class XPathParser

java.lang.Objectorg.apache.xpath.compiler.XPathParser
- public class XPathParser
- extends java.lang.Object
Tokenizes and parses XPath expressions. This should really be named XPathParserImpl, and may be renamed in the future.
| Field Summary | |
static java.lang.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) org.apache.xml.utils.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) java.lang.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 ::= '@'? NodeTest Predicate |
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,
java.lang.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(java.lang.String expected)
Consume an expected token, throwing an exception if it isn't there. |
protected java.lang.String |
dumpRemainingTokenQueue()
Dump the remaining token queue. |
protected int |
EqualityExpr(int addPos)
|
(package private) void |
error(java.lang.String msg,
java.lang.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(java.lang.String key)
Given a string, return the corresponding function token. |
private java.lang.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,
java.lang.String expression,
org.apache.xml.utils.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,
java.lang.String expression,
org.apache.xml.utils.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? | IdKeyPattern (('/' | '//') RelativePathPattern)? | '//'? 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(java.lang.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]+('.'[0-9]+)? | '.'[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 ':')? LocalPart Prefix ::= NCName LocalPart ::= NCName |
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(java.lang.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(java.lang.String msg,
java.lang.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 |
CONTINUE_AFTER_FATAL_ERROR
public static final java.lang.String CONTINUE_AFTER_FATAL_ERROR
- See Also:
- Constant Field Values
m_ops
private OpMap m_ops
- The XPath to be processed.
m_token
transient java.lang.String m_token
- The next token in the pattern.
m_tokenChar
transient 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.
m_queueMark
int m_queueMark
- The position in the token queue is tracked by m_queueMark.
FILTER_MATCH_FAILED
protected static final int FILTER_MATCH_FAILED
- Results from checking FilterExpr syntax
- See Also:
- Constant Field Values
FILTER_MATCH_PRIMARY
protected static final int FILTER_MATCH_PRIMARY
- See Also:
- Constant Field Values
FILTER_MATCH_PREDICATES
protected static final int FILTER_MATCH_PREDICATES
- See Also:
- Constant Field Values
m_namespaceContext
org.apache.xml.utils.PrefixResolver m_namespaceContext
- The prefix resolver to map prefixes to namespaces in the OpMap.
m_errorListener
private javax.xml.transform.ErrorListener m_errorListener
- The error listener where syntax errors are to be sent.
m_sourceLocator
javax.xml.transform.SourceLocator m_sourceLocator
- The source location of the XPath.
| Constructor Detail |
XPathParser
public XPathParser(javax.xml.transform.ErrorListener errorListener, javax.xml.transform.SourceLocator sourceLocator)
- The parser constructor.
| Method Detail |
initXPath
public void initXPath(Compiler compiler, java.lang.String expression, org.apache.xml.utils.PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException
- 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.
initMatchPattern
public void initMatchPattern(Compiler compiler, java.lang.String expression, org.apache.xml.utils.PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException
- 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.
setErrorHandler
public void setErrorHandler(javax.xml.transform.ErrorListener handler)
- Allow an application to register an error event handler, where syntax
errors will be sent. If the error listener is not set, syntax errors
will be sent to System.err.
getErrorListener
public javax.xml.transform.ErrorListener getErrorListener()
- Return the current error listener.
tokenIs
final boolean tokenIs(java.lang.String s)
- Check whether m_token matches the target string.
tokenIs
final boolean tokenIs(char c)
- Check whether m_tokenChar==c.
lookahead
final boolean lookahead(char c,
int n)
- Look ahead of the current token in order to
make a branching decision.
lookbehind
private final boolean lookbehind(char c,
int n)
- Look behind the first character of the current token in order to
make a branching decision.
lookbehindHasToken
private final boolean lookbehindHasToken(int n)
- look behind the current token in order to
see if there is a useable token.
lookahead
private final boolean lookahead(java.lang.String s, int n)
- Look ahead of the current token in order to
make a branching decision.
nextToken
private final void nextToken()
- Retrieve the next token from the command and
store it in m_token string.
getTokenRelative
private final java.lang.String getTokenRelative(int i)
- Retrieve a token relative to the current token.
prevToken
private final void prevToken()
- Retrieve the previous token from the command and
store it in m_token string.
consumeExpected
private final void consumeExpected(java.lang.String expected) throws javax.xml.transform.TransformerException
- Consume an expected token, throwing an exception if it
isn't there.
consumeExpected
private final void consumeExpected(char expected)
throws javax.xml.transform.TransformerException
- Consume an expected token, throwing an exception if it
isn't there.
warn
void warn(java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerException
- Warn the user of a problem.
assertion
private void assertion(boolean b,
java.lang.String msg)
- Notify the user of an assertion error, and probably throw an
exception.
error
void error(java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerException
- Notify the user of an error, and probably throw an
exception.
dumpRemainingTokenQueue
protected java.lang.String dumpRemainingTokenQueue()
- Dump the remaining token queue.
Thanks to Craig for this.
getFunctionToken
final int getFunctionToken(java.lang.String key)
- Given a string, return the corresponding function token.
insertOp
void insertOp(int pos,
int length,
int op)
- Insert room for operation. This will NOT set
the length value of the operation, but will update
the length value for the total expression.
appendOp
void appendOp(int length,
int op)
- Insert room for operation. This WILL set
the length value of the operation, and will update
the length value for the total expression.
Expr
protected void Expr()
throws javax.xml.transform.TransformerException
- Expr ::= OrExpr
OrExpr
protected void OrExpr()
throws javax.xml.transform.TransformerException
- OrExpr ::= AndExpr
| OrExpr 'or' AndExpr
AndExpr
protected void AndExpr()
throws javax.xml.transform.TransformerException
- AndExpr ::= EqualityExpr
| AndExpr 'and' EqualityExpr
EqualityExpr
protected int EqualityExpr(int addPos)
throws javax.xml.transform.TransformerException
RelationalExpr
protected int RelationalExpr(int addPos)
throws javax.xml.transform.TransformerException
- .
AdditiveExpr
protected int AdditiveExpr(int addPos)
throws javax.xml.transform.TransformerException
- This has to handle construction of the operations so that they are evaluated
in pre-fix order. So, for 9+7-6, instead of |+|9|-|7|6|, this needs to be
evaluated as |-|+|9|7|6|.
AdditiveExpr ::= MultiplicativeExpr
| AdditiveExpr '+' MultiplicativeExpr
| AdditiveExpr '-' MultiplicativeExpr
MultiplicativeExpr
protected int MultiplicativeExpr(int addPos)
throws javax.xml.transform.TransformerException
- This has to handle construction of the operations so that they are evaluated
in pre-fix order. So, for 9+7-6, instead of |+|9|-|7|6|, this needs to be
evaluated as |-|+|9|7|6|.
MultiplicativeExpr ::= UnaryExpr
| MultiplicativeExpr MultiplyOperator UnaryExpr
| MultiplicativeExpr 'div' UnaryExpr
| MultiplicativeExpr 'mod' UnaryExpr
| MultiplicativeExpr 'quo' UnaryExpr
UnaryExpr
protected void UnaryExpr()
throws javax.xml.transform.TransformerException
- UnaryExpr ::= UnionExpr
| '-' UnaryExpr
StringExpr
protected void StringExpr()
throws javax.xml.transform.TransformerException
- StringExpr ::= Expr
BooleanExpr
protected void BooleanExpr()
throws javax.xml.transform.TransformerException
- StringExpr ::= Expr
NumberExpr
protected void NumberExpr()
throws javax.xml.transform.TransformerException
- NumberExpr ::= Expr
UnionExpr
protected void UnionExpr()
throws javax.xml.transform.TransformerException
- The context of the right hand side expressions is the context of the
left hand side expression. The results of the right hand side expressions
are node sets. The result of the left hand side UnionExpr is the union
of the results of the right hand side expressions.
UnionExpr ::= PathExpr
| UnionExpr '|' PathExpr
PathExpr
protected void PathExpr()
throws javax.xml.transform.TransformerException
- PathExpr ::= LocationPath
| FilterExpr
| FilterExpr '/' RelativeLocationPath
| FilterExpr '//' RelativeLocationPath
FilterExpr
protected int FilterExpr()
throws javax.xml.transform.TransformerException
- FilterExpr ::= PrimaryExpr
| FilterExpr Predicate
PrimaryExpr
protected boolean PrimaryExpr()
throws javax.xml.transform.TransformerException
- PrimaryExpr ::= VariableReference
| '(' Expr ')'
| Literal
| Number
| FunctionCall
Argument
protected void Argument()
throws javax.xml.transform.TransformerException
- Argument ::= Expr
FunctionCall
protected boolean FunctionCall()
throws javax.xml.transform.TransformerException
- FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? ')'
LocationPath
protected void LocationPath()
throws javax.xml.transform.TransformerException
- LocationPath ::= RelativeLocationPath
| AbsoluteLocationPath
RelativeLocationPath
protected boolean RelativeLocationPath()
throws javax.xml.transform.TransformerException
- RelativeLocationPath ::= Step
| RelativeLocationPath '/' Step
| AbbreviatedRelativeLocationPath
Step
protected boolean Step()
throws javax.xml.transform.TransformerException
- Step ::= Basis Predicate
| AbbreviatedStep
Basis
protected void Basis()
throws javax.xml.transform.TransformerException
- Basis ::= AxisName '::' NodeTest
| AbbreviatedBasis
AxisName
protected int AxisName()
throws javax.xml.transform.TransformerException
- Basis ::= AxisName '::' NodeTest
| AbbreviatedBasis
NodeTest
protected void NodeTest(int axesType)
throws javax.xml.transform.TransformerException
- NodeTest ::= WildcardName
| NodeType '(' ')'
| 'processing-instruction' '(' Literal ')'
Predicate
protected void Predicate()
throws javax.xml.transform.TransformerException
- Predicate ::= '[' PredicateExpr ']'
PredicateExpr
protected void PredicateExpr()
throws javax.xml.transform.TransformerException
- PredicateExpr ::= Expr
QName
protected void QName()
throws javax.xml.transform.TransformerException
- QName ::= (Prefix ':')? LocalPart
Prefix ::= NCName
LocalPart ::= NCName
NCName
protected void NCName()
- NCName ::= (Letter | '_') (NCNameChar)
NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
Literal
protected void Literal()
throws javax.xml.transform.TransformerException
- The value of the Literal is the sequence of characters inside
the " or ' characters>.
Literal ::= '"' [^"]* '"'
| "'" [^']* "'"
Number
protected void Number()
throws javax.xml.transform.TransformerException
- Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
Pattern
protected void Pattern()
throws javax.xml.transform.TransformerException
- Pattern ::= LocationPathPattern
| Pattern '|' LocationPathPattern
LocationPathPattern
protected void LocationPathPattern()
throws javax.xml.transform.TransformerException
- LocationPathPattern ::= '/' RelativePathPattern?
| IdKeyPattern (('/' | '//') RelativePathPattern)?
| '//'? RelativePathPattern
IdKeyPattern
protected void IdKeyPattern()
throws javax.xml.transform.TransformerException
- IdKeyPattern ::= 'id' '(' Literal ')'
| 'key' '(' Literal ',' Literal ')'
(Also handle doc())
RelativePathPattern
protected void RelativePathPattern()
throws javax.xml.transform.TransformerException
- RelativePathPattern ::= StepPattern
| RelativePathPattern '/' StepPattern
| RelativePathPattern '//' StepPattern
StepPattern
protected boolean StepPattern(boolean isLeadingSlashPermitted)
throws javax.xml.transform.TransformerException
- StepPattern ::= AbbreviatedNodeTestStep
AbbreviatedNodeTestStep
protected boolean AbbreviatedNodeTestStep(boolean isLeadingSlashPermitted)
throws javax.xml.transform.TransformerException
- AbbreviatedNodeTestStep ::= '@'? NodeTest Predicate
|
|||||||||
| Home >> All >> org >> apache >> xpath >> [ compiler overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.xpath.compiler.XPathParser