Search in sources :

Example 21 with Expression

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

the class FuncExtFunction method fixupVariables.

/**
   * This function is used to fixup variables from QNames to stack frame
   * indexes at stylesheet build time.
   * @param vars List of QNames that correspond to variables.  This list
   * should be searched backwards for the first qualified name that
   * corresponds to the variable reference qname.  The position of the
   * QName in the vector from the start of the vector will be its position
   * in the stack frame (but variables above the globalsTop value will need
   * to be offset to the current stack frame).
   * NEEDSDOC @param globalsSize
   */
public void fixupVariables(java.util.Vector vars, int globalsSize) {
    if (null != m_argVec) {
        int nArgs = m_argVec.size();
        for (int i = 0; i < nArgs; i++) {
            Expression arg = (Expression) m_argVec.elementAt(i);
            arg.fixupVariables(vars, globalsSize);
        }
    }
}
Also used : Expression(org.apache.xpath.Expression)

Example 22 with Expression

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

the class ElemValueOf method execute.

/**
   * Execute the string expression and copy the text to the
   * result tree.
   * The required select attribute is an expression; this expression
   * is evaluated and the resulting object is converted to a string
   * as if by a call to the string function. The string specifies
   * the string-value of the created text node. If the string is
   * empty, no text node will be created. The created text node will
   * be merged with any adjacent text nodes.
   * @see <a href="http://www.w3.org/TR/xslt#value-of">value-of 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 {
    XPathContext xctxt = transformer.getXPathContext();
    SerializationHandler rth = transformer.getResultTreeHandler();
    try {
        // Optimize for "."
        xctxt.pushNamespaceContext(this);
        int current = xctxt.getCurrentNode();
        xctxt.pushCurrentNodeAndExpression(current, current);
        if (m_disableOutputEscaping)
            rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
        try {
            Expression expr = m_selectExpression.getExpression();
            expr.executeCharsToContentHandler(xctxt, rth);
        } finally {
            if (m_disableOutputEscaping)
                rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
            xctxt.popNamespaceContext();
            xctxt.popCurrentNodeAndExpression();
        }
    } catch (SAXException se) {
        throw new TransformerException(se);
    } catch (RuntimeException re) {
        TransformerException te = new TransformerException(re);
        te.setLocator(this);
        throw te;
    }
}
Also used : Expression(org.apache.xpath.Expression) SerializationHandler(org.apache.xml.serializer.SerializationHandler) XPathContext(org.apache.xpath.XPathContext) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 23 with Expression

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

the class RedundentExprEliminator method oldFindAndEliminateRedundant.

/**
   * To be removed.
   */
protected int oldFindAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException {
    QName uniquePseudoVarName = null;
    boolean foundFirst = false;
    int numPathsFound = 0;
    int n = paths.size();
    Expression expr1 = firstOccuranceOwner.getExpression();
    if (DEBUG)
        assertIsLocPathIterator(expr1, firstOccuranceOwner);
    boolean isGlobal = (paths == m_absPaths);
    LocPathIterator lpi = (LocPathIterator) expr1;
    for (int j = start; j < n; j++) {
        ExpressionOwner owner2 = (ExpressionOwner) paths.elementAt(j);
        if (null != owner2) {
            Expression expr2 = owner2.getExpression();
            boolean isEqual = expr2.deepEquals(lpi);
            if (isEqual) {
                LocPathIterator lpi2 = (LocPathIterator) expr2;
                if (!foundFirst) {
                    foundFirst = true;
                    // Insert variable decl into psuedoVarRecipient
                    // We want to insert this into the first legitimate 
                    // position for a variable.
                    ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, isGlobal);
                    if (null == var)
                        return 0;
                    uniquePseudoVarName = var.getName();
                    changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
                    // Replace the first occurance with the variable's XPath, so  
                    // that further reduction may take place if needed.
                    paths.setElementAt(var.getSelect(), firstOccuranceIndex);
                    numPathsFound++;
                }
                changeToVarRef(uniquePseudoVarName, owner2, paths, psuedoVarRecipient);
                // Null out the occurance, so we don't have to test it again.
                paths.setElementAt(null, j);
                // foundFirst = true;
                numPathsFound++;
            }
        }
    }
    // Change all globals in xsl:templates, etc, to global vars no matter what.
    if ((0 == numPathsFound) && (paths == m_absPaths)) {
        ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, true);
        if (null == var)
            return 0;
        uniquePseudoVarName = var.getName();
        changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
        paths.setElementAt(var.getSelect(), firstOccuranceIndex);
        numPathsFound++;
    }
    return numPathsFound;
}
Also used : Expression(org.apache.xpath.Expression) QName(org.apache.xml.utils.QName) LocPathIterator(org.apache.xpath.axes.LocPathIterator) ExpressionOwner(org.apache.xpath.ExpressionOwner)

