Java Code Examples for com.sun.org.apache.xml.internal.utils.PrefixResolver

The following examples show how to use com.sun.org.apache.xml.internal.utils.PrefixResolver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: XPathEvaluatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 3
Source Project: JDKSourceCode1.8   Source File: XPathEvaluatorImpl.java    License: MIT License 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 4
Source Project: jdk8u60   Source File: XPathEvaluatorImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example 5
Source Project: jdk1.8-source-analysis   Source File: LocPathIterator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a LocPathIterator object.
 *
 * @param nscontext The namespace context for this iterator,
 * should be OK if null.
 */
protected LocPathIterator(PrefixResolver nscontext)
{

  setLocPathIterator(this);
  m_prefixResolver = nscontext;
}
 
Example 6
Source Project: jdk1.8-source-analysis   Source File: XPath.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  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("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 7
Source Project: jdk1.8-source-analysis   Source File: XPath.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator,
        PrefixResolver prefixResolver, int type,
        ErrorListener errorListener, FunctionTable aTable)
          throws javax.xml.transform.TransformerException
{
  m_funcTable = aTable;
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  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("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 8
Source Project: JDKSourceCode1.8   Source File: Lexer.java    License: MIT License 5 votes vote down vote up
/**
 * Create a Lexer object.
 *
 * @param compiler The owning compiler for this lexer.
 * @param resolver The prefix resolver for mapping qualified name prefixes
 *                 to namespace URIs.
 * @param xpathProcessor The parser that is processing strings to opcodes.
 */
Lexer(Compiler compiler, PrefixResolver resolver,
      XPathParser xpathProcessor)
{

  m_compiler = compiler;
  m_namespaceContext = resolver;
  m_processor = xpathProcessor;
}
 
Example 9
Source Project: jdk1.8-source-analysis   Source File: Lexer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a Lexer object.
 *
 * @param compiler The owning compiler for this lexer.
 * @param resolver The prefix resolver for mapping qualified name prefixes
 *                 to namespace URIs.
 * @param xpathProcessor The parser that is processing strings to opcodes.
 */
Lexer(Compiler compiler, PrefixResolver resolver,
      XPathParser xpathProcessor)
{

  m_compiler = compiler;
  m_namespaceContext = resolver;
  m_processor = xpathProcessor;
}
 
Example 10
/**
 * Create a LocPathIterator object.
 *
 * @param nscontext The namespace context for this iterator,
 * should be OK if null.
 */
protected LocPathIterator(PrefixResolver nscontext)
{

  setLocPathIterator(this);
  m_prefixResolver = nscontext;
}
 
Example 11
Source Project: openjdk-jdk8u   Source File: XPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
            new Object[]{Integer.toString(type)}));

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 12
Source Project: TencentKona-8   Source File: XPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
            new Object[]{Integer.toString(type)}));

  // System.out.println("----------------");
  Expression expr = compiler.compileExpression(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 13
Source Project: JDKSourceCode1.8   Source File: XPath.java    License: MIT License 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  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("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 14
Source Project: jdk8u60   Source File: LocPathIterator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a LocPathIterator object.
 *
 * @param nscontext The namespace context for this iterator,
 * should be OK if null.
 */
protected LocPathIterator(PrefixResolver nscontext)
{

  setLocPathIterator(this);
  m_prefixResolver = nscontext;
}
 
Example 15
Source Project: jdk8u60   Source File: XPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{
  initFunctionTable();
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  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("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 16
Source Project: jdk8u60   Source File: XPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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(
        String exprString, SourceLocator locator,
        PrefixResolver prefixResolver, int type,
        ErrorListener errorListener, FunctionTable aTable)
          throws javax.xml.transform.TransformerException
{
  m_funcTable = aTable;
  if(null == errorListener)
    errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler();

  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  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("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);

  if((null != locator) && locator instanceof ExpressionNode)
  {
      expr.exprSetParent((ExpressionNode)locator);
  }

}
 
Example 17
Source Project: jdk8u60   Source File: Lexer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a Lexer object.
 *
 * @param compiler The owning compiler for this lexer.
 * @param resolver The prefix resolver for mapping qualified name prefixes
 *                 to namespace URIs.
 * @param xpathProcessor The parser that is processing strings to opcodes.
 */
Lexer(Compiler compiler, PrefixResolver resolver,
      XPathParser xpathProcessor)
{

  m_compiler = compiler;
  m_namespaceContext = resolver;
  m_processor = xpathProcessor;
}
 
Example 18
Source Project: jdk1.8-source-analysis   Source File: PredicatedNodeTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 19
Source Project: jdk1.8-source-analysis   Source File: XPathParser.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 * @param compiler The XPath object to be initialized.
 * @param expression A String representing the XPath.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initMatchPattern(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0, OpCodes.OP_MATCHPATTERN);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);

  nextToken();
  Pattern();

  if (null != m_token)
  {
    String extraTokens = "";

    while (null != m_token)
    {
      extraTokens += "'" + m_token + "'";

      nextToken();

      if (null != m_token)
        extraTokens += ", ";
    }

    error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
          new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
  }

  // Terminate for safety.
  m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);

  m_ops.shrink();
}
 
Example 20
Source Project: JDKSourceCode1.8   Source File: XPathParser.java    License: MIT License 4 votes vote down vote up
/**
 * 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.
 * @param compiler The XPath object to be initialized.
 * @param expression A String representing the XPath.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initMatchPattern(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0, OpCodes.OP_MATCHPATTERN);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);

  nextToken();
  Pattern();

  if (null != m_token)
  {
    String extraTokens = "";

    while (null != m_token)
    {
      extraTokens += "'" + m_token + "'";

      nextToken();

      if (null != m_token)
        extraTokens += ", ";
    }

    error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
          new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
  }

  // Terminate for safety.
  m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);

  m_ops.shrink();
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: XPathParser.java    License: MIT License 4 votes vote down vote up
/**
 * 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.
 *
 * @param compiler The compiler object.
 * @param expression A string conforming to the XPath grammar.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initXPath(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0,OpCodes.OP_XPATH);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH,2);


      // Patch for Christine's gripe. She wants her errorHandler to return from
      // a fatal error and continue trying to parse, rather than throwing an exception.
      // Without the patch, that put us into an endless loop.
      //
      // %REVIEW% Is there a better way of doing this?
      // %REVIEW% Are there any other cases which need the safety net?
      //      (and if so do we care right now, or should we rewrite the XPath
      //      grammar engine and can fix it at that time?)
      try {

    nextToken();
    Expr();

    if (null != m_token)
    {
      String extraTokens = "";

      while (null != m_token)
      {
        extraTokens += "'" + m_token + "'";

        nextToken();

        if (null != m_token)
          extraTokens += ", ";
      }

      error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
            new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
    }

  }
  catch (com.sun.org.apache.xpath.internal.XPathProcessorException e)
  {
        if(CONTINUE_AFTER_FATAL_ERROR.equals(e.getMessage()))
        {
              // What I _want_ to do is null out this XPath.
              // I doubt this has the desired effect, but I'm not sure what else to do.
              // %REVIEW%!!!
              initXPath(compiler, "/..",  namespaceContext);
        }
        else
              throw e;
  }

  compiler.shrink();
}
 
Example 22
Source Project: openjdk-jdk8u   Source File: CachedXPathAPI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 *   Evaluate XPath string to an XObject.
 *   XPath namespace prefixes are resolved from the namespaceNode.
 *   The implementation of this is a little slow, since it creates
 *   a number of objects each time it is called.  This could be optimized
 *   to keep the same objects around, but then thread-safety issues would arise.
 *
 *   @param contextNode The node to start searching from.
 *   @param str A valid XPath string.
 *   @param prefixResolver Will be called if the parser encounters namespace
 *                         prefixes, to resolve the prefixes to URLs.
 *   @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
 *   @see com.sun.org.apache.xpath.internal.objects.XObject
 *   @see com.sun.org.apache.xpath.internal.objects.XNull
 *   @see com.sun.org.apache.xpath.internal.objects.XBoolean
 *   @see com.sun.org.apache.xpath.internal.objects.XNumber
 *   @see com.sun.org.apache.xpath.internal.objects.XString
 *   @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public  XObject eval(
        Node contextNode, String str, PrefixResolver prefixResolver)
          throws TransformerException
{

  // Since we don't have a XML Parser involved here, install some default support
  // for things like namespaces, etc.
  // (Changed from: XPathContext xpathSupport = new XPathContext();
  //    because XPathContext is weak in a number of areas... perhaps
  //    XPathContext should be done away with.)
  // Create the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // Execute the XPath, and have it return the result
  XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
  int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

  return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
 
Example 23
Source Project: TencentKona-8   Source File: CachedXPathAPI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 *   Evaluate XPath string to an XObject.
 *   XPath namespace prefixes are resolved from the namespaceNode.
 *   The implementation of this is a little slow, since it creates
 *   a number of objects each time it is called.  This could be optimized
 *   to keep the same objects around, but then thread-safety issues would arise.
 *
 *   @param contextNode The node to start searching from.
 *   @param str A valid XPath string.
 *   @param prefixResolver Will be called if the parser encounters namespace
 *                         prefixes, to resolve the prefixes to URLs.
 *   @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
 *   @see com.sun.org.apache.xpath.internal.objects.XObject
 *   @see com.sun.org.apache.xpath.internal.objects.XNull
 *   @see com.sun.org.apache.xpath.internal.objects.XBoolean
 *   @see com.sun.org.apache.xpath.internal.objects.XNumber
 *   @see com.sun.org.apache.xpath.internal.objects.XString
 *   @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public  XObject eval(
        Node contextNode, String str, PrefixResolver prefixResolver)
          throws TransformerException
{

  // Since we don't have a XML Parser involved here, install some default support
  // for things like namespaces, etc.
  // (Changed from: XPathContext xpathSupport = new XPathContext();
  //    because XPathContext is weak in a number of areas... perhaps
  //    XPathContext should be done away with.)
  // Create the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // Execute the XPath, and have it return the result
  XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
  int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

  return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
 
Example 24
Source Project: TencentKona-8   Source File: XPathParser.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param compiler The compiler object.
 * @param expression A string conforming to the XPath grammar.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initXPath(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0,OpCodes.OP_XPATH);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH,2);


      // Patch for Christine's gripe. She wants her errorHandler to return from
      // a fatal error and continue trying to parse, rather than throwing an exception.
      // Without the patch, that put us into an endless loop.
      //
      // %REVIEW% Is there a better way of doing this?
      // %REVIEW% Are there any other cases which need the safety net?
      //      (and if so do we care right now, or should we rewrite the XPath
      //      grammar engine and can fix it at that time?)
      try {

    nextToken();
    Expr();

    if (null != m_token)
    {
      String extraTokens = "";

      while (null != m_token)
      {
        extraTokens += "'" + m_token + "'";

        nextToken();

        if (null != m_token)
          extraTokens += ", ";
      }

      error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
            new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
    }

  }
  catch (com.sun.org.apache.xpath.internal.XPathProcessorException e)
  {
        if(CONTINUE_AFTER_FATAL_ERROR.equals(e.getMessage()))
        {
              // What I _want_ to do is null out this XPath.
              // I doubt this has the desired effect, but I'm not sure what else to do.
              // %REVIEW%!!!
              initXPath(compiler, "/..",  namespaceContext);
        }
        else
              throw e;
  } catch (StackOverflowError sof) {
      error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN,
            new Object[]{m_token, m_queueMark, countPredicate});
  }

  compiler.shrink();
}
 
Example 25
Source Project: TencentKona-8   Source File: XPathParser.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 * @param compiler The XPath object to be initialized.
 * @param expression A String representing the XPath.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initMatchPattern(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0, OpCodes.OP_MATCHPATTERN);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);

  nextToken();
  try {
      Pattern();
  } catch (StackOverflowError sof) {
      error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN,
            new Object[]{m_token, m_queueMark, countPredicate});
  }

  if (null != m_token)
  {
    String extraTokens = "";

    while (null != m_token)
    {
      extraTokens += "'" + m_token + "'";

      nextToken();

      if (null != m_token)
        extraTokens += ", ";
    }

    error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
          new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
  }

  // Terminate for safety.
  m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);

  m_ops.shrink();
}
 
Example 26
Source Project: openjdk-jdk8u   Source File: XPathParser.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 * @param compiler The XPath object to be initialized.
 * @param expression A String representing the XPath.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initMatchPattern(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0, OpCodes.OP_MATCHPATTERN);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);

  nextToken();
  try {
      Pattern();
  } catch (StackOverflowError sof) {
      error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN,
            new Object[]{m_token, m_queueMark, countPredicate});
  }

  if (null != m_token)
  {
    String extraTokens = "";

    while (null != m_token)
    {
      extraTokens += "'" + m_token + "'";

      nextToken();

      if (null != m_token)
        extraTokens += ", ";
    }

    error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
          new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
  }

  // Terminate for safety.
  m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);

  m_ops.shrink();
}
 
Example 27
Source Project: jdk8u60   Source File: XPathAPI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 *   Evaluate XPath string to an XObject.
 *   XPath namespace prefixes are resolved from the namespaceNode.
 *   The implementation of this is a little slow, since it creates
 *   a number of objects each time it is called.  This could be optimized
 *   to keep the same objects around, but then thread-safety issues would arise.
 *
 *   @param contextNode The node to start searching from.
 *   @param str A valid XPath string.
 *   @param prefixResolver Will be called if the parser encounters namespace
 *                         prefixes, to resolve the prefixes to URLs.
 *   @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
 *   @see com.sun.org.apache.xpath.internal.objects.XObject
 *   @see com.sun.org.apache.xpath.internal.objects.XNull
 *   @see com.sun.org.apache.xpath.internal.objects.XBoolean
 *   @see com.sun.org.apache.xpath.internal.objects.XNumber
 *   @see com.sun.org.apache.xpath.internal.objects.XString
 *   @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public static XObject eval(
        Node contextNode, String str, PrefixResolver prefixResolver)
          throws TransformerException
{

  // Since we don't have a XML Parser involved here, install some default support
  // for things like namespaces, etc.
  // (Changed from: XPathContext xpathSupport = new XPathContext();
  //    because XPathContext is weak in a number of areas... perhaps
  //    XPathContext should be done away with.)
  // Create the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // Execute the XPath, and have it return the result
  XPathContext xpathSupport = new XPathContext();
  int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

  return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
 
Example 28
/**
 * Execute the expression.  Meant for reuse by other FilterExpr iterators
 * that are not derived from this object.
 */
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt,
                                                                                              PrefixResolver prefixResolver,
                                                                                              boolean isTopLevel,
                                                                                              int stackFrame,
                                                                                              Expression expr )
  throws com.sun.org.apache.xml.internal.utils.WrappedRuntimeException
{
  PrefixResolver savedResolver = xctxt.getNamespaceContext();
  XNodeSet result = null;

  try
  {
    xctxt.pushCurrentNode(context);
    xctxt.setNamespaceContext(prefixResolver);

    // The setRoot operation can take place with a reset operation,
    // and so we may not be in the context of LocPathIterator#nextNode,
    // so we have to set up the variable context, execute the expression,
    // and then restore the variable context.

    if (isTopLevel)
    {
      // System.out.println("calling m_expr.execute(getXPathContext())");
      VariableStack vars = xctxt.getVarStack();

      // These three statements need to be combined into one operation.
      int savedStart = vars.getStackFrame();
      vars.setStackFrame(stackFrame);

      result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);
      result.setShouldCacheNodes(true);

      // These two statements need to be combined into one operation.
      vars.setStackFrame(savedStart);
    }
    else
        result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);

  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix...
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(se);
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.setNamespaceContext(savedResolver);
  }
  return result;
}
 
