Java Code Examples for com.sun.org.apache.xml.internal.dtm.DTMIterator#nextNode()

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTMIterator#nextNode() . 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: FuncSum.java    From openjdk-8-source 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
{

  DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
  double sum = 0.0;
  int pos;

  while (DTM.NULL != (pos = nodes.nextNode()))
  {
    DTM dtm = nodes.getDTM(pos);
    XMLString s = dtm.getStringValue(pos);

    if (null != s)
      sum += s.toDouble();
  }
  nodes.detach();

  return new XNumber(sum);
}
 
Example 2
Source File: FuncSum.java    From openjdk-jdk9 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
{

  DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
  double sum = 0.0;
  int pos;

  while (DTM.NULL != (pos = nodes.nextNode()))
  {
    DTM dtm = nodes.getDTM(pos);
    XMLString s = dtm.getStringValue(pos);

    if (null != s)
      sum += s.toDouble();
  }
  nodes.detach();

  return new XNumber(sum);
}
 
Example 3
Source File: UnionPathIterator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize the context values for this expression
 * after it is cloned.
 *
 * @param context The XPath runtime context for this
 * transformation.
 */
public void setRoot(int context, Object environment)
{
  super.setRoot(context, environment);

  try
  {
    if (null != m_exprs)
    {
      int n = m_exprs.length;
      DTMIterator newIters[] = new DTMIterator[n];

      for (int i = 0; i < n; i++)
      {
        DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
        newIters[i] = iter;
        iter.nextNode();
      }
      m_iterators = newIters;
    }
  }
  catch(Exception e)
  {
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
  }
}
 
Example 4
Source File: UnionPathIterator.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the context values for this expression
 * after it is cloned.
 *
 * @param context The XPath runtime context for this
 * transformation.
 */
public void setRoot(int context, Object environment)
{
  super.setRoot(context, environment);

  try
  {
    if (null != m_exprs)
    {
      int n = m_exprs.length;
      DTMIterator newIters[] = new DTMIterator[n];

      for (int i = 0; i < n; i++)
      {
        DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
        newIters[i] = iter;
        iter.nextNode();
      }
      m_iterators = newIters;
    }
  }
  catch(Exception e)
  {
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
  }
}
 
Example 5
Source File: UnionPathIterator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize the context values for this expression
 * after it is cloned.
 *
 * @param context The XPath runtime context for this
 * transformation.
 */
public void setRoot(int context, Object environment)
{
  super.setRoot(context, environment);

  try
  {
    if (null != m_exprs)
    {
      int n = m_exprs.length;
      DTMIterator newIters[] = new DTMIterator[n];

      for (int i = 0; i < n; i++)
      {
        DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
        newIters[i] = iter;
        iter.nextNode();
      }
      m_iterators = newIters;
    }
  }
  catch(Exception e)
  {
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
  }
}
 
Example 6
Source File: FuncSum.java    From jdk1.8-source-analysis with Apache License 2.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
{

  DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
  double sum = 0.0;
  int pos;

  while (DTM.NULL != (pos = nodes.nextNode()))
  {
    DTM dtm = nodes.getDTM(pos);
    XMLString s = dtm.getStringValue(pos);

    if (null != s)
      sum += s.toDouble();
  }
  nodes.detach();

  return new XNumber(sum);
}
 
Example 7
Source File: UnionPathIterator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize the context values for this expression
 * after it is cloned.
 *
 * @param context The XPath runtime context for this
 * transformation.
 */
public void setRoot(int context, Object environment)
{
  super.setRoot(context, environment);

  try
  {
    if (null != m_exprs)
    {
      int n = m_exprs.length;
      DTMIterator newIters[] = new DTMIterator[n];

      for (int i = 0; i < n; i++)
      {
        DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
        newIters[i] = iter;
        iter.nextNode();
      }
      m_iterators = newIters;
    }
  }
  catch(Exception e)
  {
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
  }
}
 
Example 8
Source File: FunctionPattern.java    From hottub 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 9
Source File: NodeSetDTM.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator DTMIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSetDTM is not of
 * a mutable type.
 */
