aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/config/Keys.java8
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java7
2 files changed, 8 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 6aa41f85b..d3bba9ae7 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -1299,21 +1299,21 @@ public final class Keys {
public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES = new BooleanConfigKey(
"processing.computedAttributes.deviceAttributes",
List.of(KeyType.CONFIG));
-
+
/**
* Enable local variables declaration.
*/
public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES = new BooleanConfigKey(
"processing.computedAttributes.localVariables",
List.of(KeyType.CONFIG));
-
+
/**
* Enable loops processing.
*/
public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_LOOPS = new BooleanConfigKey(
"processing.computedAttributes.loops",
List.of(KeyType.CONFIG));
-
+
/**
* Enable new instances creation.
* When disabled, parsing a script/expression using 'new(...)' will throw a parsing exception;
@@ -1321,7 +1321,7 @@ public final class Keys {
public static final ConfigKey<Boolean> PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION = new BooleanConfigKey(
"processing.computedAttributes.newInstanceCreation",
List.of(KeyType.CONFIG));
-
+
/**
* Boolean flag to enable or disable reverse geocoder.
*/
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
index 73b549195..2964d81d7 100644
--- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
@@ -55,6 +55,8 @@ public class ComputedAttributesHandler extends BaseDataHandler {
private final JexlEngine engine;
+ private final JexlFeatures features;
+
private final boolean includeDeviceAttributes;
@Inject
@@ -62,7 +64,7 @@ public class ComputedAttributesHandler extends BaseDataHandler {
this.cacheManager = cacheManager;
JexlSandbox sandbox = new JexlSandbox(false);
sandbox.allow("com.safe.Functions");
- JexlFeatures features = new JexlFeatures()
+ features = new JexlFeatures()
.localVar(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOCAL_VARIABLES))
.loops(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_LOOPS))
.newInstance(config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_NEW_INSTANCE_CREATION))
@@ -71,7 +73,6 @@ public class ComputedAttributesHandler extends BaseDataHandler {
.strict(true)
.namespaces(Collections.singletonMap("math", Math.class))
.sandbox(sandbox)
- .features(features)
.create();
includeDeviceAttributes = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES);
}
@@ -113,7 +114,7 @@ public class ComputedAttributesHandler extends BaseDataHandler {
*/
@Deprecated
public Object computeAttribute(Attribute attribute, Position position) throws JexlException {
- return engine.createExpression(attribute.getExpression()).evaluate(prepareContext(position));
+ return engine.createScript(features, engine.createInfo(), attribute.getExpression()).execute(prepareContext(position));
}
@Override