Questions tagged [jexl]

JEXL is a library intended to facilitate the implementation of dynamic and scripting features in applications and frameworks written in Java.

JEXL is a library intended to facilitate the implementation of dynamic and scripting features in applications and frameworks written in Java.

From the official documentation:

JEXL implements an Expression Language based on some extensions to the JSTL Expression Language supporting most of the constructs seen in shell-script or ECMAScript. Its goal is to expose scripting features usable by technical operatives or consultants working with enterprise platforms.

The library exposes a small footprint API - the core features fit in 3 classes and 10 methods - that can be used in various conditions:

  • Scripting features:
    • Your application lets (advanced) users evaluate or define some simple expressions like computation formulas.
  • Module or component configuration:
    • Your application has configuration files (eventually generated by a design module) consumed by the end-user module that would benefit from variables and expressions.
    • When it would be convenient to use IOC but overall complexity doesn't require (or can't depend upon) a full-blown library (Spring, Guice...).
  • Loose-coupling of interfaces and implementations or duck-typing:
    • You have optional classes that your code cant consider as compilation dependencies.
    • You have to integrate and call "legacy" code or use components that you don't want to strongly depend upon.
  • Simple template capabilities:
    • Your application has basic template requirements and JSPs or Velocity would be overkill or too inconvenient to deploy.

JEXL name stands for Java EXpression Language, a simple expression language originally inspired by Apache Velocity and the Expression Language defined in the JavaServer Pages Standard Tag Library version 1.1 (JSTL) and JavaServer Pages version 2.0 (JSP). JEXL 2.0 added features inspired by Unified EL. The syntax is now close to a mix of ECMAScript and "shell-script" making it easy to master by technical operatives or consultants. The objects exposed and their behavior obviously need to be documented though...

The API and the expression language exploit Java-beans naming patterns through introspection to expose property getters and setters. It also considers public class fields as properties and allows to invoke any accessible method.

JEXL attempts to bring some of the lessons learned by the Velocity community about expression languages in templating to a wider audience. Commons Jelly needed Velocity-ish method access, it just had to have it.

It must be noted that JEXL is not a compatible implementation of EL as defined in JSTL 1.1 (JSR-052) or JSP 2.0 (JSR-152). For a compatible implementation of these specifications, see the Commons EL project.

79 questions
10
votes
1 answer

Looking for JEXL Filter feature

I know, I can do several things in JEXL, but unable to find Filter feature in it, which is indeed very useful. How can I do something like var x=[{a:11,b=5},{a:1,b=15},{a:12,b=25},{a:4,b=35},{a:7,b=45}]; return x[.a>10].b; // Which filters to…
Pratik
  • 908
  • 2
  • 11
  • 34
7
votes
1 answer

How to evaluate user expressions in a sandbox

I want my app to evaluate an expression from an untrusted user, that I'll be reading from a JSON file. Such as: value = "(getTime() == 60) AND isFoo('bar')" I've found many threads about this here on StackOverflow. Usually recommending using Java's…
VIBrunazo
  • 1,340
  • 14
  • 21
6
votes
1 answer

How do you create a secure JEXL (scripting) sandbox?

I'm creating a sandbox for JEXL scripts to execute in so that a malicious user can't access data outside the variables we give them access to and also can't perform a DOS attack on the server. I'd like to document this for anybody else also doing…
Sarel Botha
  • 12,419
  • 7
  • 54
  • 59
4
votes
1 answer

How to connect two numeric string in jexl?

For example: @Test public void test2() { JexlEngine jexl = new JexlEngine(); jexl.setLenient(false); jexl.setSilent(false); JexlContext jc = new MapContext(); Expression exp = jexl.createExpression("\"1\"+\"1\""); …
JacobDu
  • 43
  • 4
4
votes
2 answers

Setting JXL custom Font

How to add custom fonts in JXL? Apart from the one's available by default? public static final FontName ARIAL = new FontName("Arial"); public static final FontName TIMES = new FontName("Times New Roman"); public static final FontName COURIER = new…
varunrao321
  • 925
  • 2
  • 10
  • 18
4
votes
4 answers

Does anyone have any simple JEXL examples using a loop. I am looking to iterate around a simple Array to output various string values?

Does anyone have any simple JEXL examples using a loop. I am looking to iterate around a simple object arraylist to output various string values?
user1816880
  • 49
  • 1
  • 1
  • 2
3
votes
2 answers

Why jexl calc arithmetic wrong

I use JEXL library to compute math expression with different arguments (for example y=2x+a^2-4*a*x where (x=1&a=3), (x=5&a=-15), etc). It works good on simple expressions, but when I start to use more hard expressions - it doesn't work. Here is code…
Dmitry Belaventsev
  • 6,347
  • 12
  • 52
  • 75
3
votes
1 answer

Line break in JEXL String

I'm using JEXL in Java in standard way: var script = new JexlBuilder().create().createScript(jexlScript); var jexlContext = new MapContext(); var returnString = (String) script.execute(jexlContext)); Let's say that jexScript looks like: var paramA…
cackoa
  • 113
  • 1
  • 6
3
votes
1 answer

Can you define functions in a JEXL Script?

A JEXL Script is not the same as a JEXL Expression. I see references to functions in the source code, but I see no documentation about it. Has it maybe not been implemented yet? There is a JSR-223 interface for it.
Sarel Botha
  • 12,419
  • 7
  • 54
  • 59
2
votes
1 answer

JEXL – Get current date and time

I have to use JEXL expression and I need to get current year and month using JEXL. Is it possible?
2
votes
1 answer

JEXL : How to parse a recursive expression

Having a JEXL expression, How can I parse it in order to dynamically add to JEXL context all the involved variables? Example : Initial Expression: Initial Expression = $VAR1 + $VAR2 VAR1 and VAR2 are other expressions $VAR1 = 123 + 45 $VAR2 = 67 +…
Osy
  • 1,613
  • 5
  • 21
  • 35
2
votes
3 answers

How to call a static method of a java class without creating an instance of that class in JEXL?

I want to invoke the static method of a class without putting any object in the context of JEXL. For instance methods, we put an object to the MapContext and use the key to call the method. but In my case, I don't have anything in context.…
Waqar Babar
  • 109
  • 1
  • 7
2
votes
2 answers

Operator overloading/definition for custom classes in Jexl3

I am trying to implement a custom class that should behave like Boolean in Jexl expressions: Example: Object result = jexl.createExpression("a || b").evaluate(context) Where aand b are instances of a custom class that contains an boolean and extra…
JMax
  • 1,134
  • 1
  • 11
  • 20
2
votes
1 answer

JMeter - Difference between jexl2 and jexl3

What is jexl and why is it faster performing than JavaScript in JMeter? ${__jexl3("${checkResponse}" != "")} this code just runs fine in a while controller of Jmeter while the same is not true with "${checkResponse}" != "" or "${checkResponse}" !=…
2
votes
0 answers

NodeJS script and high memory usage while processing mongodb documents with jexl

i've created a nodejs script for processing a mongodb collection of products. Each product needs to be processed with jexl, an expression language. The final result should be a text file with all product data. The script works but i need some help…
Xaptor
  • 25
  • 2
1
2 3 4 5 6