com.sun.org.apache.xpath.internal.XPathContext Java Examples

The following examples show how to use com.sun.org.apache.xpath.internal.XPathContext. 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
Source File: FuncQname.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);
  XObject val;

  if (DTM.NULL != context)
  {
    DTM dtm = xctxt.getDTM(context);
    String qname = dtm.getNodeNameX(context);
    val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
  }
  else
  {
    val = XString.EMPTYSTRING;
  }

  return val;
}
 
Example #2
Source File: StepPattern.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the match score of the given node.
 *
 * @param xctxt The XPath runtime context.
 * @param context The node to be tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public double getMatchScore(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  xctxt.pushCurrentNode(context);
  xctxt.pushCurrentExpressionNode(context);

  try
  {
    XObject score = execute(xctxt);

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
Example #3
Source File: FunctionDef1Arg.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the first argument expression that is expected to return a
 * number.  If the argument is null, then get the number value from the
 * current context node.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The number value of the first argument, or the number value of the
 *         current context node if the first argument is null.
 *
 * @throws javax.xml.transform.TransformerException if an error occurs while
 *                                   executing the argument expression.
 */
protected double getArg0AsNumber(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  if(null == m_arg0)
  {
    int currentNode = xctxt.getCurrentNode();
    if(DTM.NULL == currentNode)
      return 0;
    else
    {
      DTM dtm = xctxt.getDTM(currentNode);
      XMLString str = dtm.getStringValue(currentNode);
      return str.toDouble();
    }

  }
  else
    return m_arg0.execute(xctxt).num();
}
 
Example #4
Source File: ExsltDynamic.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #5
Source File: FuncGenerateId.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int which = getArg0AsNode(xctxt);

  if (DTM.NULL != which)
  {
    // Note that this is a different value than in previous releases
    // of Xalan. It's sensitive to the exact encoding of the node
    // handle anyway, so fighting to maintain backward compatability
    // really didn't make sense; it may change again as we continue
    // to experiment with balancing document and node numbers within
    // that value.
    return new XString("N" + Integer.toHexString(which).toUpperCase());
  }
  else
    return XString.EMPTYSTRING;
}
 
Example #6
Source File: LocPathIterator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute an expression in the XPath runtime context, and return the
 * result of the expression.
 *
 *
 * @param xctxt The XPath runtime context.
 * @param handler The target content handler.
 *
 * @return The result of the expression in the form of a <code>XObject</code>.
 *
 * @throws javax.xml.transform.TransformerException if a runtime exception
 *         occurs.
 * @throws org.xml.sax.SAXException
 */
public void executeCharsToContentHandler(
        XPathContext xctxt, org.xml.sax.ContentHandler handler)
          throws javax.xml.transform.TransformerException,
                 org.xml.sax.SAXException
{
  LocPathIterator clone = (LocPathIterator)m_clones.getInstance();

  int current = xctxt.getCurrentNode();
  clone.setRoot(current, xctxt);

  int node = clone.nextNode();
  DTM dtm = clone.getDTM(node);
  clone.detach();

  if(node != DTM.NULL)
  {
    dtm.dispatchCharactersEvents(node, handler, false);
  }
}
 
Example #7
Source File: StepPattern.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the match score of the given node.
 *
 * @param xctxt The XPath runtime context.
 * @param context The node to be tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public double getMatchScore(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  xctxt.pushCurrentNode(context);
  xctxt.pushCurrentExpressionNode(context);

  try
  {
    XObject score = execute(xctxt);

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
Example #8
Source File: FuncNormalizeSpace.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute an expression in the XPath runtime context, and return the
 * result of the expression.
 *
 *
 * @param xctxt The XPath runtime context.
 *
 * @return The result of the expression in the form of a <code>XObject</code>.
 *
 * @throws javax.xml.transform.TransformerException if a runtime exception
 *         occurs.
 */
public void executeCharsToContentHandler(XPathContext xctxt,
                                            ContentHandler handler)
  throws javax.xml.transform.TransformerException,
         org.xml.sax.SAXException
{
  if(Arg0IsNodesetExpr())
  {
    int node = getArg0AsNode(xctxt);
    if(DTM.NULL != node)
    {
      DTM dtm = xctxt.getDTM(node);
      dtm.dispatchCharactersEvents(node, handler, true);
    }
  }
  else
  {
    XObject obj = execute(xctxt);
    obj.dispatchCharactersEvents(handler);
  }
}
 
Example #9
Source File: FunctionDef1Arg.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the first argument expression that is expected to return a
 * number.  If the argument is null, then get the number value from the
 * current context node.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The number value of the first argument, or the number value of the
 *         current context node if the first argument is null.
 *
 * @throws javax.xml.transform.TransformerException if an error occurs while
 *                                   executing the argument expression.
 */
protected double getArg0AsNumber(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  if(null == m_arg0)
  {
    int currentNode = xctxt.getCurrentNode();
    if(DTM.NULL == currentNode)
      return 0;
    else
    {
      DTM dtm = xctxt.getDTM(currentNode);
      XMLString str = dtm.getStringValue(currentNode);
      return str.toDouble();
    }

  }
  else
    return m_arg0.execute(xctxt).num();
}
 
Example #10
Source File: AxesWalker.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the root node of the TreeWalker.
 * (Not part of the DOM2 TreeWalker interface).
 *
 * @param root The context node of this step.
 */
public void setRoot(int root)
{
  // %OPT% Get this directly from the lpi.
  XPathContext xctxt = wi().getXPathContext();
  m_dtm = xctxt.getDTM(root);
  m_traverser = m_dtm.getAxisTraverser(m_axis);
  m_isFresh = true;
  m_foundLast = false;
  m_root = root;
  m_currentNode = root;

  if (DTM.NULL == root)
  {
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); //"\n !!!! Error! Setting the root of a walker to null!!!");
  }

  resetProximityPositions();
}
 
Example #11
Source File: FuncNormalizeSpace.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute an expression in the XPath runtime context, and return the
 * result of the expression.
 *
 *
 * @param xctxt The XPath runtime context.
 *
 * @return The result of the expression in the form of a <code>XObject</code>.
 *
 * @throws javax.xml.transform.TransformerException if a runtime exception
 *         occurs.
 */
public void executeCharsToContentHandler(XPathContext xctxt,
                                            ContentHandler handler)
  throws javax.xml.transform.TransformerException,
         org.xml.sax.SAXException
{
  if(Arg0IsNodesetExpr())
  {
    int node = getArg0AsNode(xctxt);
    if(DTM.NULL != node)
    {
      DTM dtm = xctxt.getDTM(node);
      dtm.dispatchCharactersEvents(node, handler, true);
    }
  }
  else
  {
    XObject obj = execute(xctxt);
    obj.dispatchCharactersEvents(handler);
  }
}
 
Example #12
Source File: FuncGenerateId.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int which = getArg0AsNode(xctxt);

  if (DTM.NULL != which)
  {
    // Note that this is a different value than in previous releases
    // of Xalan. It's sensitive to the exact encoding of the node
    // handle anyway, so fighting to maintain backward compatability
    // really didn't make sense; it may change again as we continue
    // to experiment with balancing document and node numbers within
    // that value.
    return new XString("N" + Integer.toHexString(which).toUpperCase());
  }
  else
    return XString.EMPTYSTRING;
}
 
Example #13
Source File: FuncLang.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #14
Source File: FunctionPattern.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int context = xctxt.getCurrentNode();
  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #15
Source File: FunctionPattern.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    // nl.detach();
  }
  nl.detach();

  return score;
}
 
