diff options
author | Anton Tananaev <anton@traccar.org> | 2023-01-29 09:33:16 -0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-01-29 09:33:16 -0800 |
commit | f4f1b05f8d5211476ae073d8a3c2dbd10cbcbe8a (patch) | |
tree | 7b8bc4f17f69403809fc7a5812ac5d534be1a482 /src/main | |
parent | 7df40dd7e6068c09e84080c6d47b577e51426e70 (diff) | |
download | trackermap-server-f4f1b05f8d5211476ae073d8a3c2dbd10cbcbe8a.tar.gz trackermap-server-f4f1b05f8d5211476ae073d8a3c2dbd10cbcbe8a.tar.bz2 trackermap-server-f4f1b05f8d5211476ae073d8a3c2dbd10cbcbe8a.zip |
Upgrade JXLS library
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/handler/ComputedAttributesHandler.java | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index 620852502..ca6c0fc74 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -26,9 +26,10 @@ import java.util.Map; import java.util.Set; import io.netty.channel.ChannelHandler; -import org.apache.commons.jexl2.JexlEngine; -import org.apache.commons.jexl2.JexlException; -import org.apache.commons.jexl2.MapContext; +import org.apache.commons.jexl3.JexlBuilder; +import org.apache.commons.jexl3.JexlEngine; +import org.apache.commons.jexl3.JexlException; +import org.apache.commons.jexl3.MapContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.BaseDataHandler; @@ -57,9 +58,10 @@ public class ComputedAttributesHandler extends BaseDataHandler { @Inject public ComputedAttributesHandler(Config config, CacheManager cacheManager) { this.cacheManager = cacheManager; - engine = new JexlEngine(); - engine.setStrict(true); - engine.setFunctions(Collections.singletonMap("math", Math.class)); + engine = new JexlBuilder() + .strict(true) + .namespaces(Collections.singletonMap("math", Math.class)) + .create(); includeDeviceAttributes = config.getBoolean(Keys.PROCESSING_COMPUTED_ATTRIBUTES_DEVICE_ATTRIBUTES); } @@ -68,13 +70,13 @@ public class ComputedAttributesHandler extends BaseDataHandler { if (includeDeviceAttributes) { Device device = cacheManager.getObject(Device.class, position.getDeviceId()); if (device != null) { - for (Object key : device.getAttributes().keySet()) { - result.set((String) key, device.getAttributes().get(key)); + for (String key : device.getAttributes().keySet()) { + result.set(key, device.getAttributes().get(key)); } } } Set<Method> methods = new HashSet<>(Arrays.asList(position.getClass().getMethods())); - methods.removeAll(Arrays.asList(Object.class.getMethods())); + Arrays.asList(Object.class.getMethods()).forEach(methods::remove); for (Method method : methods) { if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) { String name = Character.toLowerCase(method.getName().charAt(3)) + method.getName().substring(4); @@ -83,8 +85,8 @@ public class ComputedAttributesHandler extends BaseDataHandler { if (!method.getReturnType().equals(Map.class)) { result.set(name, method.invoke(position)); } else { - for (Object key : ((Map) method.invoke(position)).keySet()) { - result.set((String) key, ((Map) method.invoke(position)).get(key)); + for (Object key : ((Map<?, ?>) method.invoke(position)).keySet()) { + result.set((String) key, ((Map<?, ?>) method.invoke(position)).get(key)); } } } catch (IllegalAccessException | InvocationTargetException error) { |