public void addNodesInDocOrder(DTMIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!");

  int node;

  while (DTM.NULL != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
Example 10
Source File: FunctionPattern.java    From openjdk-jdk9 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, int context,
                       DTM dtm, int expType)
        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();
  }

  return score;
}
 
Example 11
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,
                       DTM dtm, int expType)
        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();
  }

  return score;
}
 
Example 12
Source File: NodeSetDTM.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator DTMIterator which yields the nodes to be added.
 * @param support The XPath runtime context.
 * @throws RuntimeException thrown if this NodeSetDTM is not of
 * a mutable type.
 */
public void addNodesInDocOrder(DTMIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!");

  int node;

  while (DTM.NULL != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
Example 13
Source File: LocPathIterator.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return the first node out of the nodeset, if this expression is
 * a nodeset expression.  This is the default implementation for
 * nodesets.  Derived classes should try and override this and return a
 * value without having to do a clone operation.
 * @param xctxt The XPath runtime context.
 * @return the first node out of the nodeset, or DTM.NULL.
 */
public int asNode(XPathContext xctxt)
  throws javax.xml.transform.TransformerException
{
  DTMIterator iter = m_clones.getInstance();

  int current = xctxt.getCurrentNode();

  iter.setRoot(current, xctxt);

  int next = iter.nextNode();
  // m_clones.freeInstance(iter);
  iter.detach();
  return next;
}
 
Example 14
Source File: FunctionPattern.java    From Bytecoder with Apache License 2.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, int context,
                       DTM dtm, int expType)
        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();
  }

  return score;
}
 
Example 15
Source File: FuncPosition.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The current position of the itteration in the context node list,
 *         or -1 if there is no active context node list.
 */
public int getPositionInContextNodeList(XPathContext xctxt)
{

  // System.out.println("FuncPosition- entry");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  if (null != iter)
  {
    int prox = iter.getProximityPosition(xctxt);

    // System.out.println("FuncPosition- prox: "+prox);
    return prox;
  }

  DTMIterator cnl = xctxt.getContextNodeList();

  if (null != cnl)
  {
    int n = cnl.getCurrentNode();
    if(n == DTM.NULL)
    {
      if(cnl.getCurrentPos() == 0)
        return 0;

      // Then I think we're in a sort.  See sort21.xsl. So the iterator has
      // already been spent, and is not on the node we're processing.
      // It's highly possible that this is an issue for other context-list
      // functions.  Shouldn't be a problem for last(), and it shouldn't be
      // a problem for current().
      try
      {
        cnl = cnl.cloneWithReset();
      }
      catch(CloneNotSupportedException cnse)
      {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
      }
      int currentNode = xctxt.getContextNode();
      // System.out.println("currentNode: "+currentNode);
      while(DTM.NULL != (n = cnl.nextNode()))
      {
        if(n == currentNode)
          break;
      }
    }
    // System.out.println("n: "+n);
    // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
    return cnl.getCurrentPos();
  }

  // System.out.println("FuncPosition - out of guesses: -1");
  return -1;
}
 
Example 16
Source File: FuncPosition.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The current position of the itteration in the context node list,
 *         or -1 if there is no active context node list.
 */
public int getPositionInContextNodeList(XPathContext xctxt)
{

  // System.out.println("FuncPosition- entry");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  if (null != iter)
  {
    int prox = iter.getProximityPosition(xctxt);

    // System.out.println("FuncPosition- prox: "+prox);
    return prox;
  }

  DTMIterator cnl = xctxt.getContextNodeList();

  if (null != cnl)
  {
    int n = cnl.getCurrentNode();
    if(n == DTM.NULL)
    {
      if(cnl.getCurrentPos() == 0)
        return 0;

      // Then I think we're in a sort.  See sort21.xsl. So the iterator has
      // already been spent, and is not on the node we're processing.
      // It's highly possible that this is an issue for other context-list
      // functions.  Shouldn't be a problem for last(), and it shouldn't be
      // a problem for current().
      try
      {
        cnl = cnl.cloneWithReset();
      }
      catch(CloneNotSupportedException cnse)
      {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
      }
      int currentNode = xctxt.getContextNode();
      // System.out.println("currentNode: "+currentNode);
      while(DTM.NULL != (n = cnl.nextNode()))
      {
        if(n == currentNode)
          break;
      }
    }
    // System.out.println("n: "+n);
    // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
    return cnl.getCurrentPos();
  }

  // System.out.println("FuncPosition - out of guesses: -1");
  return -1;
}
 