Example #16
Source File: XObject.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Cast object to type t.
 *
 * @param t Type of object to cast this to
 * @param support XPath context to use for the conversion
 *
 * @return This object as the given type t
 *
 * @throws javax.xml.transform.TransformerException
 */
public Object castToType(int t, XPathContext support)
        throws javax.xml.transform.TransformerException
{

  Object result;

  switch (t)
  {
  case CLASS_STRING :
    result = str();
    break;
  case CLASS_NUMBER :
    result = new Double(num());
    break;
  case CLASS_NODESET :
    result = iter();
    break;
  case CLASS_BOOLEAN :
    result = new Boolean(bool());
    break;
  case CLASS_UNKNOWN :
    result = m_obj;
    break;

  // %TBD%  What to do here?
  //    case CLASS_RTREEFRAG :
  //      result = rtree(support);
  //      break;
  default :
    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
          new Object[]{ getTypeString(),
                        Integer.toString(t) });  //"Can not convert "+getTypeString()+" to a type#"+t);

    result = null;
  }

  return result;
}
 
Example #17
Source File: ReverseAxesWalker.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Get the number of nodes in this node list.  The function is probably ill
 * named?
 *
 *
 * @param xctxt The XPath runtime context.
 *
 * @return the number of nodes in this node list.
 */