Example 29
Source Project: jdk8u60   Source File: PredicatedNodeTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 30
/**
 * Execute the expression.  Meant for reuse by other FilterExpr iterators
 * that are not derived from this object.
 */
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt,
                                                                                              PrefixResolver prefixResolver,
                                                                                              boolean isTopLevel,
                                                                                              int stackFrame,
                                                                                              Expression expr )
  throws com.sun.org.apache.xml.internal.utils.WrappedRuntimeException
{
  PrefixResolver savedResolver = xctxt.getNamespaceContext();
  XNodeSet result = null;

  try
  {
    xctxt.pushCurrentNode(context);
    xctxt.setNamespaceContext(prefixResolver);

    // The setRoot operation can take place with a reset operation,
    // and so we may not be in the context of LocPathIterator#nextNode,
    // so we have to set up the variable context, execute the expression,
    // and then restore the variable context.

    if (isTopLevel)
    {
      // System.out.println("calling m_expr.execute(getXPathContext())");
      VariableStack vars = xctxt.getVarStack();

      // These three statements need to be combined into one operation.
      int savedStart = vars.getStackFrame();
      vars.setStackFrame(stackFrame);

      result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);
      result.setShouldCacheNodes(true);

      // These two statements need to be combined into one operation.
      vars.setStackFrame(savedStart);
    }
    else
        result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);

  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix...
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(se);
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.setNamespaceContext(savedResolver);
  }
  return result;
}