Package org.apache.xpath
Class XPath
java.lang.Object
org.apache.xpath.XPath
- All Implemented Interfaces:
Serializable,ExpressionOwner
public class XPath extends Object implements Serializable, ExpressionOwner
The XPath class wraps an expression object and provides general services
for execution of that expression.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static intMATCHRepresents a match type expression.static doubleMATCH_SCORE_NODETESTThe match score if the pattern consists of just a NodeTest.static doubleMATCH_SCORE_NONEThe match score if no match is made.static doubleMATCH_SCORE_NSWILDThe match score if the pattern pattern has the form NCName:*.static doubleMATCH_SCORE_OTHERThe match score if the pattern consists of something other than just a NodeTest or just a qname.static doubleMATCH_SCORE_QNAMEThe match score if the pattern has the form of a QName optionally preceded by an @ character.static intSELECTRepresents a select type expression. -
Constructor Summary
Constructors Constructor Description XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type)Construct an XPath object.XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener)Construct an XPath object.XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener, FunctionTable aTable)Construct an XPath object.XPath(Expression expr)Construct an XPath object. -
Method Summary
Modifier and Type Method Description voidassertion(boolean b, String msg)Tell the user of an assertion error, and probably throw an exception.booleanbool(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)Given an expression and a context, evaluate the XPath and return the result.voidcallVisitors(ExpressionOwner owner, XPathVisitor visitor)This will traverse the heararchy, calling the visitor for each member.voiderror(XPathContext xctxt, int sourceNode, String msg, Object[] args)Tell the user of an error, and probably throw an exception.XObjectexecute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)Given an expression and a context, evaluate the XPath and return the result.XObjectexecute(XPathContext xctxt, Node contextNode, PrefixResolver namespaceContext)Given an expression and a context, evaluate the XPath and return the result.voidfixupVariables(Vector vars, int globalsSize)This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.ExpressiongetExpression()Get the raw Expression object that this class wraps.SourceLocatorgetLocator()Get the SourceLocator on the expression object.doublegetMatchScore(XPathContext xctxt, int context)Get the match score of the given node.StringgetPatternString()Return the XPath string associated with this object.voidsetExpression(Expression exp)Set the raw expression object for this object.voidwarn(XPathContext xctxt, int sourceNode, String msg, Object[] args)Warn the user of an problem.
-
Field Details
-
SELECT
public static final int SELECTRepresents a select type expression.- See Also:
- Constant Field Values
-
MATCH
public static final int MATCHRepresents a match type expression.- See Also:
- Constant Field Values
-
MATCH_SCORE_NONE
public static final double MATCH_SCORE_NONEThe match score if no match is made.- See Also:
- Constant Field Values
-
MATCH_SCORE_QNAME
public static final double MATCH_SCORE_QNAMEThe match score if the pattern has the form of a QName optionally preceded by an @ character.- See Also:
- Constant Field Values
-
MATCH_SCORE_NSWILD
public static final double MATCH_SCORE_NSWILDThe match score if the pattern pattern has the form NCName:*.- See Also:
- Constant Field Values
-
MATCH_SCORE_NODETEST
public static final double MATCH_SCORE_NODETESTThe match score if the pattern consists of just a NodeTest.- See Also:
- Constant Field Values
-
MATCH_SCORE_OTHER
public static final double MATCH_SCORE_OTHERThe match score if the pattern consists of something other than just a NodeTest or just a qname.- See Also:
- Constant Field Values
-
-
Constructor Details
-
XPath
public XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener) throws TransformerExceptionConstruct an XPath object. (Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.- Parameters:
exprString- The XPath expression.locator- The location of the expression, may be null.prefixResolver- A prefix resolver to use to resolve prefixes to namespace URIs.type- one ofSELECTorMATCH.errorListener- The error listener, or null if default should be used.- Throws:
TransformerException- if syntax or other error.
-
XPath
public XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener, FunctionTable aTable) throws TransformerExceptionConstruct an XPath object. (Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.- Parameters:
exprString- The XPath expression.locator- The location of the expression, may be null.prefixResolver- A prefix resolver to use to resolve prefixes to namespace URIs.type- one ofSELECTorMATCH.errorListener- The error listener, or null if default should be used.- Throws:
TransformerException- if syntax or other error.
-
XPath
public XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type) throws TransformerExceptionConstruct an XPath object. (Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.- Parameters:
exprString- The XPath expression.locator- The location of the expression, may be null.prefixResolver- A prefix resolver to use to resolve prefixes to namespace URIs.type- one ofSELECTorMATCH.- Throws:
TransformerException- if syntax or other error.
-
XPath
Construct an XPath object.- Parameters:
expr- The Expression object.- Throws:
TransformerException- if syntax or other error.
-
-
Method Details
-
getExpression
Get the raw Expression object that this class wraps.- Specified by:
getExpressionin interfaceExpressionOwner- Returns:
- the raw Expression object, which should not normally be null.
-
fixupVariables
This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.- Parameters:
vars- List of QNames that correspond to variables. This list should be searched backwards for the first qualified name that corresponds to the variable reference qname. The position of the QName in the vector from the start of the vector will be its position in the stack frame (but variables above the globalsTop value will need to be offset to the current stack frame).
-
setExpression
Set the raw expression object for this object.- Specified by:
setExpressionin interfaceExpressionOwner- Parameters:
exp- the raw Expression object, which should not normally be null.
-
getLocator
Get the SourceLocator on the expression object.- Returns:
- the SourceLocator on the expression object, which may be null.
-
getPatternString
Return the XPath string associated with this object.- Returns:
- the XPath string associated with this object.
-
execute
public XObject execute(XPathContext xctxt, Node contextNode, PrefixResolver namespaceContext) throws TransformerExceptionGiven an expression and a context, evaluate the XPath and return the result.- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.namespaceContext- The context in which namespaces in the XPath are supposed to be expanded.- Returns:
- The result of the XPath or null if callbacks are used.
- Throws:
TransformerException- thrown if the error condition is severe enough to halt processing.TransformerException
-
execute
public XObject execute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws TransformerExceptionGiven an expression and a context, evaluate the XPath and return the result.- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.namespaceContext- The context in which namespaces in the XPath are supposed to be expanded.- Throws:
TransformerException- thrown if the active ProblemListener decides the error condition is severe enough to halt processing.TransformerException
-
bool
public boolean bool(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws TransformerExceptionGiven an expression and a context, evaluate the XPath and return the result.- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.namespaceContext- The context in which namespaces in the XPath are supposed to be expanded.- Throws:
TransformerException- thrown if the active ProblemListener decides the error condition is severe enough to halt processing.TransformerException
-
getMatchScore
Get the match score of the given node.- Parameters:
xctxt- XPath runtime context.context- The current source tree context node.- Returns:
- score, one of
MATCH_SCORE_NODETEST,MATCH_SCORE_NONE,MATCH_SCORE_OTHER, orMATCH_SCORE_QNAME. - Throws:
TransformerException
-
warn
public void warn(XPathContext xctxt, int sourceNode, String msg, Object[] args) throws TransformerExceptionWarn the user of an problem.- Parameters:
xctxt- The XPath runtime context.sourceNode- Not used.msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
TransformerException- if the current ErrorListoner determines to throw an exception.
-
assertion
Tell the user of an assertion error, and probably throw an exception.- Parameters:
b- If false, a runtime exception will be thrown.msg- The assertion message, which should be informative.- Throws:
RuntimeException- if the b argument is false.
-
error
public void error(XPathContext xctxt, int sourceNode, String msg, Object[] args) throws TransformerExceptionTell the user of an error, and probably throw an exception.- Parameters:
xctxt- The XPath runtime context.sourceNode- Not used.msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
TransformerException- if the current ErrorListoner determines to throw an exception.
-
callVisitors
This will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- Parameters:
owner- The owner of the visitor, where that path may be rewritten if needed.visitor- The visitor whose appropriate method will be called.
-