use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class XUnresolvedVariableSimple method execute.
/**
* For support of literal objects in xpaths.
*
* @param xctxt The XPath execution context.
*
* @return This object.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
Expression expr = ((ElemVariable) m_obj).getSelect().getExpression();
XObject xobj = expr.execute(xctxt);
xobj.allowDetachToRelease(false);
return xobj;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class ElemCallTemplate method execute.
/**
* Invoke a named template.
* @see <a href="http://www.w3.org/TR/xslt#named-templates">named-templates in XSLT Specification</a>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
if (null != m_template) {
XPathContext xctxt = transformer.getXPathContext();
VariableStack vars = xctxt.getVarStack();
int thisframe = vars.getStackFrame();
int nextFrame = vars.link(m_template.m_frameSize);
// so that the default param evaluation will work correctly.
if (m_template.m_inArgsSize > 0) {
vars.clearLocalSlots(0, m_template.m_inArgsSize);
if (null != m_paramElems) {
int currentNode = xctxt.getCurrentNode();
vars.setStackFrame(thisframe);
int size = m_paramElems.length;
for (int i = 0; i < size; i++) {
ElemWithParam ewp = m_paramElems[i];
if (ewp.m_index >= 0) {
XObject obj = ewp.getValue(transformer, currentNode);
// Note here that the index for ElemWithParam must have been
// statically made relative to the xsl:template being called,
// NOT this xsl:template.
vars.setLocalVariable(ewp.m_index, obj, nextFrame);
}
}
vars.setStackFrame(nextFrame);
}
}
SourceLocator savedLocator = xctxt.getSAXLocator();
try {
xctxt.setSAXLocator(m_template);
// template.executeChildTemplates(transformer, sourceNode, mode, true);
transformer.pushElemTemplateElement(m_template);
m_template.execute(transformer);
} finally {
transformer.popElemTemplateElement();
xctxt.setSAXLocator(savedLocator);
// When we entered this function, the current
// frame buffer (cfb) index in the variable stack may
// have been manually set. If we just call
// unlink(), however, it will restore the cfb to the
// previous link index from the link stack, rather than
// the manually set cfb. So,
// the only safe solution is to restore it back
// to the same position it was on entry, since we're
// really not working in a stack context here. (Bug4218)
vars.unlink(thisframe);
}
} else {
transformer.getMsgMgr().error(this, XSLTErrorResources.ER_TEMPLATE_NOT_FOUND, //"Could not find template named: '"+templateName+"'");
new Object[] { m_templateName });
}
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class ElemExsltFuncResult method execute.
/**
* Generate the EXSLT function return value, and assign it to the variable
* index slot assigned for it in ElemExsltFunction compose().
*
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext context = transformer.getXPathContext();
// in the owner ElemExsltFunction execute().
if (transformer.currentFuncResultSeen()) {
throw new TransformerException("An EXSLT function cannot set more than one result!");
}
int sourceNode = context.getCurrentNode();
// Set the return value;
XObject var = getValue(transformer, sourceNode);
transformer.popCurrentFuncResult();
transformer.pushCurrentFuncResult(var);
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class FuncKey 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 {
// TransformerImpl transformer = (TransformerImpl)xctxt;
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext) {
// path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
}
String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if (argIsNodeSetDTM) {
XNodeSet ns = (XNodeSet) arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if (len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM) {
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode())) {
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null) {
// We already have 'em.
continue;
} else {
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
} else {
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}
return nodes;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
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;
}
Aggregations