use of org.apache.xpath.objects.XNodeSet in project robovm by robovm.
the class Variable method execute.
/**
* Dereference the variable, and return the reference value. Note that lazy
* evaluation will occur. If a variable within scope is not found, a warning
* will be sent to the error listener, and an empty nodeset will be returned.
*
*
* @param xctxt The runtime execution context.
*
* @return The evaluated variable, or an empty nodeset if not found.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException {
org.apache.xml.utils.PrefixResolver xprefixResolver = xctxt.getNamespaceContext();
XObject result;
// XObject result = xctxt.getVariable(m_qname);
if (m_fixUpWasCalled) {
if (m_isGlobal)
result = xctxt.getVarStack().getGlobalVariable(xctxt, m_index, destructiveOK);
else
result = xctxt.getVarStack().getLocalVariable(xctxt, m_index, destructiveOK);
} else {
result = xctxt.getVarStack().getVariableOrParam(xctxt, m_qname);
}
if (null == result) {
// This should now never happen...
warn(xctxt, XPATHErrorResources.WG_ILLEGAL_VARIABLE_REFERENCE, //"VariableReference given for variable out "+
new Object[] { m_qname.getLocalPart() });
// (new RuntimeException()).printStackTrace();
// error(xctxt, XPATHErrorResources.ER_COULDNOT_GET_VAR_NAMED,
// new Object[]{ m_qname.getLocalPart() }); //"Could not get variable named "+varName);
result = new XNodeSet(xctxt.getDTMManager());
}
return result;
// }
// else
// {
// // Hack city... big time. This is needed to evaluate xpaths from extensions,
// // pending some bright light going off in my head. Some sort of callback?
// synchronized(this)
// {
// org.apache.xalan.templates.ElemVariable vvar= getElemVariable();
// if(null != vvar)
// {
// m_index = vvar.getIndex();
// m_isGlobal = vvar.getIsTopLevel();
// m_fixUpWasCalled = true;
// return execute(xctxt);
// }
// }
// throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[]{m_qname.toString()})); //"Variable not resolvable: "+m_qname);
// }
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class FuncDocument 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 = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
XObject arg = (XObject) this.getArg0().execute(xctxt);
String base = "";
Expression arg1Expr = this.getArg1();
if (null != arg1Expr) {
// The URI reference may be relative. The base URI (see [3.2 Base URI])
// of the node in the second argument node-set that is first in document
// order is used as the base URI for resolving the
// relative URI into an absolute URI.
XObject arg2 = arg1Expr.execute(xctxt);
if (XObject.CLASS_NODESET == arg2.getType()) {
int baseNode = arg2.iter().nextNode();
if (baseNode == DTM.NULL) {
// See http://www.w3.org/1999/11/REC-xslt-19991116-errata#E14.
// If the second argument is an empty nodeset, this is an error.
// The processor can recover by returning an empty nodeset.
warn(xctxt, XSLTErrorResources.WG_EMPTY_SECOND_ARG, null);
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
return nodes;
} else {
DTM baseDTM = xctxt.getDTM(baseNode);
base = baseDTM.getDocumentBaseURI();
}
// %REVIEW% This doesn't seem to be a problem with the conformance
// suite, but maybe it's just not doing a good test?
// int baseDoc = baseDTM.getDocument();
//
// if (baseDoc == DTM.NULL /* || baseDoc instanceof Stylesheet -->What to do?? */)
// {
//
// // base = ((Stylesheet)baseDoc).getBaseIdentifier();
// base = xctxt.getNamespaceContext().getBaseIdentifier();
// }
// else
// base = xctxt.getSourceTreeManager().findURIFromDoc(baseDoc);
} else {
//Can not convert other type to a node-set!;
arg2.iter();
}
} else {
// If the second argument is omitted, then it defaults to
// the node in the stylesheet that contains the expression that
// includes the call to the document function. Note that a
// zero-length URI reference is a reference to the document
// relative to which the URI reference is being resolved; thus
// document("") refers to the root node of the stylesheet;
// the tree representation of the stylesheet is exactly
// the same as if the XML document containing the stylesheet
// was the initial source document.
assertion(null != xctxt.getNamespaceContext(), "Namespace context can not be null!");
base = xctxt.getNamespaceContext().getBaseIdentifier();
}
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM mnl = nodes.mutableNodeset();
DTMIterator iterator = (XObject.CLASS_NODESET == arg.getType()) ? arg.iter() : null;
int pos = DTM.NULL;
while ((null == iterator) || (DTM.NULL != (pos = iterator.nextNode()))) {
XMLString ref = (null != iterator) ? xctxt.getDTM(pos).getStringValue(pos) : arg.xstr();
// member.
if (null == arg1Expr && DTM.NULL != pos) {
DTM baseDTM = xctxt.getDTM(pos);
base = baseDTM.getDocumentBaseURI();
}
if (null == ref)
continue;
if (DTM.NULL == docContext) {
//"context does not have an owner document!");
error(xctxt, XSLTErrorResources.ER_NO_CONTEXT_OWNERDOC, null);
}
// From http://www.ics.uci.edu/pub/ietf/uri/rfc1630.txt
// A partial form can be distinguished from an absolute form in that the
// latter must have a colon and that colon must occur before any slash
// characters. Systems not requiring partial forms should not use any
// unencoded slashes in their naming schemes. If they do, absolute URIs
// will still work, but confusion may result.
int indexOfColon = ref.indexOf(':');
int indexOfSlash = ref.indexOf('/');
if ((indexOfColon != -1) && (indexOfSlash != -1) && (indexOfColon < indexOfSlash)) {
// The url (or filename, for that matter) is absolute.
base = null;
}
int newDoc = getDoc(xctxt, context, ref.toString(), base);
// nodes.mutableNodeset().addNode(newDoc);
if (DTM.NULL != newDoc) {
// TODO: mnl.addNodeInDocOrder(newDoc, true, xctxt); ??
if (!mnl.contains(newDoc)) {
mnl.addElement(newDoc);
}
}
if (null == iterator || newDoc == DTM.NULL)
break;
}
return nodes;
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class KeyManager method getNodeSetDTMByKey.
/**
* Given a valid element key, return the corresponding node list.
*
* @param xctxt The XPath runtime state
* @param doc The document node
* @param name The key element name
* @param ref The key value we're looking for
* @param nscontext The prefix resolver for the execution context
*
* @return A nodelist of nodes mathing the given key
*
* @throws javax.xml.transform.TransformerException
*/
public XNodeSet getNodeSetDTMByKey(XPathContext xctxt, int doc, QName name, XMLString ref, PrefixResolver nscontext) throws javax.xml.transform.TransformerException {
XNodeSet nl = null;
// yuck -sb
ElemTemplateElement template = (ElemTemplateElement) nscontext;
if ((null != template) && null != template.getStylesheetRoot().getKeysComposed()) {
boolean foundDoc = false;
if (null == m_key_tables) {
m_key_tables = new Vector(4);
} else {
int nKeyTables = m_key_tables.size();
for (int i = 0; i < nKeyTables; i++) {
KeyTable kt = (KeyTable) m_key_tables.elementAt(i);
if (kt.getKeyTableName().equals(name) && doc == kt.getDocKey()) {
nl = kt.getNodeSetDTMByKey(name, ref);
if (nl != null) {
foundDoc = true;
break;
}
}
}
}
if ((null == nl) && !foundDoc) /* && m_needToBuildKeysTable */
{
KeyTable kt = new KeyTable(doc, nscontext, name, template.getStylesheetRoot().getKeysComposed(), xctxt);
m_key_tables.addElement(kt);
if (doc == kt.getDocKey()) {
foundDoc = true;
nl = kt.getNodeSetDTMByKey(name, ref);
}
}
}
return nl;
}
use of org.apache.xpath.objects.XNodeSet 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.XNodeSet 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);
}
}
Aggregations