Search in sources :

Example 1 with XPathFunctionException

use of javax.xml.xpath.XPathFunctionException in project robovm by robovm.

the class JAXPExtensionsProvider method extFunction.

/**
     * Execute the extension function.
     */
public Object extFunction(String ns, String funcName, Vector argVec, Object methodKey) throws javax.xml.transform.TransformerException {
    try {
        if (funcName == null) {
            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "Function Name" });
            throw new NullPointerException(fmsg);
        }
        //Find the XPathFunction corresponding to namespace and funcName
        javax.xml.namespace.QName myQName = new QName(ns, funcName);
        // throw XPathFunctionException
        if (extensionInvocationDisabled) {
            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { myQName.toString() });
            throw new XPathFunctionException(fmsg);
        }
        // Assuming user is passing all the needed parameters ( including
        // default values )
        int arity = argVec.size();
        javax.xml.xpath.XPathFunction xpathFunction = resolver.resolveFunction(myQName, arity);
        // not using methodKey
        ArrayList argList = new ArrayList(arity);
        for (int i = 0; i < arity; i++) {
            Object argument = argVec.elementAt(i);
            // Explicitly getting NodeList by using nodelist()
            if (argument instanceof XNodeSet) {
                argList.add(i, ((XNodeSet) argument).nodelist());
            } else if (argument instanceof XObject) {
                Object passedArgument = ((XObject) argument).object();
                argList.add(i, passedArgument);
            } else {
                argList.add(i, argument);
            }
        }
        return (xpathFunction.evaluate(argList));
    } catch (XPathFunctionException xfe) {
        // further execution by throwing WrappedRuntimeException 
        throw new org.apache.xml.utils.WrappedRuntimeException(xfe);
    } catch (Exception e) {
        throw new javax.xml.transform.TransformerException(e);
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TransformerException(javax.xml.transform.TransformerException) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XNodeSet(org.apache.xpath.objects.XNodeSet) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XObject(org.apache.xpath.objects.XObject) QName(javax.xml.namespace.QName) XPathFunction(javax.xml.xpath.XPathFunction) XObject(org.apache.xpath.objects.XObject)

Example 2 with XPathFunctionException

use of javax.xml.xpath.XPathFunctionException in project robovm by robovm.

the class JAXPExtensionsProvider method extFunction.

/**
     * Execute the extension function.
     */
public Object extFunction(FuncExtFunction extFunction, Vector argVec) throws javax.xml.transform.TransformerException {
    try {
        String namespace = extFunction.getNamespace();
        String functionName = extFunction.getFunctionName();
        int arity = extFunction.getArgCount();
        javax.xml.namespace.QName myQName = new javax.xml.namespace.QName(namespace, functionName);
        // throw XPathFunctionException
        if (extensionInvocationDisabled) {
            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { myQName.toString() });
            throw new XPathFunctionException(fmsg);
        }
        XPathFunction xpathFunction = resolver.resolveFunction(myQName, arity);
        ArrayList argList = new ArrayList(arity);
        for (int i = 0; i < arity; i++) {
            Object argument = argVec.elementAt(i);
            // Explicitly getting NodeList by using nodelist()
            if (argument instanceof XNodeSet) {
                argList.add(i, ((XNodeSet) argument).nodelist());
            } else if (argument instanceof XObject) {
                Object passedArgument = ((XObject) argument).object();
                argList.add(i, passedArgument);
            } else {
                argList.add(i, argument);
            }
        }
        return (xpathFunction.evaluate(argList));
    } catch (XPathFunctionException xfe) {
        // further execution by throwing WrappedRuntimeException
        throw new org.apache.xml.utils.WrappedRuntimeException(xfe);
    } catch (Exception e) {
        throw new javax.xml.transform.TransformerException(e);
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) QName(javax.xml.namespace.QName) XPathFunction(javax.xml.xpath.XPathFunction) ArrayList(java.util.ArrayList) TransformerException(javax.xml.transform.TransformerException) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XNodeSet(org.apache.xpath.objects.XNodeSet) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XObject(org.apache.xpath.objects.XObject) QName(javax.xml.namespace.QName) XObject(org.apache.xpath.objects.XObject)

Example 3 with XPathFunctionException

use of javax.xml.xpath.XPathFunctionException in project j2objc by google.

the class JAXPExtensionsProvider method extFunction.

/**
 * Execute the extension function.
 */
public Object extFunction(String ns, String funcName, Vector argVec, Object methodKey) throws javax.xml.transform.TransformerException {
    try {
        if (funcName == null) {
            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "Function Name" });
            throw new NullPointerException(fmsg);
        }
        // Find the XPathFunction corresponding to namespace and funcName
        javax.xml.namespace.QName myQName = new QName(ns, funcName);
        // throw XPathFunctionException
        if (extensionInvocationDisabled) {
            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { myQName.toString() });
            throw new XPathFunctionException(fmsg);
        }
        // Assuming user is passing all the needed parameters ( including
        // default values )
        int arity = argVec.size();
        javax.xml.xpath.XPathFunction xpathFunction = resolver.resolveFunction(myQName, arity);
        // not using methodKey
        ArrayList argList = new ArrayList(arity);
        for (int i = 0; i < arity; i++) {
            Object argument = argVec.elementAt(i);
            // Explicitly getting NodeList by using nodelist()
            if (argument instanceof XNodeSet) {
                argList.add(i, ((XNodeSet) argument).nodelist());
            } else if (argument instanceof XObject) {
                Object passedArgument = ((XObject) argument).object();
                argList.add(i, passedArgument);
            } else {
                argList.add(i, argument);
            }
        }
        return (xpathFunction.evaluate(argList));
    } catch (XPathFunctionException xfe) {
        // further execution by throwing WrappedRuntimeException
        throw new org.apache.xml.utils.WrappedRuntimeException(xfe);
    } catch (Exception e) {
        throw new javax.xml.transform.TransformerException(e);
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TransformerException(javax.xml.transform.TransformerException) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XNodeSet(org.apache.xpath.objects.XNodeSet) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XObject(org.apache.xpath.objects.XObject) QName(javax.xml.namespace.QName) XPathFunction(javax.xml.xpath.XPathFunction) XObject(org.apache.xpath.objects.XObject)

Example 4 with XPathFunctionException

use of javax.xml.xpath.XPathFunctionException in project j2objc by google.

the class JAXPExtensionsProvider method extFunction.

/**
 * Execute the extension function.
 */
public Object extFunction(FuncExtFunction extFunction, Vector argVec) throws javax.xml.transform.TransformerException {
    try {
        String namespace = extFunction.getNamespace();
        String functionName = extFunction.getFunctionName();
        int arity = extFunction.getArgCount();
        javax.xml.namespace.QName myQName = new javax.xml.namespace.QName(namespace, functionName);
        // throw XPathFunctionException
        if (extensionInvocationDisabled) {
            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { myQName.toString() });
            throw new XPathFunctionException(fmsg);
        }
        XPathFunction xpathFunction = resolver.resolveFunction(myQName, arity);
        ArrayList argList = new ArrayList(arity);
        for (int i = 0; i < arity; i++) {
            Object argument = argVec.elementAt(i);
            // Explicitly getting NodeList by using nodelist()
            if (argument instanceof XNodeSet) {
                argList.add(i, ((XNodeSet) argument).nodelist());
            } else if (argument instanceof XObject) {
                Object passedArgument = ((XObject) argument).object();
                argList.add(i, passedArgument);
            } else {
                argList.add(i, argument);
            }
        }
        return (xpathFunction.evaluate(argList));
    } catch (XPathFunctionException xfe) {
        // further execution by throwing WrappedRuntimeException
        throw new org.apache.xml.utils.WrappedRuntimeException(xfe);
    } catch (Exception e) {
        throw new javax.xml.transform.TransformerException(e);
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) QName(javax.xml.namespace.QName) XPathFunction(javax.xml.xpath.XPathFunction) ArrayList(java.util.ArrayList) TransformerException(javax.xml.transform.TransformerException) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XNodeSet(org.apache.xpath.objects.XNodeSet) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XObject(org.apache.xpath.objects.XObject) QName(javax.xml.namespace.QName) XObject(org.apache.xpath.objects.XObject)

Example 5 with XPathFunctionException

use of javax.xml.xpath.XPathFunctionException in project gocd by gocd.

the class NokogiriXPathFunction method evaluate.

public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() != this.arity) {
        throw new XPathFunctionException("arity does not match");
    }
    Ruby ruby = this.handler.getRuntime();
    ThreadContext context = ruby.getCurrentContext();
    IRubyObject result = RuntimeHelpers.invoke(context, this.handler, this.name, fromObjectToRubyArgs(args));
    return fromRubyToObject(result);
}
Also used : XPathFunctionException(javax.xml.xpath.XPathFunctionException) ThreadContext(org.jruby.runtime.ThreadContext) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby)

Aggregations

XPathFunctionException (javax.xml.xpath.XPathFunctionException)9 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 TransformerException (javax.xml.transform.TransformerException)4 XPathFunction (javax.xml.xpath.XPathFunction)4 XNodeSet (org.apache.xpath.objects.XNodeSet)4 XObject (org.apache.xpath.objects.XObject)4 Ruby (org.jruby.Ruby)3 ThreadContext (org.jruby.runtime.ThreadContext)3 IRubyObject (org.jruby.runtime.builtin.IRubyObject)3 Nullable (javax.annotation.Nullable)1 JPConverter (net.sf.saxon.expr.JPConverter)1 XPathContextMajor (net.sf.saxon.expr.XPathContextMajor)1 Sequence (net.sf.saxon.om.Sequence)1 RubyString (org.jruby.RubyString)1