Search in sources :

Example 11 with XNumber

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

the class XPathParser method Number.

/**
   *
   * Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
   *
   *
   * @throws javax.xml.transform.TransformerException
   */
protected void Number() throws javax.xml.transform.TransformerException {
    if (null != m_token) {
        // Mutate the token to remove the quotes and have the XNumber object
        // already made.
        double num;
        try {
            // XPath 1.0 does not support number in exp notation
            if ((m_token.indexOf('e') > -1) || (m_token.indexOf('E') > -1))
                throw new NumberFormatException();
            num = Double.valueOf(m_token).doubleValue();
        } catch (NumberFormatException nfe) {
            // to shut up compiler.
            num = 0.0;
            error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER, //m_token+" could not be formatted to a number!");
            new Object[] { m_token });
        }
        m_ops.m_tokenQueue.setElementAt(new XNumber(num), m_queueMark - 1);
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
        m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
        nextToken();
    }
}
Also used : XNumber(org.apache.xpath.objects.XNumber)

Example 12 with XNumber

use of org.apache.xpath.objects.XNumber 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)

Example 13 with XNumber

use of org.apache.xpath.objects.XNumber in project j2objc by google.

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 14 with XNumber

use of org.apache.xpath.objects.XNumber in project j2objc by google.

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

Example 15 with XNumber

use of org.apache.xpath.objects.XNumber in project j2objc by google.

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

XNumber (org.apache.xpath.objects.XNumber)17 DTMIterator (org.apache.xml.dtm.DTMIterator)10 XObject (org.apache.xpath.objects.XObject)3 DTM (org.apache.xml.dtm.DTM)2 XMLString (org.apache.xml.utils.XMLString)2 ContextMatchStepPattern (org.apache.xpath.patterns.ContextMatchStepPattern)2 StepPattern (org.apache.xpath.patterns.StepPattern)2 SimpleNumber (freemarker.template.SimpleNumber)1 SimpleScalar (freemarker.template.SimpleScalar)1 TemplateModelException (freemarker.template.TemplateModelException)1 List (java.util.List)1 TransformerException (javax.xml.transform.TransformerException)1 XPath (org.apache.xpath.XPath)1 XBoolean (org.apache.xpath.objects.XBoolean)1 XNodeSet (org.apache.xpath.objects.XNodeSet)1 XNull (org.apache.xpath.objects.XNull)1 XString (org.apache.xpath.objects.XString)1 Node (org.w3c.dom.Node)1 NodeIterator (org.w3c.dom.traversal.NodeIterator)1