Search in sources :

Example 16 with XNumber

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

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

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

the class FuncCount 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 nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
    // // We should probably make a function on the iterator for this,
    // // as a given implementation could optimize.
    // int i = 0;
    // 
    // while (DTM.NULL != nl.nextNode())
    // {
    // i++;
    // }
    // nl.detach();
    DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
    int i = nl.getLength();
    nl.detach();
    return new XNumber((double) i);
}
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