Search in sources :

Example 1 with DTMAxisTraverser

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

the class StepPattern method getProximityPosition.

/**
   * Get the proximity position index of the current node based on this
   * node test.
   *
   *
   * @param xctxt XPath runtime context.
   * @param predPos Which predicate we're evaluating of foo[1][2][3].
   * @param findLast If true, don't terminate when the context node is found.
   *
   * @return the proximity position index of the current node based on the
   *         node test.
   */
private final int getProximityPosition(XPathContext xctxt, int predPos, boolean findLast) {
    int pos = 0;
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int parent = dtm.getParent(context);
    try {
        DTMAxisTraverser traverser = dtm.getAxisTraverser(Axis.CHILD);
        for (int child = traverser.first(parent); DTM.NULL != child; child = traverser.next(parent, child)) {
            try {
                xctxt.pushCurrentNode(child);
                if (NodeTest.SCORE_NONE != super.execute(xctxt, child)) {
                    boolean pass = true;
                    try {
                        xctxt.pushSubContextList(this);
                        for (int i = 0; i < predPos; i++) {
                            xctxt.pushPredicatePos(i);
                            try {
                                XObject pred = m_predicates[i].execute(xctxt);
                                try {
                                    if (XObject.CLASS_NUMBER == pred.getType()) {
                                        if ((pos + 1) != (int) pred.numWithSideEffects()) {
                                            pass = false;
                                            break;
                                        }
                                    } else if (!pred.boolWithSideEffects()) {
                                        pass = false;
                                        break;
                                    }
                                } finally {
                                    pred.detach();
                                }
                            } finally {
                                xctxt.popPredicatePos();
                            }
                        }
                    } finally {
                        xctxt.popSubContextList();
                    }
                    if (pass)
                        pos++;
                    if (!findLast && child == context) {
                        return pos;
                    }
                }
            } finally {
                xctxt.popCurrentNode();
            }
        }
    } catch (javax.xml.transform.TransformerException se) {
        // TODO: should keep throw sax exception...
        throw new java.lang.RuntimeException(se.getMessage());
    }
    return pos;
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 2 with DTMAxisTraverser

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

the class StepPattern method executeRelativePathPattern.

/**
   * Execute the match pattern step relative to another step.
   *
   *
   * @param xctxt The XPath runtime context.
   * @param dtm The DTM of the current node.
   * @param currentNode The current node 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
   */
protected final XObject executeRelativePathPattern(XPathContext xctxt, DTM dtm, int currentNode) throws javax.xml.transform.TransformerException {
    XObject score = NodeTest.SCORE_NONE;
    int context = currentNode;
    DTMAxisTraverser traverser;
    traverser = dtm.getAxisTraverser(m_axis);
    for (int relative = traverser.first(context); DTM.NULL != relative; relative = traverser.next(context, relative)) {
        try {
            xctxt.pushCurrentNode(relative);
            score = execute(xctxt);
            if (score != NodeTest.SCORE_NONE)
                break;
        } finally {
            xctxt.popCurrentNode();
        }
    }
    return score;
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) XObject(org.apache.xpath.objects.XObject)

Example 3 with DTMAxisTraverser

use of org.apache.xml.dtm.DTMAxisTraverser in project j2objc by google.

the class ContextMatchStepPattern method executeRelativePathPattern.

/**
 * Execute the match pattern step relative to another step.
 *
 * @param xctxt The XPath runtime context.
 * NEEDSDOC @param prevStep
 *
 * @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 executeRelativePathPattern(XPathContext xctxt, StepPattern prevStep) throws javax.xml.transform.TransformerException {
    XObject score = NodeTest.SCORE_NONE;
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    if (null != dtm) {
        int predContext = xctxt.getCurrentNode();
        DTMAxisTraverser traverser;
        int axis = m_axis;
        boolean needToTraverseAttrs = WalkerFactory.isDownwardAxisOfMany(axis);
        boolean iterRootIsAttr = (dtm.getNodeType(xctxt.getIteratorRoot()) == DTM.ATTRIBUTE_NODE);
        if ((Axis.PRECEDING == axis) && iterRootIsAttr) {
            axis = Axis.PRECEDINGANDANCESTOR;
        }
        traverser = dtm.getAxisTraverser(axis);
        for (int relative = traverser.first(context); DTM.NULL != relative; relative = traverser.next(context, relative)) {
            try {
                xctxt.pushCurrentNode(relative);
                score = execute(xctxt);
                if (score != NodeTest.SCORE_NONE) {
                    // predContext, relative);
                    if (executePredicates(xctxt, dtm, context))
                        return score;
                    score = NodeTest.SCORE_NONE;
                }
                if (needToTraverseAttrs && iterRootIsAttr && (DTM.ELEMENT_NODE == dtm.getNodeType(relative))) {
                    int xaxis = Axis.ATTRIBUTE;
                    for (int i = 0; i < 2; i++) {
                        DTMAxisTraverser atraverser = dtm.getAxisTraverser(xaxis);
                        for (int arelative = atraverser.first(relative); DTM.NULL != arelative; arelative = atraverser.next(relative, arelative)) {
                            try {
                                xctxt.pushCurrentNode(arelative);
                                score = execute(xctxt);
                                if (score != NodeTest.SCORE_NONE) {
                                    if (score != NodeTest.SCORE_NONE)
                                        return score;
                                }
                            } finally {
                                xctxt.popCurrentNode();
                            }
                        }
                        xaxis = Axis.NAMESPACE;
                    }
                }
            } finally {
                xctxt.popCurrentNode();
            }
        }
    }
    return score;
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 4 with DTMAxisTraverser

use of org.apache.xml.dtm.DTMAxisTraverser in project j2objc by google.

the class DescendantIterator method asNode.

/**
 * Return the first node out of the nodeset, if this expression is
 * a nodeset expression.  This is the default implementation for
 * nodesets.
 * <p>WARNING: Do not mutate this class from this function!</p>
 * @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 {
    if (getPredicateCount() > 0)
        return super.asNode(xctxt);
    int current = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(current);
    DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
    String localName = getLocalName();
    String namespace = getNamespace();
    int what = m_whatToShow;
    // NodeTest.debugWhatToShow(what);
    if (DTMFilter.SHOW_ALL == what || localName == NodeTest.WILD || namespace == NodeTest.WILD) {
        return traverser.first(current);
    } else {
        int type = getNodeTypeTest(what);
        int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
        return traverser.first(current, extendedType);
    }
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) DTM(org.apache.xml.dtm.DTM)

Example 5 with DTMAxisTraverser

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

the class ContextMatchStepPattern method executeRelativePathPattern.

/**
   * Execute the match pattern step relative to another step.
   *
   *
   * @param xctxt The XPath runtime context.
   * NEEDSDOC @param prevStep
   *
   * @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 executeRelativePathPattern(XPathContext xctxt, StepPattern prevStep) throws javax.xml.transform.TransformerException {
    XObject score = NodeTest.SCORE_NONE;
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    if (null != dtm) {
        int predContext = xctxt.getCurrentNode();
        DTMAxisTraverser traverser;
        int axis = m_axis;
        boolean needToTraverseAttrs = WalkerFactory.isDownwardAxisOfMany(axis);
        boolean iterRootIsAttr = (dtm.getNodeType(xctxt.getIteratorRoot()) == DTM.ATTRIBUTE_NODE);
        if ((Axis.PRECEDING == axis) && iterRootIsAttr) {
            axis = Axis.PRECEDINGANDANCESTOR;
        }
        traverser = dtm.getAxisTraverser(axis);
        for (int relative = traverser.first(context); DTM.NULL != relative; relative = traverser.next(context, relative)) {
            try {
                xctxt.pushCurrentNode(relative);
                score = execute(xctxt);
                if (score != NodeTest.SCORE_NONE) {
                    //       predContext, relative);
                    if (executePredicates(xctxt, dtm, context))
                        return score;
                    score = NodeTest.SCORE_NONE;
                }
                if (needToTraverseAttrs && iterRootIsAttr && (DTM.ELEMENT_NODE == dtm.getNodeType(relative))) {
                    int xaxis = Axis.ATTRIBUTE;
                    for (int i = 0; i < 2; i++) {
                        DTMAxisTraverser atraverser = dtm.getAxisTraverser(xaxis);
                        for (int arelative = atraverser.first(relative); DTM.NULL != arelative; arelative = atraverser.next(relative, arelative)) {
                            try {
                                xctxt.pushCurrentNode(arelative);
                                score = execute(xctxt);
                                if (score != NodeTest.SCORE_NONE) {
                                    if (score != NodeTest.SCORE_NONE)
                                        return score;
                                }
                            } finally {
                                xctxt.popCurrentNode();
                            }
                        }
                        xaxis = Axis.NAMESPACE;
                    }
                }
            } finally {
                xctxt.popCurrentNode();
            }
        }
    }
    return score;
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Aggregations

DTMAxisTraverser (org.apache.xml.dtm.DTMAxisTraverser)8 DTM (org.apache.xml.dtm.DTM)6 XObject (org.apache.xpath.objects.XObject)6