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));
}
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);
}
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();
}
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;
}
Aggregations