public int getLastPos(XPathContext xctxt)
{

  int count = 0;
  AxesWalker savedWalker = wi().getLastUsedWalker();

  try
  {
    ReverseAxesWalker clone = (ReverseAxesWalker) this.clone();

    clone.setRoot(this.getRoot());

    clone.setPredicateCount(this.getPredicateCount() - 1);

    clone.setPrevWalker(null);
    clone.setNextWalker(null);
    wi().setLastUsedWalker(clone);

    // Count 'em all
    // count = 1;
    int next;

    while (DTM.NULL != (next = clone.nextNode()))
    {
      count++;
    }
  }
  catch (CloneNotSupportedException cnse)
  {

    // can't happen
  }
  finally
  {
    wi().setLastUsedWalker(savedWalker);
  }

  return count;
}
 
Example #18
Source File: FuncLang.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #19
Source File: FuncSubstringAfter.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XMLString s1 = m_arg0.execute(xctxt).xstr();
  XMLString s2 = m_arg1.execute(xctxt).xstr();
  int index = s1.indexOf(s2);

  return (-1 == index)
         ? XString.EMPTYSTRING
         : (XString)s1.substring(index + s2.length());
}
 
Example #20
Source File: Equals.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a binary operation by calling execute on each of the operands,
 * and then calling the operate method on the derived class.
 *
 *
 * @param xctxt The runtime execution context.
 *
 * @return The XObject result of the operation.
 *
 * @throws javax.xml.transform.TransformerException
 */
public boolean bool(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
  XObject left = m_left.execute(xctxt, true);
  XObject right = m_right.execute(xctxt, true);

  boolean result = left.equals(right) ? true : false;
      left.detach();
      right.detach();
  return result;
}
 
Example #21
Source File: FuncUnparsedEntityURI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String name = m_arg0.execute(xctxt).str();
  int context = xctxt.getCurrentNode();
  DTM dtm = xctxt.getDTM(context);
  int doc = dtm.getDocument();

  String uri = dtm.getUnparsedEntityURI(name);

  return new XString(uri);
}
 
Example #22
Source File: Function.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute an XPath function object.  The function must return
 * a valid object.
 * @param xctxt The execution current context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  // Programmer's assert.  (And, no, I don't want the method to be abstract).
  System.out.println("Error! Function.execute should not be called!");

  return null;
}
 
Example #23
Source File: FuncUnparsedEntityURI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String name = m_arg0.execute(xctxt).str();
  int context = xctxt.getCurrentNode();
  DTM dtm = xctxt.getDTM(context);
  int doc = dtm.getDocument();

  String uri = dtm.getUnparsedEntityURI(name);

  return new XString(uri);
}
 
Example #24
Source File: ReverseAxesWalker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the number of nodes in this node list.  The function is probably ill
 * named?
 *
 *
 * @param xctxt The XPath runtime context.
 *
 * @return the number of nodes in this node list.
 */
