Search in sources :

Example 6 with VariableStack

use of org.apache.xpath.VariableStack in project robovm by robovm.

the class FilterExprIteratorSimple method executeFilterExpr.

/**
   * 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);
        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;
}
Also used : VariableStack(org.apache.xpath.VariableStack) PrefixResolver(org.apache.xml.utils.PrefixResolver) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 7 with VariableStack

use of org.apache.xpath.VariableStack in project j2objc by google.

the class ElemParam method execute.

/**
   * Execute a variable declaration and push it onto the variable stack.
   * @see <a href="http://www.w3.org/TR/xslt#variables">variables 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 {
    VariableStack vars = transformer.getXPathContext().getVarStack();
    if (!vars.isLocalSet(m_index)) {
        int sourceNode = transformer.getXPathContext().getCurrentNode();
        XObject var = getValue(transformer, sourceNode);
        // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
        transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack) XObject(org.apache.xpath.objects.XObject)

Example 8 with VariableStack

use of org.apache.xpath.VariableStack in project j2objc by google.

the class TransformerImpl method pushGlobalVars.

/**
   * 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);
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack) ElemVariable(org.apache.xalan.templates.ElemVariable) XUnresolvedVariable(org.apache.xalan.templates.XUnresolvedVariable) StylesheetRoot(org.apache.xalan.templates.StylesheetRoot) XPathContext(org.apache.xpath.XPathContext) Vector(java.util.Vector) NodeVector(org.apache.xml.utils.NodeVector) XObject(org.apache.xpath.objects.XObject)

Example 9 with VariableStack

use of org.apache.xpath.VariableStack in project j2objc by google.

the class TransformerImpl method clearParameters.

/**
   * Reset the parameters to a null list.
   */
public void clearParameters() {
    synchronized (m_reentryGuard) {
        VariableStack varstack = new VariableStack();
        m_xcontext.setVarStack(varstack);
        m_userParams = null;
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack)

Example 10 with VariableStack

use of org.apache.xpath.VariableStack in project j2objc by google.

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 });
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack) SourceLocator(javax.xml.transform.SourceLocator) XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject)

Aggregations

VariableStack (org.apache.xpath.VariableStack)18 XObject (org.apache.xpath.objects.XObject)10 XPathContext (org.apache.xpath.XPathContext)8 Vector (java.util.Vector)4 TransformerException (javax.xml.transform.TransformerException)4 SourceLocator (javax.xml.transform.SourceLocator)2 ElemVariable (org.apache.xalan.templates.ElemVariable)2 StylesheetRoot (org.apache.xalan.templates.StylesheetRoot)2 XUnresolvedVariable (org.apache.xalan.templates.XUnresolvedVariable)2 DTM (org.apache.xml.dtm.DTM)2 DTMIterator (org.apache.xml.dtm.DTMIterator)2 SerializationHandler (org.apache.xml.serializer.SerializationHandler)2 IntStack (org.apache.xml.utils.IntStack)2 NodeVector (org.apache.xml.utils.NodeVector)2 PrefixResolver (org.apache.xml.utils.PrefixResolver)2 QName (org.apache.xml.utils.QName)2 XNodeSet (org.apache.xpath.objects.XNodeSet)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 SAXException (org.xml.sax.SAXException)2