Example 24 with Expression

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

the class TemplateList method setTemplate.

/**
   * Add a template to the table of named templates and/or the table of templates
   * with match patterns.  This routine should
   * be called in decreasing order of precedence but it checks nonetheless.
   *
   * @param template
   */
public void setTemplate(ElemTemplate template) {
    XPath matchXPath = template.getMatch();
    if (null == template.getName() && null == matchXPath) {
        template.error(XSLTErrorResources.ER_NEED_NAME_OR_MATCH_ATTRIB, new Object[] { "xsl:template" });
    }
    if (null != template.getName()) {
        ElemTemplate existingTemplate = (ElemTemplate) m_namedTemplates.get(template.getName());
        if (null == existingTemplate) {
            m_namedTemplates.put(template.getName(), template);
        } else {
            int existingPrecedence = existingTemplate.getStylesheetComposed().getImportCountComposed();
            int newPrecedence = template.getStylesheetComposed().getImportCountComposed();
            if (newPrecedence > existingPrecedence) {
                // This should never happen
                m_namedTemplates.put(template.getName(), template);
            } else if (newPrecedence == existingPrecedence)
                template.error(XSLTErrorResources.ER_DUPLICATE_NAMED_TEMPLATE, new Object[] { template.getName() });
        }
    }
    if (null != matchXPath) {
        Expression matchExpr = matchXPath.getExpression();
        if (matchExpr instanceof StepPattern) {
            insertPatternInTable((StepPattern) matchExpr, template);
        } else if (matchExpr instanceof UnionPattern) {
            UnionPattern upat = (UnionPattern) matchExpr;
            StepPattern[] pats = upat.getPatterns();
            int n = pats.length;
            for (int i = 0; i < n; i++) {
                insertPatternInTable(pats[i], template);
            }
        } else {
        // TODO: assert error
        }
    }
}
Also used : XPath(org.apache.xpath.XPath) Expression(org.apache.xpath.Expression) StepPattern(org.apache.xpath.patterns.StepPattern) UnionPattern(org.apache.xpath.patterns.UnionPattern)

Example 25 with Expression

use of org.apache.xpath.Expression 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;
}
Also used : Expression(org.apache.xpath.Expression) XObject(org.apache.xpath.objects.XObject)

Aggregations

Expression (org.apache.xpath.Expression)28 XObject (org.apache.xpath.objects.XObject)8 QName (org.apache.xml.utils.QName)6 TransformerException (javax.xml.transform.TransformerException)4 ExpressionOwner (org.apache.xpath.ExpressionOwner)4 XPathContext (org.apache.xpath.XPathContext)4 LocPathIterator (org.apache.xpath.axes.LocPathIterator)4 XNodeSet (org.apache.xpath.objects.XNodeSet)4 StepPattern (org.apache.xpath.patterns.StepPattern)4 Vector (java.util.Vector)2 DTM (org.apache.xml.dtm.DTM)2 DTMIterator (org.apache.xml.dtm.DTMIterator)2 DTMManager (org.apache.xml.dtm.DTMManager)2 SerializationHandler (org.apache.xml.serializer.SerializationHandler)2 XMLString (org.apache.xml.utils.XMLString)2 ExtensionsProvider (org.apache.xpath.ExtensionsProvider)2 NodeSetDTM (org.apache.xpath.NodeSetDTM)2 XPath (org.apache.xpath.XPath)2 WrongNumberArgsException (org.apache.xpath.functions.WrongNumberArgsException)2 XNull (org.apache.xpath.objects.XNull)2