Search in sources :

Example 41 with XObject

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

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 42 with XObject

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

the class FuncExtFunction 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 {
    if (xctxt.isSecureProcessing())
        throw new javax.xml.transform.TransformerException(XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { toString() }));
    XObject result;
    Vector argVec = new Vector();
    int nArgs = m_argVec.size();
    for (int i = 0; i < nArgs; i++) {
        Expression arg = (Expression) m_argVec.elementAt(i);
        XObject xobj = arg.execute(xctxt);
        /*
       * Should cache the arguments for func:function
       */
        xobj.allowDetachToRelease(false);
        argVec.addElement(xobj);
    }
    // dml
    ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject();
    Object val = extProvider.extFunction(this, argVec);
    if (null != val) {
        result = XObject.create(val, xctxt);
    } else {
        result = new XNull();
    }
    return result;
}
Also used : ExtensionsProvider(org.apache.xpath.ExtensionsProvider) XNull(org.apache.xpath.objects.XNull) Expression(org.apache.xpath.Expression) XObject(org.apache.xpath.objects.XObject) Vector(java.util.Vector) XObject(org.apache.xpath.objects.XObject)

Example 43 with XObject

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

the class FuncNormalizeSpace method executeCharsToContentHandler.

/**
 * Execute an expression in the XPath runtime context, and return the
 * result of the expression.
 *
 * @param xctxt The XPath runtime context.
 *
 * @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 void executeCharsToContentHandler(XPathContext xctxt, ContentHandler handler) throws javax.xml.transform.TransformerException, org.xml.sax.SAXException {
    if (Arg0IsNodesetExpr()) {
        int node = getArg0AsNode(xctxt);
        if (DTM.NULL != node) {
            DTM dtm = xctxt.getDTM(node);
            dtm.dispatchCharactersEvents(node, handler, true);
        }
    } else {
        XObject obj = execute(xctxt);
        obj.dispatchCharactersEvents(handler);
    }
}
Also used : DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 44 with XObject

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

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 45 with XObject

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

the class PredicatedNodeTest method executePredicates.

/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException {
    int nPredicates = getPredicateCount();
    // System.out.println("nPredicates: "+nPredicates);
    if (nPredicates == 0)
        return true;
    PrefixResolver savedResolver = xctxt.getNamespaceContext();
    try {
        m_predicateIndex = 0;
        xctxt.pushSubContextList(this);
        xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
        xctxt.pushCurrentNode(context);
        for (int i = 0; i < nPredicates; i++) {
            // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
            XObject pred = m_predicates[i].execute(xctxt);
            // System.out.println("pred.getType(): "+pred.getType());
            if (XObject.CLASS_NUMBER == pred.getType()) {
                if (DEBUG_PREDICATECOUNTING) {
                    System.out.flush();
                    System.out.println("\n===== start predicate count ========");
                    System.out.println("m_predicateIndex: " + m_predicateIndex);
                    // System.out.println("getProximityPosition(m_predicateIndex): "
                    // + getProximityPosition(m_predicateIndex));
                    System.out.println("pred.num(): " + pred.num());
                }
                int proxPos = this.getProximityPosition(m_predicateIndex);
                int predIndex = (int) pred.num();
                if (proxPos != predIndex) {
                    if (DEBUG_PREDICATECOUNTING) {
                        System.out.println("\nnode context: " + nodeToString(context));
                        System.out.println("index predicate is false: " + proxPos);
                        System.out.println("\n===== end predicate count ========");
                    }
                    return false;
                } else if (DEBUG_PREDICATECOUNTING) {
                    System.out.println("\nnode context: " + nodeToString(context));
                    System.out.println("index predicate is true: " + proxPos);
                    System.out.println("\n===== end predicate count ========");
                }
                // only sets m_foundLast if on the last predicate
                if (m_predicates[i].isStableNumber() && i == nPredicates - 1) {
                    m_foundLast = true;
                }
            } else if (!pred.bool())
                return false;
            countProximityPosition(++m_predicateIndex);
        }
    } finally {
        xctxt.popCurrentNode();
        xctxt.popNamespaceContext();
        xctxt.popSubContextList();
        m_predicateIndex = -1;
    }
    return true;
}
Also used : PrefixResolver(org.apache.xml.utils.PrefixResolver) XObject(org.apache.xpath.objects.XObject)

Aggregations

XObject (org.apache.xpath.objects.XObject)107 TransformerException (javax.xml.transform.TransformerException)27 DTM (org.apache.xml.dtm.DTM)24 XPathContext (org.apache.xpath.XPathContext)24 XNodeSet (org.apache.xpath.objects.XNodeSet)15 DTMIterator (org.apache.xml.dtm.DTMIterator)12 VariableStack (org.apache.xpath.VariableStack)11 Vector (java.util.Vector)9 QName (org.apache.xml.utils.QName)9 Node (org.w3c.dom.Node)9 Expression (org.apache.xpath.Expression)8 XString (org.apache.xpath.objects.XString)7 DTMAxisTraverser (org.apache.xml.dtm.DTMAxisTraverser)6 XMLString (org.apache.xml.utils.XMLString)6 org.apache.xpath (org.apache.xpath)6 Document (org.w3c.dom.Document)6 ArrayList (java.util.ArrayList)5 NodeVector (org.apache.xml.utils.NodeVector)5 SAXException (org.xml.sax.SAXException)5 Hashtable (java.util.Hashtable)4