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;
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations