org.apache.commons.jexl3.JxltEngine Java Examples

The following examples show how to use org.apache.commons.jexl3.JxltEngine. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateEngine.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public JxltEngine.Expression createExpression(JexlInfo info, String expression) {
    if (info == null) {
        info = jexl.createInfo();
    }
    Exception xuel = null;
    TemplateExpression stmt = null;
    try {
        stmt = cache.get(expression);
        if (stmt == null) {
            stmt = parseExpression(info, expression, null);
            cache.put(expression, stmt);
        }
    } catch (JexlException xjexl) {
        xuel = new Exception(xjexl.getInfo(), "failed to parse '" + expression + "'", xjexl);
    }
    if (xuel != null) {
        if (jexl.isSilent()) {
            jexl.logger.warn(xuel.getMessage(), xuel.getCause());
            stmt = null;
        } else {
            throw xuel;
        }
    }
    return stmt;
}
 
Example #2
Source File: TemplateDebugger.java    From commons-jexl with Apache License 2.0 5 votes vote down vote up
/**
 * Position the debugger on the root of a template expression.
 * @param je the expression
 * @return true if the expression was a {@link TemplateExpression} instance, false otherwise
 */
public boolean debug(JxltEngine.Expression je) {
    if (je instanceof TemplateExpression) {
        TemplateEngine.TemplateExpression te = (TemplateEngine.TemplateExpression) je;
        return visit(te, this) != null;
    } else {
        return false;
    }
}
 
Example #3
Source File: TemplateDebugger.java    From commons-jexl with Apache License 2.0 5 votes vote down vote up
/**
 * Position the debugger on the root of a template script.
 * @param jt the template
 * @return true if the template was a {@link TemplateScript} instance, false otherwise
 */
public boolean debug(JxltEngine.Template jt) {
    if (jt instanceof TemplateScript) {
        TemplateScript ts = (TemplateScript) jt;
        // ensure expr is not null for templates
        this.exprs = ts.getExpressions() == null? new TemplateExpression[0] : ts.getExpressions();
        this.script = ts.getScript();
        start = 0;
        end = 0;
        indentLevel = 0;
        builder.setLength(0);
        cause = script;
        int num = script.jjtGetNumChildren();
        for (int i = 0; i < num; ++i) {
            JexlNode child = script.jjtGetChild(i);
            acceptStatement(child, null);
        }
        // the last line
        if (builder.length() > 0 && builder.charAt(builder.length() - 1) != '\n') {
            builder.append('\n');
        }
        end = builder.length();
        return end > 0;
    } else {
        return false;
    }
}
 
Example #4
Source File: Interpreter.java    From commons-jexl with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluates an access identifier based on the 2 main implementations;
 * static (name or numbered identifier) or dynamic (jxlt).
 * @param node the identifier access node
 * @return the evaluated identifier
 */
private Object evalIdentifier(ASTIdentifierAccess node) {
    if (node instanceof ASTIdentifierAccessJxlt) {
        final ASTIdentifierAccessJxlt accessJxlt = (ASTIdentifierAccessJxlt) node;
        final String src = node.getName();
        Throwable cause = null;
        TemplateEngine.TemplateExpression expr = (TemplateEngine.TemplateExpression) accessJxlt.getExpression();
        try {
            if (expr == null) {
                TemplateEngine jxlt = jexl.jxlt();
                expr = jxlt.parseExpression(node.jexlInfo(), src, frame != null ? frame.getScope() : null);
                accessJxlt.setExpression(expr);
            }
            if (expr != null) {
                Object name = expr.evaluate(frame, context);
                if (name != null) {
                    Integer id = ASTIdentifierAccess.parseIdentifier(name.toString());
                    return id != null ? id : name;
                }
            }
        } catch (JxltEngine.Exception xjxlt) {
            cause = xjxlt;
        }
        return node.isSafe() ? null : unsolvableProperty(node, src, true, cause);
    } else {
        return node.getIdentifier();
    }
}
 
Example #5
Source File: JexlUtils.java    From syncope with Apache License 2.0 4 votes vote down vote up
public static JxltEngine newJxltEngine() {
    return getEngine().createJxltEngine(false);
}
 
Example #6
Source File: JexlUtilsTest.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Test
public void newJxltEngine() {
    JxltEngine engine = JexlUtils.newJxltEngine();
    assertNotNull(engine);
}
 
Example #7
Source File: ASTIdentifierAccessJxlt.java    From commons-jexl with Apache License 2.0 4 votes vote down vote up
public void setExpression(JxltEngine.Expression tp) {
    jxltExpr = tp;
}
 
Example #8
Source File: ASTIdentifierAccessJxlt.java    From commons-jexl with Apache License 2.0 4 votes vote down vote up
public JxltEngine.Expression getExpression() {
    return jxltExpr;
}