本文整理汇总了Java中org.apache.xpath.XPathContext.getVarStack方法的典型用法代码示例。如果您正苦于以下问题:Java XPathContext.getVarStack方法的具体用法?Java XPathContext.getVarStack怎么用?Java XPathContext.getVarStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathContext
的用法示例。
在下文中一共展示了XPathContext.getVarStack方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pushGlobalVars
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Internal -- push the global variables from the Stylesheet onto
* the context's runtime variable stack.
* <p>If we encounter a variable
* that is already defined in the variable stack, we ignore it. This
* is because the second variable definition will be at a lower import
* precedence. Presumably, global"variables at the same import precedence
* with the same name will have been caught during the recompose process.
* <p>However, if we encounter a parameter that is already defined in the
* variable stack, we need to see if this is a parameter whose value was
* supplied by a setParameter call. If so, we need to "receive" the one
* already in the stack, ignoring this one. If it is just an earlier
* xsl:param or xsl:variable definition, we ignore it using the same
* reasoning as explained above for the variable.
*
* @param contextNode The root of the source tree, can't be null.
*
* @throws TransformerException
*/
protected void pushGlobalVars(int contextNode) throws TransformerException
{
XPathContext xctxt = m_xcontext;
VariableStack vs = xctxt.getVarStack();
StylesheetRoot sr = getStylesheet();
Vector vars = sr.getVariablesAndParamsComposed();
int i = vars.size();
vs.link(i);
while (--i >= 0)
{
ElemVariable v = (ElemVariable) vars.elementAt(i);
// XObject xobj = v.getValue(this, contextNode);
XObject xobj = new XUnresolvedVariable(v, contextNode, this,
vs.getStackFrame(), 0, true);
if(null == vs.elementAt(i))
vs.setGlobalVariable(i, xobj);
}
}
示例2: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* 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
{
if (!m_doneEval)
{
this.m_transformer.getMsgMgr().error
(xctxt.getSAXLocator(), XSLTErrorResources.ER_REFERENCING_ITSELF,
new Object[]{((ElemVariable)this.object()).getName().getLocalName()});
}
VariableStack vars = xctxt.getVarStack();
// These three statements need to be combined into one operation.
int currentFrame = vars.getStackFrame();
//// vars.setStackFrame(m_varStackPos);
ElemVariable velem = (ElemVariable)m_obj;
try
{
m_doneEval = false;
if(-1 != velem.m_frameSize)
vars.link(velem.m_frameSize);
XObject var = velem.getValue(m_transformer, m_context);
m_doneEval = true;
return var;
}
finally
{
// These two statements need to be combined into one operation.
// vars.setStackFrame(currentFrame);
if(-1 != velem.m_frameSize)
vars.unlink(currentFrame);
}
}
示例3: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
public void execute(TransformerImpl transformer, XObject[] args)
throws TransformerException
{
XPathContext xctxt = transformer.getXPathContext();
VariableStack vars = xctxt.getVarStack();
// Increment the frame bottom of the variable stack by the
// frame size
int thisFrame = vars.getStackFrame();
int nextFrame = vars.link(m_frameSize);
if (m_inArgsSize < args.length) {
throw new TransformerException ("function called with too many args");
}
// Set parameters,
// have to clear the section of the stack frame that has params.
if (m_inArgsSize > 0) {
vars.clearLocalSlots(0, m_inArgsSize);
if (args.length > 0) {
vars.setStackFrame(thisFrame);
NodeList children = this.getChildNodes();
for (int i = 0; i < args.length; i ++) {
Node child = children.item(i);
if (children.item(i) instanceof ElemParam) {
ElemParam param = (ElemParam)children.item(i);
vars.setLocalVariable(param.getIndex(), args[i], nextFrame);
}
}
vars.setStackFrame(nextFrame);
}
}
// Removed ElemTemplate 'push' and 'pop' of RTFContext, in order to avoid losing the RTF context
// before a value can be returned. ElemExsltFunction operates in the scope of the template that called
// the function.
// xctxt.pushRTFContext();
vars.setStackFrame(nextFrame);
transformer.executeChildTemplates(this, true);
// Reset the stack frame after the function call
vars.unlink(thisFrame);
// Following ElemTemplate 'pop' removed -- see above.
// xctxt.popRTFContext();
}
示例4: executeFilterExpr
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the expression. Meant for reuse by other FilterExpr iterators
* that are not derived from this object.
*/
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt,
PrefixResolver prefixResolver,
boolean isTopLevel,
int stackFrame,
Expression expr )
throws org.apache.xml.utils.WrappedRuntimeException
{
PrefixResolver savedResolver = xctxt.getNamespaceContext();
XNodeSet result = null;
try
{
xctxt.pushCurrentNode(context);
xctxt.setNamespaceContext(prefixResolver);
// The setRoot operation can take place with a reset operation,
// and so we may not be in the context of LocPathIterator#nextNode,
// so we have to set up the variable context, execute the expression,
// and then restore the variable context.
if (isTopLevel)
{
// System.out.println("calling m_expr.execute(getXPathContext())");
VariableStack vars = xctxt.getVarStack();
// These three statements need to be combined into one operation.
int savedStart = vars.getStackFrame();
vars.setStackFrame(stackFrame);
result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
result.setShouldCacheNodes(true);
// These two statements need to be combined into one operation.
vars.setStackFrame(savedStart);
}
else
result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
}
catch (javax.xml.transform.TransformerException se)
{
// TODO: Fix...
throw new org.apache.xml.utils.WrappedRuntimeException(se);
}
finally
{
xctxt.popCurrentNode();
xctxt.setNamespaceContext(savedResolver);
}
return result;
}