public int getLastPos(XPathContext xctxt)
{

  int count = 0;
  AxesWalker savedWalker = wi().getLastUsedWalker();

  try
  {
    ReverseAxesWalker clone = (ReverseAxesWalker) this.clone();

    clone.setRoot(this.getRoot());

    clone.setPredicateCount(this.getPredicateCount() - 1);

    clone.setPrevWalker(null);
    clone.setNextWalker(null);
    wi().setLastUsedWalker(clone);

    // Count 'em all
    // count = 1;
    int next;

    while (DTM.NULL != (next = clone.nextNode()))
    {
      count++;
    }
  }
  catch (CloneNotSupportedException cnse)
  {

    // can't happen
  }
  finally
  {
    wi().setLastUsedWalker(savedWalker);
  }

  return count;
}
 
Example #25
Source File: PredicatedNodeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Test whether a specified node is visible in the logical view of a
 * TreeWalker or NodeIterator. This function will be called by the
 * implementation of TreeWalker and NodeIterator; it is not intended to
 * be called directly from user code.
 * @param n  The node to check to see if it passes the filter or not.
 * @return  a constant to determine whether the node is accepted,
 *   rejected, or skipped, as defined  above .
 */
public short acceptNode(int n)
{

  XPathContext xctxt = m_lpi.getXPathContext();

  try
  {
    xctxt.pushCurrentNode(n);

    XObject score = execute(xctxt, n);

    // System.out.println("\n::acceptNode - score: "+score.num()+"::");
    if (score != NodeTest.SCORE_NONE)
    {
      if (getPredicateCount() > 0)
      {
        countProximityPosition(0);

        if (!executePredicates(n, xctxt))
          return DTMIterator.FILTER_SKIP;
      }

      return DTMIterator.FILTER_ACCEPT;
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix this.
    throw new RuntimeException(se.getMessage());
  }
  finally
  {
    xctxt.popCurrentNode();
  }

  return DTMIterator.FILTER_SKIP;
}
 
Example #26
Source File: Operation.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a binary operation by calling execute on each of the operands,
 * and then calling the operate method on the derived class.
 *
 *
 * @param xctxt The runtime execution context.
 *
 * @return The XObject result of the operation.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  XObject left = m_left.execute(xctxt, true);
  XObject right = m_right.execute(xctxt, true);

  XObject result = operate(left, right);
  left.detach();
  right.detach();
  return result;
}
 
Example #27
Source File: FunctionPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int context = xctxt.getCurrentNode();
  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #28
Source File: FuncSubstringBefore.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();
  int index = s1.indexOf(s2);

  return (-1 == index)
         ? XString.EMPTYSTRING : new XString(s1.substring(0, index));
}
 
Example #29
Source File: PredicatedNodeTest.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 *  Test whether a specified node is visible in the logical view of a
 * TreeWalker or NodeIterator. This function will be called by the
 * implementation of TreeWalker and NodeIterator; it is not intended to
 * be called directly from user code.
 * @param n  The node to check to see if it passes the filter or not.
 * @return  a constant to determine whether the node is accepted,
 *   rejected, or skipped, as defined  above .
 */
public short acceptNode(int n)
{

  XPathContext xctxt = m_lpi.getXPathContext();

  try
  {
    xctxt.pushCurrentNode(n);

    XObject score = execute(xctxt, n);

    // System.out.println("\n::acceptNode - score: "+score.num()+"::");
    if (score != NodeTest.SCORE_NONE)
    {
      if (getPredicateCount() > 0)
      {
        countProximityPosition(0);

        if (!executePredicates(n, xctxt))
          return DTMIterator.FILTER_SKIP;
      }

      return DTMIterator.FILTER_ACCEPT;
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix this.
    throw new RuntimeException(se.getMessage());
  }
  finally
  {
    xctxt.popCurrentNode();
  }

  return DTMIterator.FILTER_SKIP;
}
 
Example #30
Source File: And.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}