Search in sources :

Example 6 with DTMIterator

use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.

the class FuncId method execute.

/**
   * 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 = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int docContext = dtm.getDocument();
    if (DTM.NULL == docContext)
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    XObject arg = m_arg0.execute(xctxt);
    int argType = arg.getType();
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    if (XObject.CLASS_NODESET == argType) {
        DTMIterator ni = arg.iter();
        StringVector usedrefs = null;
        int pos = ni.nextNode();
        while (DTM.NULL != pos) {
            DTM ndtm = ni.getDTM(pos);
            String refval = ndtm.getStringValue(pos).toString();
            pos = ni.nextNode();
            usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
        }
    // ni.detach();
    } else if (XObject.CLASS_NULL == argType) {
        return nodes;
    } else {
        String refval = arg.str();
        getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
    }
    return nodes;
}
Also used : NodeSetDTM(org.apache.xpath.NodeSetDTM) StringVector(org.apache.xml.utils.StringVector) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject) XNodeSet(org.apache.xpath.objects.XNodeSet) DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 7 with DTMIterator

use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.

the class FuncPosition method getPositionInContextNodeList.

/**
   * 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;
            // a problem for current().
            try {
                cnl = cnl.cloneWithReset();
            } catch (CloneNotSupportedException cnse) {
                throw new org.apache.xml.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("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
        return cnl.getCurrentPos();
    }
    // System.out.println("FuncPosition - out of guesses: -1");
    return -1;
}
Also used : SubContextList(org.apache.xpath.axes.SubContextList) DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 8 with DTMIterator

use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.

the class FuncSum method execute.

/**
   * 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);
}
Also used : XNumber(org.apache.xpath.objects.XNumber) DTM(org.apache.xml.dtm.DTM) XMLString(org.apache.xml.utils.XMLString) DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 9 with DTMIterator

use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.

the class WalkerFactory method newDTMIterator.

/**
   * Create a new LocPathIterator iterator.  The exact type of iterator
   * returned is based on an analysis of the XPath operations.
   *
   * @param compiler non-null reference to compiler object that has processed
   *                 the XPath operations into an opcode map.
   * @param opPos The position of the operation code for this itterator.
   *
   * @return non-null reference to a LocPathIterator or derivative.
   *
   * @throws javax.xml.transform.TransformerException
   */
public static DTMIterator newDTMIterator(Compiler compiler, int opPos, boolean isTopLevel) throws javax.xml.transform.TransformerException {
    int firstStepPos = OpMap.getFirstChildPos(opPos);
    int analysis = analyze(compiler, firstStepPos, 0);
    boolean isOneStep = isOneStep(analysis);
    DTMIterator iter;
    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
    if (isOneStep && walksSelfOnly(analysis) && isWild(analysis) && !hasPredicate(analysis)) {
        if (DEBUG_ITERATOR_CREATION)
            diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler);
        // Then use a simple iteration of the attributes, with node test 
        // and predicate testing.
        iter = new SelfIteratorNoPredicate(compiler, opPos, analysis);
    } else // Is the iteration exactly one child step?
    if (walksChildrenOnly(analysis) && isOneStep) {
        // Does the pattern specify *any* child with no predicate? (i.e. select="child::node()".
        if (isWild(analysis) && !hasPredicate(analysis)) {
            if (DEBUG_ITERATOR_CREATION)
                diagnoseIterator("ChildIterator", analysis, compiler);
            // Use simple child iteration without any test.
            iter = new ChildIterator(compiler, opPos, analysis);
        } else {
            if (DEBUG_ITERATOR_CREATION)
                diagnoseIterator("ChildTestIterator", analysis, compiler);
            // Else use simple node test iteration with predicate test.
            iter = new ChildTestIterator(compiler, opPos, analysis);
        }
    } else // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
    if (isOneStep && walksAttributes(analysis)) {
        if (DEBUG_ITERATOR_CREATION)
            diagnoseIterator("AttributeIterator", analysis, compiler);
        // Then use a simple iteration of the attributes, with node test 
        // and predicate testing.
        iter = new AttributeIterator(compiler, opPos, analysis);
    } else if (isOneStep && !walksFilteredList(analysis)) {
        if (!walksNamespaces(analysis) && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT))) {
            if (false || DEBUG_ITERATOR_CREATION)
                diagnoseIterator("OneStepIteratorForward", analysis, compiler);
            // Then use a simple iteration of the attributes, with node test 
            // and predicate testing.
            iter = new OneStepIteratorForward(compiler, opPos, analysis);
        } else {
            if (false || DEBUG_ITERATOR_CREATION)
                diagnoseIterator("OneStepIterator", analysis, compiler);
            // Then use a simple iteration of the attributes, with node test 
            // and predicate testing.
            iter = new OneStepIterator(compiler, opPos, analysis);
        }
    } else // to work right.
    if (isOptimizableForDescendantIterator(compiler, firstStepPos, 0)) // && getStepCount(analysis) <= 3 
    // && walksDescendants(analysis) 
    // && walksSubtreeOnlyFromRootOrContext(analysis)
    {
        if (DEBUG_ITERATOR_CREATION)
            diagnoseIterator("DescendantIterator", analysis, compiler);
        iter = new DescendantIterator(compiler, opPos, analysis);
    } else {
        if (isNaturalDocOrder(compiler, firstStepPos, 0, analysis)) {
            if (false || DEBUG_ITERATOR_CREATION) {
                diagnoseIterator("WalkingIterator", analysis, compiler);
            }
            iter = new WalkingIterator(compiler, opPos, analysis, true);
        } else {
            //        return new MatchPatternIterator(compiler, opPos, analysis);
            if (DEBUG_ITERATOR_CREATION)
                diagnoseIterator("WalkingIteratorSorted", analysis, compiler);
            iter = new WalkingIteratorSorted(compiler, opPos, analysis, true);
        }
    }
    if (iter instanceof LocPathIterator)
        ((LocPathIterator) iter).setIsTopLevel(isTopLevel);
    return iter;
}
Also used : DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 10 with DTMIterator

use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.

the class FunctionPattern method execute.

/**
   * Test a node to see if it matches the given node test.
   *
   * @param xctxt XPath runtime context.
   *
   * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
   *         {@link org.apache.xpath.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;
}
Also used : XNumber(org.apache.xpath.objects.XNumber) DTMIterator(org.apache.xml.dtm.DTMIterator)

Aggregations

DTMIterator (org.apache.xml.dtm.DTMIterator)46 DTM (org.apache.xml.dtm.DTM)23 XPathContext (org.apache.xpath.XPathContext)12 XObject (org.apache.xpath.objects.XObject)12 TransformerException (javax.xml.transform.TransformerException)11 XMLString (org.apache.xml.utils.XMLString)10 XNumber (org.apache.xpath.objects.XNumber)10 XNodeSet (org.apache.xpath.objects.XNodeSet)8 Vector (java.util.Vector)6 QName (org.apache.xml.utils.QName)6 SAXException (org.xml.sax.SAXException)6 SerializationHandler (org.apache.xml.serializer.SerializationHandler)5 Hashtable (java.util.Hashtable)4 IntStack (org.apache.xml.utils.IntStack)4 NodeSetDTM (org.apache.xpath.NodeSetDTM)4 SubContextList (org.apache.xpath.axes.SubContextList)4 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)2 KeyDeclaration (org.apache.xalan.templates.KeyDeclaration)2