Java Code Examples for com.sun.org.apache.xml.internal.dtm.DTMIterator

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTMIterator. 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
Source Project: JDKSourceCode1.8   Source File: UnionPathIterator.java    License: MIT License 6 votes vote down vote up
/**
 * Add an iterator to the union list.
 *
 * @param expr non-null reference to a location path iterator.
 */
public void addIterator(DTMIterator expr)
{

  // Increase array size by only 1 at a time.  Fix this
  // if it looks to be a problem.
  if (null == m_iterators)
  {
    m_iterators = new DTMIterator[1];
    m_iterators[0] = expr;
  }
  else
  {
    DTMIterator[] exprs = m_iterators;
    int len = m_iterators.length;

    m_iterators = new DTMIterator[len + 1];

    System.arraycopy(exprs, 0, m_iterators, 0, len);

    m_iterators[len] = expr;
  }
  expr.nextNode();
  if(expr instanceof Expression)
      ((Expression)expr).exprSetParent(this);
}
 
Example 2
Source Project: hottub   Source File: UnionPathIterator.java    License: 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 3
Source Project: jdk1.8-source-analysis   Source File: Expression.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIterator(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    return execute(xctxt).iter();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example 4
Source Project: hottub   Source File: FuncLast.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt non-null reference to XPath runtime context.
 *
 * @return The number of nodes in the list.
 *
 * @throws javax.xml.transform.TransformerException
 */
public int getCountOfContextNodeList(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  // assert(null != m_contextNodeList, "m_contextNodeList must be non-null");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  // System.out.println("iter: "+iter);
  if (null != iter)
    return iter.getLastPos(xctxt);

  DTMIterator cnl = xctxt.getContextNodeList();
  int count;
  if(null != cnl)
  {
    count = cnl.getLength();
    // System.out.println("count: "+count);
  }
  else
    count = 0;
  return count;
}
 
Example 5
Source Project: Bytecoder   Source File: Expression.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIterator(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    return execute(xctxt).iter();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example 6
Source Project: JDKSourceCode1.8   Source File: FuncLast.java    License: MIT License 6 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt non-null reference to XPath runtime context.
 *
 * @return The number of nodes in the list.
 *
 * @throws javax.xml.transform.TransformerException
 */
public int getCountOfContextNodeList(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  // assert(null != m_contextNodeList, "m_contextNodeList must be non-null");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  // System.out.println("iter: "+iter);
  if (null != iter)
    return iter.getLastPos(xctxt);

  DTMIterator cnl = xctxt.getContextNodeList();
  int count;
  if(null != cnl)
  {
    count = cnl.getLength();
    // System.out.println("count: "+count);
  }
  else
    count = 0;
  return count;
}
 
Example 7
Source Project: openjdk-8-source   Source File: Expression.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example 8
Source Project: jdk1.8-source-analysis   Source File: UnionPathIterator.java    License: 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 9
Source Project: jdk1.8-source-analysis   Source File: UnionPathIterator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add an iterator to the union list.
 *
 * @param expr non-null reference to a location path iterator.
 */
public void addIterator(DTMIterator expr)
{

  // Increase array size by only 1 at a time.  Fix this
  // if it looks to be a problem.
  if (null == m_iterators)
  {
    m_iterators = new DTMIterator[1];
    m_iterators[0] = expr;
  }
  else
  {
    DTMIterator[] exprs = m_iterators;
    int len = m_iterators.length;

    m_iterators = new DTMIterator[len + 1];

    System.arraycopy(exprs, 0, m_iterators, 0, len);

    m_iterators[len] = expr;
  }
  expr.nextNode();
  if(expr instanceof Expression)
      ((Expression)expr).exprSetParent(this);
}
 
Example 10
Source Project: openjdk-jdk9   Source File: NodeSequence.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Note: Not a deep clone.
 * @see DTMIterator#cloneWithReset()
 */
public DTMIterator cloneWithReset() throws CloneNotSupportedException
{
      NodeSequence seq = (NodeSequence)super.clone();
  seq.m_next = 0;
  if (m_cache != null) {
      // In making this clone of an iterator we are making
      // another NodeSequence object it has a reference
      // to the same IteratorCache object as the original
      // so we need to remember that more than one
      // NodeSequence object shares the cache.
      m_cache.increaseUseCount();
  }

  return seq;
}
 
Example 11
/**
 * Add an iterator to the union list.
 *
 * @param expr non-null reference to a location path iterator.
 */
public void addIterator(DTMIterator expr)
{

  // Increase array size by only 1 at a time.  Fix this
  // if it looks to be a problem.
  if (null == m_iterators)
  {
    m_iterators = new DTMIterator[1];
    m_iterators[0] = expr;
  }
  else
  {
    DTMIterator[] exprs = m_iterators;
    int len = m_iterators.length;

    m_iterators = new DTMIterator[len + 1];

    System.arraycopy(exprs, 0, m_iterators, 0, len);

    m_iterators[len] = expr;
  }
  expr.nextNode();
  if(expr instanceof Expression)
      ((Expression)expr).exprSetParent(this);
}
 
Example 12
Source Project: openjdk-8   Source File: UnionPathIterator.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add an iterator to the union list.
 *
 * @param expr non-null reference to a location path iterator.
 */
public void addIterator(DTMIterator expr)
{

  // Increase array size by only 1 at a time.  Fix this
  // if it looks to be a problem.
  if (null == m_iterators)
  {
    m_iterators = new DTMIterator[1];
    m_iterators[0] = expr;
  }
  else
  {
    DTMIterator[] exprs = m_iterators;
    int len = m_iterators.length;

    m_iterators = new DTMIterator[len + 1];

    System.arraycopy(exprs, 0, m_iterators, 0, len);

    m_iterators[len] = expr;
  }
  expr.nextNode();
  if(expr instanceof Expression)
      ((Expression)expr).exprSetParent(this);
}
 
Example 13
Source Project: openjdk-8-source   Source File: FuncSum.java    License: 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 14
Source Project: Bytecoder   Source File: ExsltCommon.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The exsl:object-type function returns a string giving the type of the object passed
 * as the argument. The possible object types are: 'string', 'number', 'boolean',
 * 'node-set', 'RTF', or 'external'.
 *
 * Most XSLT object types can be coerced to each other without error. However, there are
 * certain coercions that raise errors, most importantly treating anything other than a
 * node set as a node set. Authors of utilities such as named templates or user-defined
 * extension functions may wish to give some flexibility in the parameter and argument values
 * that are accepted by the utility; the exsl:object-type function enables them to do so.
 *
 * The Xalan extensions MethodResolver converts 'object-type' to 'objectType'.
 *
 * @param obj The object to be typed.
 * @return objectType 'string', 'number', 'boolean', 'node-set', 'RTF', or 'external'.
 *
 * @see <a href="http://www.exslt.org/">EXSLT</a>
 */
public static String objectType (Object obj)
{
  if (obj instanceof String)
    return "string";
  else if (obj instanceof Boolean)
    return "boolean";
  else if (obj instanceof Number)
    return "number";
  else if (obj instanceof DTMNodeIterator)
  {
    DTMIterator dtmI = ((DTMNodeIterator)obj).getDTMIterator();
    if (dtmI instanceof com.sun.org.apache.xpath.internal.axes.RTFIterator)
      return "RTF";
    else
      return "node-set";
  }
  else
    return "unknown";
}
 
Example 15
Source Project: openjdk-8-source   Source File: XNodeSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a XNodeSet object.
 *
 * @param val Value of the XNodeSet object
 */
public XNodeSet(DTMIterator val)
{
      super();
      if(val instanceof XNodeSet)
      {
          final XNodeSet nodeSet = (XNodeSet) val;
          setIter(nodeSet.m_iter);
          m_dtmMgr = nodeSet.m_dtmMgr;
          m_last = nodeSet.m_last;
          // First make sure the DTMIterator val has a cache,
          // so if it doesn't have one, make one.
          if(!nodeSet.hasCache())
              nodeSet.setShouldCacheNodes(true);

          // Get the cache from val and use it ourselves (we share it).
          setObject(nodeSet.getIteratorCache());
      }
      else
      setIter(val);
}
 
Example 16
Source Project: jdk8u60   Source File: XNodeSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a XNodeSet object.
 *
 * @param val Value of the XNodeSet object
 */
public XNodeSet(DTMIterator val)
{
      super();
      if(val instanceof XNodeSet)
      {
          final XNodeSet nodeSet = (XNodeSet) val;
          setIter(nodeSet.m_iter);
          m_dtmMgr = nodeSet.m_dtmMgr;
          m_last = nodeSet.m_last;
          // First make sure the DTMIterator val has a cache,
          // so if it doesn't have one, make one.
          if(!nodeSet.hasCache())
              nodeSet.setShouldCacheNodes(true);

          // Get the cache from val and use it ourselves (we share it).
          setObject(nodeSet.getIteratorCache());
      }
      else
      setIter(val);
}
 
Example 17
/**
 * Get the current context node list.
 * @return An iterator for the current context list, as
 * defined in XSLT.
 */
public final DTMIterator getContextNodes()
{

  try
  {
    DTMIterator cnl = getContextNodeList();

    if (null != cnl)
      return cnl.cloneWithReset();
    else
      return null;  // for now... this might ought to be an empty iterator.
  }
  catch (CloneNotSupportedException cnse)
  {
    return null;  // error reporting?
  }
}
 
Example 18
Source Project: hottub   Source File: Expression.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIterator(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    return execute(xctxt).iter();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example 19
/**
 *  Get a cloned Iterator that is reset to the beginning
 *  of the query.
 *
 *  @return A cloned NodeIterator set of the start of the query.
 *
 *  @throws CloneNotSupportedException
 */
public DTMIterator cloneWithReset() throws CloneNotSupportedException
{

  DescendantIterator clone = (DescendantIterator) super.cloneWithReset();
  clone.m_traverser = m_traverser;

  clone.resetProximityPositions();

  return clone;
}
 
Example 20
Source Project: openjdk-8   Source File: XNodeSet.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Cast result object to a nodelist.
 *
 * @return The nodeset as a nodelist
 */
public DTMIterator iter()
{
  try
  {
      if(hasCache())
              return cloneWithReset();
      else
              return this; // don't bother to clone... won't do any good!
  }
  catch (CloneNotSupportedException cnse)
  {
    throw new RuntimeException(cnse.getMessage());
  }
}
 
Example 21
Source Project: openjdk-8   Source File: NodeSetDTM.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a NodeSetDTM, and copy the members of the
 * given DTMIterator into it.
 *
 * @param ni Iterator which yields Nodes to be made members of the new set.
 */
public NodeSetDTM(DTMIterator ni)
{

  super();

  m_manager = ni.getDTMManager();
  m_root = ni.getRoot();
  addNodes(ni);
}
 
Example 22
Source Project: jdk8u60   Source File: XNodeSet.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Cast result object to a nodelist.
 *
 * @return The nodeset as a nodelist
 */
public DTMIterator iter()
{
  try
  {
      if(hasCache())
              return cloneWithReset();
      else
              return this; // don't bother to clone... won't do any good!
  }
  catch (CloneNotSupportedException cnse)
  {
    throw new RuntimeException(cnse.getMessage());
  }
}
 
Example 23
Source Project: jdk1.8-source-analysis   Source File: FunctionPattern.java    License: 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)
        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 24
/**
 *  Get a cloned Iterator that is reset to the beginning
 *  of the query.
 *
 *  @return A cloned NodeIterator set of the start of the query.
 *
 *  @throws CloneNotSupportedException
 */
public DTMIterator cloneWithReset() throws CloneNotSupportedException
{

  ChildTestIterator clone = (ChildTestIterator) super.cloneWithReset();
  clone.m_traverser = m_traverser;

  return clone;
}
 
Example 25
/**
 * 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 = (DTMIterator)m_clones.getInstance();

  int current = xctxt.getCurrentNode();

  iter.setRoot(current, xctxt);

  int next = iter.nextNode();
  // m_clones.freeInstance(iter);
  iter.detach();
  return next;
}
 
Example 26
Source Project: openjdk-jdk9   Source File: DTMNodeIterator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Public constructor: Wrap a DTMNodeIterator around an existing
 * and preconfigured DTMIterator
 * */
public DTMNodeIterator(DTMIterator dtmIterator)
  {
    try
    {
      dtm_iter=(DTMIterator)dtmIterator.clone();
    }
    catch(CloneNotSupportedException cnse)
    {
      throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
    }
  }
 
Example 27
Source Project: JDKSourceCode1.8   Source File: XPathContext.java    License: MIT License 5 votes vote down vote up
/**
 * Create a new <code>DTMIterator</code> that holds exactly one node.
 *
 * @param node The node handle that the DTMIterator will iterate to.
 *
 * @return The newly created <code>DTMIterator</code>.
 */
public DTMIterator createDTMIterator(int node)
{
  // DescendantIterator iter = new DescendantIterator();
  DTMIterator iter = new com.sun.org.apache.xpath.internal.axes.OneStepIteratorForward(Axis.SELF);
  iter.setRoot(node, this);
  return iter;
  // return m_dtmManager.createDTMIterator(node);
}
 
Example 28
Source Project: openjdk-8   Source File: FilterIterator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public int next() {
    int node;
    while ((node = _source.next()) != END) {
        if (_filter.acceptNode(node, DTMFilter.SHOW_ALL) == DTMIterator.FILTER_ACCEPT) {
            return returnNode(node);
        }
    }
    return END;
}
 
Example 29
Source Project: hottub   Source File: OneStepIterator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Get a cloned Iterator that is reset to the beginning
 *  of the query.
 *
 *  @return A cloned NodeIterator set of the start of the query.
 *
 *  @throws CloneNotSupportedException
 */
public DTMIterator cloneWithReset() throws CloneNotSupportedException
{

  OneStepIterator clone = (OneStepIterator) super.cloneWithReset();
  clone.m_iterator = m_iterator;

  return clone;
}
 
Example 30
/**
 * 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;
}