/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPath.java,v 1.2.4.1 2005/09/15 01:41:57 jeffsuttor Exp $
*/
/**
* The XPath class wraps an expression object and provides general services
* for execution of that expression.
* @xsl.usage advanced
*/
{
/** The top of the expression tree.
* @serial */
/**
* The function table for xpath build-in functions
*/
/**
* initial the function table
*/
private void initFunctionTable(){
m_funcTable = new FunctionTable();
}
/**
* Get the raw Expression object that this class wraps.
*
*
* @return the raw Expression object, which should not normally be null.
*/
{
return m_mainExp;
}
/**
* This function is used to fixup variables from QNames to stack frame
* indexes at stylesheet build time.
* @param 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).
*/
{
}
/**
* Set the raw expression object for this object.
*
*
* @param exp the raw Expression object, which should not normally be null.
*/
{
}
/**
* Get the SourceLocator on the expression object.
*
*
* @return the SourceLocator on the expression object, which may be null.
*/
{
return m_mainExp;
}
// /**
// * Set the SourceLocator on the expression object.
// *
// *
// * @param l the SourceLocator on the expression object, which may be null.
// */
// public void setLocator(SourceLocator l)
// {
// // Note potential hazards -- l may not be serializable, or may be changed
// // after being assigned here.
// m_mainExp.setSourceLocator(l);
// }
/** The pattern string, mainly kept around for diagnostic purposes.
* @serial */
/**
* Return the XPath string associated with this object.
*
*
* @return the XPath string associated with this object.
*/
{
return m_patternString;
}
/** Represents a select type expression. */
/** Represents a match type expression. */
/**
* Construct an XPath object.
*
* (Needs review -sc) This method initializes an XPathParser/
* Compiler and compiles the expression.
* @param exprString The XPath expression.
* @param locator The location of the expression, may be null.
* @param prefixResolver A prefix resolver to use to resolve prefixes to
* namespace URIs.
* @param type one of {@link #SELECT} or {@link #MATCH}.
* @param errorListener The error listener, or null if default should be used.
*
* @throws javax.xml.transform.TransformerException if syntax or other error.
*/
public XPath(
{
if(null == errorListener)
else
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type);
// System.out.println("----------------");
// System.out.println("expr: "+expr);
this.setExpression(expr);
{
}
}
/**
* Construct an XPath object.
*
* (Needs review -sc) This method initializes an XPathParser/
* Compiler and compiles the expression.
* @param exprString The XPath expression.
* @param locator The location of the expression, may be null.
* @param prefixResolver A prefix resolver to use to resolve prefixes to
* namespace URIs.
* @param type one of {@link #SELECT} or {@link #MATCH}.
* @param errorListener The error listener, or null if default should be used.
*
* @throws javax.xml.transform.TransformerException if syntax or other error.
*/
public XPath(
{
if(null == errorListener)
else
//"Can not deal with XPath type: " + type);
// System.out.println("----------------");
// System.out.println("expr: "+expr);
this.setExpression(expr);
{
}
}
/**
* Construct an XPath object.
*
* (Needs review -sc) This method initializes an XPathParser/
* Compiler and compiles the expression.
* @param exprString The XPath expression.
* @param locator The location of the expression, may be null.
* @param prefixResolver A prefix resolver to use to resolve prefixes to
* namespace URIs.
* @param type one of {@link #SELECT} or {@link #MATCH}.
*
* @throws javax.xml.transform.TransformerException if syntax or other error.
*/
public XPath(
{
}
/**
* Construct an XPath object.
*
* @param expr The Expression object.
*
* @throws javax.xml.transform.TransformerException if syntax or other error.
*/
{
this.setExpression(expr);
}
/**
* Given an expression and a context, evaluate the XPath
* and return the result.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
* @param namespaceContext The context in which namespaces in the
* XPath are supposed to be expanded.
*
* @return The result of the XPath or null if callbacks are used.
* @throws TransformerException thrown if
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
{
return execute(
}
/**
* Given an expression and a context, evaluate the XPath
* and return the result.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
* @param 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.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
{
try
{
}
catch (TransformerException te)
{
{
}
else
throw te;
}
catch (Exception e)
{
{
}
// e.printStackTrace();
}
getLocator(), e);
// te.printStackTrace();
{
}
else
throw te;
}
finally
{
}
return xobj;
}
/**
* Given an expression and a context, evaluate the XPath
* and return the result.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
* @param 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.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
public boolean bool(
{
try
{
}
catch (TransformerException te)
{
{
}
else
throw te;
}
catch (Exception e)
{
{
}
// e.printStackTrace();
}
getLocator(), e);
// te.printStackTrace();
{
}
else
throw te;
}
finally
{
}
return false;
}
/** Set to true to get diagnostic messages about the result of
* match pattern testing. */
private static final boolean DEBUG_MATCHES = false;
/**
* Get the match score of the given node.
*
* @param xctxt XPath runtime context.
* @param context The current source tree context node.
*
* @return score, one of {@link #MATCH_SCORE_NODETEST},
* {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER},
* or {@link #MATCH_SCORE_QNAME}.
*
* @throws javax.xml.transform.TransformerException
*/
{
try
{
if (DEBUG_MATCHES)
{
+ this.getPatternString());
}
}
finally
{
}
// return XPath.MATCH_SCORE_NONE;
}
/**
* Warn the user of an problem.
*
* @param xctxt The XPath runtime context.
* @param sourceNode Not used.
* @param msg An error msgkey that corresponds to one of the constants found
* in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
* a key for a format string.
* @param 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.
*/
public void warn(
{
{
// TO DO: Need to get stylesheet Locator from here.
}
}
/**
* Tell the user of an assertion error, and probably throw an
* exception.
*
* @param b If false, a runtime exception will be thrown.
* @param msg The assertion message, which should be informative.
*
* @throws RuntimeException if the b argument is false.
*/
{
if (!b)
{
throw new RuntimeException(fMsg);
}
}
/**
* Tell the user of an error, and probably throw an
* exception.
*
* @param xctxt The XPath runtime context.
* @param sourceNode Not used.
* @param msg An error msgkey that corresponds to one of the constants found
* in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
* a key for a format string.
* @param 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.
*/
public void error(
{
{
}
else
{
+ slocator.getColumnNumber());
}
}
/**
* This will traverse the heararchy, calling the visitor for
* each member. If the called visitor method returns
* false, the subtree should not be called.
*
* @param owner The owner of the visitor, where that path may be
* rewritten if needed.
* @param visitor The visitor whose appropriate method will be called.
*/
{
}
/**
* The match score if no match is made.
* @xsl.usage advanced
*/
/**
* The match score if the pattern has the form
* of a QName optionally preceded by an @ character.
* @xsl.usage advanced
*/
/**
* The match score if the pattern pattern has the form NCName:*.
* @xsl.usage advanced
*/
/**
* The match score if the pattern consists of just a NodeTest.
* @xsl.usage advanced
*/
/**
* The match score if the pattern consists of something
* other than just a NodeTest or just a qname.
* @xsl.usage advanced
*/
}