Search in sources :

Example 16 with XObject

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

the class VariableStack method getLocalVariable.

/**
   * Get a local variable or parameter in the current stack frame.
   *
   *
   * @param xctxt The XPath context, which must be passed in order to
   * lazy evaluate variables.
   *
   * @param index Local variable index relative to the current stack
   * frame bottom.
   *
   * @return The value of the variable.
   *
   * @throws TransformerException
   */
public XObject getLocalVariable(XPathContext xctxt, int index) throws TransformerException {
    index += _currentFrameBottom;
    XObject val = _stackFrames[index];
    if (null == val)
        throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null), xctxt.getSAXLocator());
    // Lazy execution of variables.
    if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
        return (_stackFrames[index] = val.execute(xctxt));
    return val;
}
Also used : XObject(org.apache.xpath.objects.XObject) TransformerException(javax.xml.transform.TransformerException)

Example 17 with XObject

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

the class XPath method getMatchScore.

/**
   * Get the match score of the given node.
   *
   * @param xctxt XPath runtime context.
   * @param context The current source tree context node.
   * 
   * @return score, one of {@link #MATCH_SCORE_NODETEST},
   * {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER}, 
   * or {@link #MATCH_SCORE_QNAME}.
   *
   * @throws javax.xml.transform.TransformerException
   */
public double getMatchScore(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException {
    xctxt.pushCurrentNode(context);
    xctxt.pushCurrentExpressionNode(context);
    try {
        XObject score = m_mainExp.execute(xctxt);
        if (DEBUG_MATCHES) {
            DTM dtm = xctxt.getDTM(context);
            System.out.println("score: " + score.num() + " for " + dtm.getNodeName(context) + " for xpath " + this.getPatternString());
        }
        return score.num();
    } finally {
        xctxt.popCurrentNode();
        xctxt.popCurrentExpressionNode();
    }
// return XPath.MATCH_SCORE_NONE;
}
Also used : DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 18 with XObject

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

the class XPath method execute.

/**
   * Given an expression and a context, evaluate the XPath
   * and return the result.
   * 
   * @param xctxt The execution context.
   * @param contextNode The node that "." expresses.
   * @param namespaceContext The context in which namespaces in the
   * XPath are supposed to be expanded.
   * 
   * @throws TransformerException thrown if the active ProblemListener decides
   * the error condition is severe enough to halt processing.
   *
   * @throws javax.xml.transform.TransformerException
   * @xsl.usage experimental
   */
public XObject execute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException {
    xctxt.pushNamespaceContext(namespaceContext);
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
    XObject xobj = null;
    try {
        xobj = m_mainExp.execute(xctxt);
    } catch (TransformerException te) {
        te.setLocator(this.getLocator());
        ErrorListener el = xctxt.getErrorListener();
        if (// defensive, should never happen.
        null != el) {
            el.error(te);
        } else
            throw te;
    } catch (Exception e) {
        while (e instanceof org.apache.xml.utils.WrappedRuntimeException) {
            e = ((org.apache.xml.utils.WrappedRuntimeException) e).getException();
        }
        // e.printStackTrace();
        String msg = e.getMessage();
        if (msg == null || msg.length() == 0) {
            msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XPATH_ERROR, null);
        }
        TransformerException te = new TransformerException(msg, getLocator(), e);
        ErrorListener el = xctxt.getErrorListener();
        // te.printStackTrace();
        if (// defensive, should never happen.
        null != el) {
            el.fatalError(te);
        } else
            throw te;
    } finally {
        xctxt.popNamespaceContext();
        xctxt.popCurrentNodeAndExpression();
    }
    return xobj;
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) XObject(org.apache.xpath.objects.XObject) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException)

Example 19 with XObject

use of org.apache.xpath.objects.XObject 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 20 with XObject

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

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