Search in sources :

Example 16 with VariableStack

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

the class XUnresolvedVariable 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 {
    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 {
        if (-1 != velem.m_frameSize)
            vars.unlink(currentFrame);
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack) XObject(org.apache.xpath.objects.XObject)

Example 17 with VariableStack

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

Example 18 with VariableStack

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

the class WalkingIterator method nextNode.

/**
   *  Returns the next node in the set and advances the position of the
   * iterator in the set. After a NodeIterator is created, the first call
   * to nextNode() returns the first node in the set.
   * @return  The next <code>Node</code> in the set being iterated over, or
   *   <code>null</code> if there are no more members in that set.
   */
public int nextNode() {
    if (m_foundLast)
        return DTM.NULL;
    // from the execute method.
    if (-1 == m_stackFrame) {
        return returnNextNode(m_firstWalker.nextNode());
    } else {
        VariableStack vars = m_execContext.getVarStack();
        // These three statements need to be combined into one operation.
        int savedStart = vars.getStackFrame();
        vars.setStackFrame(m_stackFrame);
        int n = returnNextNode(m_firstWalker.nextNode());
        // These two statements need to be combined into one operation.
        vars.setStackFrame(savedStart);
        return n;
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack)

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