Search in sources :

Example 11 with StepPattern

use of org.apache.xpath.patterns.StepPattern in project j2objc by google.

the class Compiler method matchPattern.

/**
 * Compile an entire match pattern expression.
 *
 * @param opPos The current position in the m_opMap array.
 *
 * @return reference to {@link org.apache.xpath.patterns.UnionPattern} instance.
 *
 * @throws TransformerException if a error occurs creating the Expression.
 */
protected Expression matchPattern(int opPos) throws TransformerException {
    locPathDepth++;
    try {
        // First, count...
        int nextOpPos = opPos;
        int i;
        for (i = 0; getOp(nextOpPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++) {
            nextOpPos = getNextOpPos(nextOpPos);
        }
        if (i == 1)
            return compile(opPos);
        UnionPattern up = new UnionPattern();
        StepPattern[] patterns = new StepPattern[i];
        for (i = 0; getOp(opPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++) {
            nextOpPos = getNextOpPos(opPos);
            patterns[i] = (StepPattern) compile(opPos);
            opPos = nextOpPos;
        }
        up.setPatterns(patterns);
        return up;
    } finally {
        locPathDepth--;
    }
}
Also used : StepPattern(org.apache.xpath.patterns.StepPattern) UnionPattern(org.apache.xpath.patterns.UnionPattern)

Example 12 with StepPattern

use of org.apache.xpath.patterns.StepPattern in project j2objc by google.

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)

Aggregations

StepPattern (org.apache.xpath.patterns.StepPattern)12 Expression (org.apache.xpath.Expression)4 ContextMatchStepPattern (org.apache.xpath.patterns.ContextMatchStepPattern)4 FunctionPattern (org.apache.xpath.patterns.FunctionPattern)4 UnionPattern (org.apache.xpath.patterns.UnionPattern)4 XPath (org.apache.xpath.XPath)2 LocPathIterator (org.apache.xpath.axes.LocPathIterator)2 PredicatedNodeTest (org.apache.xpath.axes.PredicatedNodeTest)2 SubContextList (org.apache.xpath.axes.SubContextList)2 XNodeSet (org.apache.xpath.objects.XNodeSet)2 XNumber (org.apache.xpath.objects.XNumber)2