org.apache.commons.jexl2.JexlEngine Java Examples
The following examples show how to use
org.apache.commons.jexl2.JexlEngine.
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: EdgePreconditionJexlContext.java From datawave with Apache License 2.0 | 6 votes |
private HashSet<String> createFilterKeysFromEdgeDefinitions(List<EdgeDefinition> edges) { long start = System.currentTimeMillis(); JexlEngine engine = new JexlEngine(); Script script; HashSet<String> filterFields = new HashSet<>(); for (EdgeDefinition edgeDef : edges) { if (edgeDef.hasJexlPrecondition()) { script = engine.createScript(edgeDef.getJexlPrecondition()); filterFields.addAll(extractTermsFromJexlScript(script)); } } if (log.isTraceEnabled()) { log.trace("Time to create filtered keys from edge definitions: " + (System.currentTimeMillis() - start) + "ms."); } return filterFields; }
Example #2
Source File: ClusterManager.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Evaluate a JEXL expression. * @param expr expression * @param ctx context for the expression * @return evaluation result */ public Object evalExpression(String expr, Map<String, Object> ctx) { JexlEngine jexl = new JexlEngine(); // Create an expression Expression jexlExpr = jexl.createExpression(expr); // Create a context and add data JexlContext jc = new MapContext(ctx); try { return jexlExpr.evaluate(jc); } catch (JexlException e) { LOG.error("Error evaluating expression: " + expr, e); throw new RuntimeException(e); } }
Example #3
Source File: JexlTest.java From data-mediator with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // Create or retrieve an engine JexlEngine jexl = new JexlEngine(); // Create an expression String jexlExp = "Convertor.convert(foo.bar())"; //wrong Expression e = jexl.createExpression(jexlExp); // Create a context and add data JexlContext jc = new MapContext(); jc.set("foo", new Foo()); jc.set("Convertor","com.heaven7.java.data.mediator.test.jexl.Convertor"); // Now evaluate the expression, getting the result Object o = e.evaluate(jc); System.out.println(0); }
Example #4
Source File: PartitionExpression.java From kite with Apache License 2.0 | 5 votes |
public PartitionExpression(String expression, boolean isStrict) { this.engine = new JexlEngine(); Map<String, Object> fns = new HashMap<String, Object>(); fns.put(null, PartitionFunctions.class); this.engine.setFunctions(fns); this.engine.setStrict(true); this.engine.setSilent(false); this.engine.setCache(10); this.expression = engine.createExpression(expression); this.isStrict = isStrict; }
Example #5
Source File: JexlExpression.java From scriptella-etl with Apache License 2.0 | 5 votes |
/** * Creates a preconfigured JexlEngine. * <p>The instance is configured to use function namespaces from {@link scriptella.core.EtlVariable}. * * @return instance of JexlEngine. */ public static JexlEngine newJexlEngine() { JexlEngine je = new JexlEngine(); Map<String, Object> fMap = new HashMap<String, Object>(); EtlVariable etl = new EtlVariable(); fMap.put("date", etl.getDate()); fMap.put("text", etl.getText()); fMap.put("class", etl.getClazz()); je.setFunctions(fMap); return je; }
Example #6
Source File: BaseWriteUtil.java From excel-rw-annotation with Apache License 2.0 | 5 votes |
/** * 条件执行器 * * @param exp * @param args * @return */ private static boolean convertToCode(String exp, Map<String, Object> args) { JexlEngine engine = new JexlEngine(); Expression expression = engine.createExpression(exp); JexlContext context = new MapContext(); args.forEach(context::set); return (boolean) expression.evaluate(context); }
Example #7
Source File: EdgePreconditionCacheHelper.java From datawave with Apache License 2.0 | 4 votes |
public JexlEngine getEngine() { return engine; }
Example #8
Source File: EdgePreconditionCacheHelper.java From datawave with Apache License 2.0 | 4 votes |
private void createEngine() { this.setEngine(new JexlEngine(null, new MultiMapArithmetic(false), null, null)); this.getEngine().setDebug(false); // Turn off debugging to make things go faster this.getEngine().setCache(50); // Set cache size lower than default value of 512 }
Example #9
Source File: ContactSelectorView.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
public void keyReleased(KeyEvent ke){ String txt = text.getText(); // We have a formula, if the string starts with "=" if (txt.startsWith("=")) { String formula; if (txt.contains(";")) { formula = txt.substring(1, txt.indexOf(";")); Map<String, Object> functions = new HashMap<>(); functions.put("math", Math.class); JexlEngine jexl = new JexlEngine(); jexl.setLenient(false); jexl.setFunctions(functions); try { Expression expr = jexl.createExpression(formula); Object result = expr.evaluate(new MapContext()); text.setText(""); text.setMessage(formula + "=" + result + ""); result = null; } catch (JexlException e) { text.setText(""); text.setMessage("Invalid expression: " + formula); } } return; } if (txt.length() > 1) { filterPositionTitle.setSearchText(txt); viewer.getControl().setRedraw(false); viewer.refresh(); viewer.getControl().setRedraw(true); } else { filterPositionTitle.setSearchText(null); viewer.getControl().setRedraw(false); viewer.refresh(); viewer.getControl().setRedraw(true); } }
Example #10
Source File: ExpressionLanguageJEXLImpl.java From super-csv-annotation with Apache License 2.0 | 4 votes |
public ExpressionLanguageJEXLImpl() { this(new JexlEngine()); }
Example #11
Source File: ExpressionLanguageJEXLImpl.java From xlsmapper with Apache License 2.0 | 4 votes |
public ExpressionLanguageJEXLImpl() { this(new JexlEngine()); this.jexlEngine.setLenient(true); this.jexlEngine.setSilent(true); }
Example #12
Source File: QueryJexl.java From datawave with Apache License 2.0 | 4 votes |
NormalizedExpression(JexlEngine engine, String query, ASTJexlScript script) { super(engine, query, script); }
Example #13
Source File: EdgePreconditionCacheHelper.java From datawave with Apache License 2.0 | 4 votes |
public void setEngine(JexlEngine engine) { this.engine = engine; }
Example #14
Source File: DatawaveInterpreter.java From datawave with Apache License 2.0 | 4 votes |
public DatawaveInterpreter(JexlEngine jexl, JexlContext aContext, boolean strictFlag, boolean silentFlag) { super(jexl, aContext, strictFlag, silentFlag); resultMap = Maps.newHashMap(); }
Example #15
Source File: ExpressionEvaluatorImpl.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
public ExpressionEvaluatorImpl(@NonNull JexlEngine jexl) { this.jexl = jexl; }
Example #16
Source File: AppModule.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Provides @Singleton RuleExpressionEvaluator ruleExpressionEvaluator(@NonNull JexlEngine jexlEngine) { return new ExpressionEvaluatorImpl(jexlEngine); }
Example #17
Source File: AppModule.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Provides @Singleton JexlEngine jexlEngine() { return new JexlEngine(); }
Example #18
Source File: ExpressionUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * @param expression the expression. * @param vars the variables, can be null. * @param strict indicates whether to use strict or lenient engine mode. * @return the result of the evaluation. */ private static Object evaluate( String expression, Map<String, Object> vars, boolean strict ) { expression = expression.replaceAll( IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY ); JexlEngine engine = strict ? JEXL_STRICT : JEXL; Expression exp = engine.createExpression( expression ); JexlContext context = vars != null ? new MapContext( vars ) : new MapContext(); return exp.evaluate( context ); }
Example #19
Source File: ExpressionUtils.java From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * @param expression the expression. * @param vars the variables, can be null. * @param strict indicates whether to use strict or lenient engine mode. * @return the result of the evaluation. */ private static Object evaluate(String expression, Map<String, Object> vars, boolean strict) { String formattedExpression = expression.replaceAll(IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY); JexlEngine engine = strict ? JEXL_STRICT : JEXL; Expression exp = engine.createExpression(formattedExpression); JexlContext context = vars == null ? new MapContext() : new MapContext(vars); return exp.evaluate(context); }
Example #20
Source File: ExpressionLanguageJEXLImpl.java From xlsmapper with Apache License 2.0 | 2 votes |
/** * {@link JexlEngine}を指定するコンストラクタ。 * @param jexlEngine JEXLの処理エンジン。 */ public ExpressionLanguageJEXLImpl(final JexlEngine jexlEngine) { this.jexlEngine = jexlEngine; }
Example #21
Source File: ExpressionLanguageJEXLImpl.java From xlsmapper with Apache License 2.0 | 2 votes |
/** * {@link JexlEngine}を取得する。 * @return */ public JexlEngine getJexlEngine() { return jexlEngine; }
Example #22
Source File: ExpressionLanguageJEXLImpl.java From super-csv-annotation with Apache License 2.0 | 2 votes |
/** * {@link JexlEngine}を指定するコンストラクタ。 * @param jexlEngine JEXLの処理エンジン。 */ public ExpressionLanguageJEXLImpl(final JexlEngine jexlEngine) { this.jexlEngine = jexlEngine; }
Example #23
Source File: ExpressionLanguageJEXLImpl.java From super-csv-annotation with Apache License 2.0 | 2 votes |
/** * {@link JexlEngine}を取得する。 * @return */ public JexlEngine getJexlEngine() { return jexlEngine; }