Search in sources :

Example 6 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.

the class ReferenceBuilderNamespaceTest method evalTest.

@Test
public void evalTest() {
    JexlBuilder builder = new JexlBuilder();
    JexlEngine jexl = builder.create();
    JexlExpression expr = jexl.createExpression("x == 'IN_SCOPE' && y == 10");
    MapContext ctx1 = new MapContext();
    ctx1.set("x", "IN_SCOPE");
    ctx1.set("y", 10);
    MapContext ctx2 = new MapContext();
    ctx2.set("x", "IN_SCOPE");
    ctx2.set("y", 12);
    System.out.printf("Result1: [%s]\n", expr.evaluate(ctx1));
    System.out.printf("Result2: [%s]\n", expr.evaluate(ctx2));
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder) JexlExpression(org.apache.commons.jexl3.JexlExpression) MapContext(org.apache.commons.jexl3.MapContext) Test(org.junit.jupiter.api.Test)

Example 7 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project dbeaver by dbeaver.

the class DBVUtils method parseExpression.

public static JexlExpression parseExpression(String expression) {
    Map<String, Object> nsList = getExpressionNamespaces();
    JexlBuilder jexlBuilder = new JexlBuilder();
    jexlBuilder.cache(100);
    jexlBuilder.namespaces(nsList);
    JexlEngine jexlEngine = jexlBuilder.create();
    return jexlEngine.createExpression(expression);
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder)

Example 8 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project nifi by apache.

the class ExtractCCDAAttributes method onScheduled.

@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    getLogger().debug("Loading packages");
    final StopWatch stopWatch = new StopWatch(true);
    // Load required MDHT packages
    System.setProperty("org.eclipse.emf.ecore.EPackage.Registry.INSTANCE", "org.eclipse.emf.ecore.impl.EPackageRegistryImpl");
    CDAPackage.eINSTANCE.eClass();
    HITSPPackage.eINSTANCE.eClass();
    CCDPackage.eINSTANCE.eClass();
    ConsolPackage.eINSTANCE.eClass();
    IHEPackage.eINSTANCE.eClass();
    stopWatch.stop();
    getLogger().debug("Loaded packages in {}", new Object[] { stopWatch.getDuration(TimeUnit.MILLISECONDS) });
    // Initialize JEXL
    jexl = new JexlBuilder().cache(1024).debug(false).silent(true).strict(false).create();
    jexlCtx = new MapContext();
    getLogger().debug("Loading mappings");
    // Load CDA mappings for parser
    loadMappings();
}
Also used : JexlBuilder(org.apache.commons.jexl3.JexlBuilder) MapContext(org.apache.commons.jexl3.MapContext) StopWatch(org.apache.nifi.util.StopWatch) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 9 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project nutch by apache.

the class JexlUtil method parseExpression.

/**
 * Parses the given expression to a JEXL expression. This supports
 * date parsing.
 *
 * @param expr string JEXL expression
 * @return parsed JEXL expression or null in case of parse error
 */
public static JexlScript parseExpression(String expr) {
    if (expr == null)
        return null;
    try {
        // Translate any date object into a long. Dates must be in the DATE_PATTERN
        // format. For example: 2016-03-20T00:00:00Z
        Matcher matcher = DATE_PATTERN.matcher(expr);
        if (matcher.find()) {
            String date = matcher.group();
            // parse the matched substring and get the epoch
            Date parsedDate = DateUtils.parseDateStrictly(date, new String[] { "yyyy-MM-dd'T'HH:mm:ss'Z'" });
            long time = parsedDate.getTime();
            // replace the original string date with the numeric value
            expr = expr.replace(date, Long.toString(time));
        }
        JexlEngine jexl = new JexlBuilder().silent(true).strict(true).create();
        return jexl.createScript(expr);
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
    return null;
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) Matcher(java.util.regex.Matcher) JexlBuilder(org.apache.commons.jexl3.JexlBuilder) Date(java.util.Date)

Aggregations

JexlBuilder (org.apache.commons.jexl3.JexlBuilder)9 JexlEngine (org.apache.commons.jexl3.JexlEngine)8 MapContext (org.apache.commons.jexl3.MapContext)4 JexlExpression (org.apache.commons.jexl3.JexlExpression)3 Test (org.junit.jupiter.api.Test)3 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 StopWatch (org.apache.nifi.util.StopWatch)1