Example 17
Source File: FuncPosition.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The current position of the itteration in the context node list,
 *         or -1 if there is no active context node list.
 */
public int getPositionInContextNodeList(XPathContext xctxt)
{

  // System.out.println("FuncPosition- entry");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  if (null != iter)
  {
    int prox = iter.getProximityPosition(xctxt);

    // System.out.println("FuncPosition- prox: "+prox);
    return prox;
  }

  DTMIterator cnl = xctxt.getContextNodeList();

  if (null != cnl)
  {
    int n = cnl.getCurrentNode();
    if(n == DTM.NULL)
    {
      if(cnl.getCurrentPos() == 0)
        return 0;

      // Then I think we're in a sort.  See sort21.xsl. So the iterator has
      // already been spent, and is not on the node we're processing.
      // It's highly possible that this is an issue for other context-list
      // functions.  Shouldn't be a problem for last(), and it shouldn't be
      // a problem for current().
      try
      {
        cnl = cnl.cloneWithReset();
      }
      catch(CloneNotSupportedException cnse)
      {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
      }
      int currentNode = xctxt.getContextNode();
      // System.out.println("currentNode: "+currentNode);
      while(DTM.NULL != (n = cnl.nextNode()))
      {
        if(n == currentNode)
          break;
      }
    }
    // System.out.println("n: "+n);
    // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
    return cnl.getCurrentPos();
  }

  // System.out.println("FuncPosition - out of guesses: -1");
  return -1;
}
 
Example 18
Source File: FuncPosition.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The current position of the itteration in the context node list,
 *         or -1 if there is no active context node list.
 */
public int getPositionInContextNodeList(XPathContext xctxt)
{

  // System.out.println("FuncPosition- entry");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  if (null != iter)
  {
    int prox = iter.getProximityPosition(xctxt);

    // System.out.println("FuncPosition- prox: "+prox);
    return prox;
  }

  DTMIterator cnl = xctxt.getContextNodeList();

  if (null != cnl)
  {
    int n = cnl.getCurrentNode();
    if(n == DTM.NULL)
    {
      if(cnl.getCurrentPos() == 0)
        return 0;

      // Then I think we're in a sort.  See sort21.xsl. So the iterator has
      // already been spent, and is not on the node we're processing.
      // It's highly possible that this is an issue for other context-list
      // functions.  Shouldn't be a problem for last(), and it shouldn't be
      // a problem for current().
      try
      {
        cnl = cnl.cloneWithReset();
      }
      catch(CloneNotSupportedException cnse)
      {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
      }
      int currentNode = xctxt.getContextNode();
      // System.out.println("currentNode: "+currentNode);
      while(DTM.NULL != (n = cnl.nextNode()))
      {
        if(n == currentNode)
          break;
      }
    }
    // System.out.println("n: "+n);
    // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
    return cnl.getCurrentPos();
  }

  // System.out.println("FuncPosition - out of guesses: -1");
  return -1;
}
 
Example 19
Source File: Expression.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Return the first node out of the nodeset, if this expression is
 * a nodeset expression.
 * @param xctxt The XPath runtime context.
 * @return the first node out of the nodeset, or DTM.NULL.
 *
 * @throws javax.xml.transform.TransformerException
 */
public int asNode(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
      DTMIterator iter = execute(xctxt).iter();
  return iter.nextNode();
}
 
Example 20
Source File: Expression.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return the first node out of the nodeset, if this expression is
 * a nodeset expression.
 * @param xctxt The XPath runtime context.
 * @return the first node out of the nodeset, or DTM.NULL.
 *
 * @throws javax.xml.transform.TransformerException
 */
public int asNode(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
      DTMIterator iter = execute(xctxt).iter();
  return iter.nextNode();
}