Search in sources :

Example 91 with XObject

use of org.apache.xpath.objects.XObject in project robovm by robovm.

the class UnionChildIterator method acceptNode.

/**
   * 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 = getXPathContext();
    try {
        xctxt.pushCurrentNode(n);
        for (int i = 0; i < m_nodeTests.length; i++) {
            PredicatedNodeTest pnt = m_nodeTests[i];
            XObject score = pnt.execute(xctxt, n);
            if (score != NodeTest.SCORE_NONE) {
                // Note that we are assuming there are no positional predicates!
                if (pnt.getPredicateCount() > 0) {
                    if (pnt.executePredicates(n, xctxt))
                        return DTMIterator.FILTER_ACCEPT;
                } else
                    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;
}
Also used : XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject)

Example 92 with XObject

use of org.apache.xpath.objects.XObject in project robovm by robovm.

the class StepPattern method executePredicates.

/**
   * Execute the predicates on this step to determine if the current node 
   * should be filtered or accepted.
   *
   * @param xctxt The XPath runtime context.
   * @param dtm The DTM of the current node.
   * @param currentNode The current node context.
   *
   * @return true if the node should be accepted, false otherwise.
   *
   * @throws javax.xml.transform.TransformerException
   */
protected final boolean executePredicates(XPathContext xctxt, DTM dtm, int currentNode) throws javax.xml.transform.TransformerException {
    boolean result = true;
    boolean positionAlreadySeen = false;
    int n = getPredicateCount();
    try {
        xctxt.pushSubContextList(this);
        for (int i = 0; i < n; i++) {
            xctxt.pushPredicatePos(i);
            try {
                XObject pred = m_predicates[i].execute(xctxt);
                try {
                    if (XObject.CLASS_NUMBER == pred.getType()) {
                        int pos = (int) pred.num();
                        if (positionAlreadySeen) {
                            result = (pos == 1);
                            break;
                        } else {
                            positionAlreadySeen = true;
                            if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos)) {
                                result = false;
                                break;
                            }
                        }
                    } else if (!pred.boolWithSideEffects()) {
                        result = false;
                        break;
                    }
                } finally {
                    pred.detach();
                }
            } finally {
                xctxt.popPredicatePos();
            }
        }
    } finally {
        xctxt.popSubContextList();
    }
    return result;
}
Also used : XObject(org.apache.xpath.objects.XObject)

Example 93 with XObject

use of org.apache.xpath.objects.XObject in project robovm by robovm.

the class StepPattern method execute.

/**
   * Execute an expression in the XPath runtime context, and return the
   * result of the expression.
   *
   *
   * @param xctxt The XPath runtime context.
   * @param currentNode The currentNode.
   * @param dtm The DTM of the current node.
   * @param expType The expanded type ID of the current node.
   *
   * @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 XObject execute(XPathContext xctxt, int currentNode, DTM dtm, int expType) throws javax.xml.transform.TransformerException {
    if (m_whatToShow == NodeTest.SHOW_BYFUNCTION) {
        if (null != m_relativePathPattern) {
            return m_relativePathPattern.execute(xctxt);
        } else
            return NodeTest.SCORE_NONE;
    }
    XObject score;
    score = super.execute(xctxt, currentNode, dtm, expType);
    if (score == NodeTest.SCORE_NONE)
        return NodeTest.SCORE_NONE;
    if (getPredicateCount() != 0) {
        if (!executePredicates(xctxt, dtm, currentNode))
            return NodeTest.SCORE_NONE;
    }
    if (null != m_relativePathPattern)
        return m_relativePathPattern.executeRelativePathPattern(xctxt, dtm, currentNode);
    return score;
}
Also used : XObject(org.apache.xpath.objects.XObject)

Example 94 with XObject

use of org.apache.xpath.objects.XObject in project robovm by robovm.

the class FuncQname 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 = 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;
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 95 with XObject

use of org.apache.xpath.objects.XObject in project robovm by robovm.

the class FuncRound 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 {
    final XObject obj = m_arg0.execute(xctxt);
    final double val = obj.num();
    if (val >= -0.5 && val < 0)
        return new XNumber(-0.0);
    if (val == 0.0)
        return new XNumber(val);
    return new XNumber(java.lang.Math.floor(val + 0.5));
}
Also used : XNumber(org.apache.xpath.objects.XNumber) XObject(org.apache.xpath.objects.XObject)

Aggregations

XObject (org.apache.xpath.objects.XObject)102 TransformerException (javax.xml.transform.TransformerException)24 DTM (org.apache.xml.dtm.DTM)24 XPathContext (org.apache.xpath.XPathContext)24 XNodeSet (org.apache.xpath.objects.XNodeSet)14 DTMIterator (org.apache.xml.dtm.DTMIterator)12 VariableStack (org.apache.xpath.VariableStack)10 Vector (java.util.Vector)8 QName (org.apache.xml.utils.QName)8 Expression (org.apache.xpath.Expression)8 Node (org.w3c.dom.Node)7 DTMAxisTraverser (org.apache.xml.dtm.DTMAxisTraverser)6 XMLString (org.apache.xml.utils.XMLString)6 org.apache.xpath (org.apache.xpath)6 XString (org.apache.xpath.objects.XString)6 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4 QName (javax.xml.namespace.QName)4 XPathFunction (javax.xml.xpath.XPathFunction)4 XPathFunctionException (javax.xml.xpath.XPathFunctionException)4