Search in sources :

Example 1 with UnionPattern

use of org.apache.xpath.patterns.UnionPattern 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 2 with UnionPattern

use of org.apache.xpath.patterns.UnionPattern in project robovm by robovm.

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 3 with UnionPattern

use of org.apache.xpath.patterns.UnionPattern 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 4 with UnionPattern

use of org.apache.xpath.patterns.UnionPattern 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)4 UnionPattern (org.apache.xpath.patterns.UnionPattern)4 Expression (org.apache.xpath.Expression)2 XPath (org.apache.xpath.XPath)2