use of org.apache.xpath.objects.XObject in project j2objc by google.
the class ContextMatchStepPattern method executeRelativePathPattern.
/**
* Execute the match pattern step relative to another step.
*
* @param xctxt The XPath runtime context.
* NEEDSDOC @param prevStep
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject executeRelativePathPattern(XPathContext xctxt, StepPattern prevStep) throws javax.xml.transform.TransformerException {
XObject score = NodeTest.SCORE_NONE;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
if (null != dtm) {
int predContext = xctxt.getCurrentNode();
DTMAxisTraverser traverser;
int axis = m_axis;
boolean needToTraverseAttrs = WalkerFactory.isDownwardAxisOfMany(axis);
boolean iterRootIsAttr = (dtm.getNodeType(xctxt.getIteratorRoot()) == DTM.ATTRIBUTE_NODE);
if ((Axis.PRECEDING == axis) && iterRootIsAttr) {
axis = Axis.PRECEDINGANDANCESTOR;
}
traverser = dtm.getAxisTraverser(axis);
for (int relative = traverser.first(context); DTM.NULL != relative; relative = traverser.next(context, relative)) {
try {
xctxt.pushCurrentNode(relative);
score = execute(xctxt);
if (score != NodeTest.SCORE_NONE) {
// predContext, relative);
if (executePredicates(xctxt, dtm, context))
return score;
score = NodeTest.SCORE_NONE;
}
if (needToTraverseAttrs && iterRootIsAttr && (DTM.ELEMENT_NODE == dtm.getNodeType(relative))) {
int xaxis = Axis.ATTRIBUTE;
for (int i = 0; i < 2; i++) {
DTMAxisTraverser atraverser = dtm.getAxisTraverser(xaxis);
for (int arelative = atraverser.first(relative); DTM.NULL != arelative; arelative = atraverser.next(relative, arelative)) {
try {
xctxt.pushCurrentNode(arelative);
score = execute(xctxt);
if (score != NodeTest.SCORE_NONE) {
if (score != NodeTest.SCORE_NONE)
return score;
}
} finally {
xctxt.popCurrentNode();
}
}
xaxis = Axis.NAMESPACE;
}
}
} finally {
xctxt.popCurrentNode();
}
}
}
return score;
}
use of org.apache.xpath.objects.XObject 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);
}
}
use of org.apache.xpath.objects.XObject 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);
}
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class XPathImpl method eval.
private XObject eval(String expression, Object contextItem) throws javax.xml.transform.TransformerException {
org.apache.xpath.XPath xpath = new org.apache.xpath.XPath(expression, null, prefixResolver, org.apache.xpath.XPath.SELECT);
org.apache.xpath.XPathContext xpathSupport = null;
// expressions.
if (functionResolver != null) {
JAXPExtensionsProvider jep = new JAXPExtensionsProvider(functionResolver, featureSecureProcessing);
xpathSupport = new org.apache.xpath.XPathContext(jep, false);
} else {
xpathSupport = new org.apache.xpath.XPathContext(false);
}
XObject xobj = null;
xpathSupport.setVarStack(new JAXPVariableStack(variableResolver));
// If item is null, then we will create a a Dummy contextNode
if (contextItem instanceof Node) {
xobj = xpath.execute(xpathSupport, (Node) contextItem, prefixResolver);
} else {
xobj = xpath.execute(xpathSupport, DTM.NULL, prefixResolver);
}
return xobj;
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class XPathImpl method evaluate.
/**
* <p>Evaluate an XPath expression in the context of the specified <code>InputSource</code>
* and return the result as the specified type.</p>
*
* <p>This method builds a data model for the {@link InputSource} and calls
* {@link #evaluate(String expression, Object item, QName returnType)} on the resulting document object.</p>
*
* <p>See "Evaluation of XPath Expressions" section of JAXP 1.3 spec
* for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
* then an <code>IllegalArgumentException</code> is thrown.</p>
*
* <p>If <code>expression</code>, <code>source</code> or <code>returnType</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
* @param source The input source of the document to evaluate over.
* @param returnType The desired return type.
*
* @return The <code>Object</code> that encapsulates the result of evaluating the expression.
*
* @throws XPathExpressionException If expression cannot be evaluated.
* @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
* @throws NullPointerException If <code>expression</code>, <code>source</code> or <code>returnType</code>
* is <code>null</code>.
*/
public Object evaluate(String expression, InputSource source, QName returnType) throws XPathExpressionException {
// Checking validity of different parameters
if (source == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "source" });
throw new NullPointerException(fmsg);
}
if (expression == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "XPath expression" });
throw new NullPointerException(fmsg);
}
if (returnType == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "returnType" });
throw new NullPointerException(fmsg);
}
// returnType need to be defined in XPathConstants
if (!isSupported(returnType)) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, new Object[] { returnType.toString() });
throw new IllegalArgumentException(fmsg);
}
try {
Document document = getParser().parse(source);
XObject resultObject = eval(expression, document);
return getResultAsType(resultObject, returnType);
} catch (SAXException e) {
throw new XPathExpressionException(e);
} catch (IOException e) {
throw new XPathExpressionException(e);
} catch (javax.xml.transform.TransformerException te) {
Throwable nestedException = te.getException();
if (nestedException instanceof javax.xml.xpath.XPathFunctionException) {
throw (javax.xml.xpath.XPathFunctionException) nestedException;
} else {
throw new XPathExpressionException(te);
}
}
}
Aggregations