use of org.apache.commons.jexl.JexlContext in project com.revolsys.open by revolsys.
the class HtmlUiBuilder method getMessage.
public String getMessage(final String messageName, final Map<String, Object> variables) {
final String message = getMessage(messageName);
if (message != null) {
try {
final Expression expression = JexlUtil.newExpression(message);
if (expression != null) {
final JexlContext context = new HashMapContext();
context.setVars(variables);
return (String) expression.evaluate(context);
}
} catch (final Throwable e) {
this.log.error(e.getMessage(), e);
}
}
return message;
}
use of org.apache.commons.jexl.JexlContext in project com.revolsys.open by revolsys.
the class CreateObjectsWithinDistanceOfGeometry method getRecordDefinitionGeometries.
private final Map<RecordDefinition, Geometry> getRecordDefinitionGeometries(final RecordDefinition recordDefinition) {
Map<RecordDefinition, Geometry> recordDefinitionGeometries = this.recordDefinitionGeometryMap.get(recordDefinition);
if (recordDefinitionGeometries == null) {
recordDefinitionGeometries = new LinkedHashMap<>();
RecordDefinition newRecordDefinition;
Geometry preparedGeometry;
for (final Record record : this.geometryObjects) {
Geometry geometry = record.getGeometry();
if (geometry != null) {
final JexlContext context = new HashMapContext();
final Map<String, Object> vars = new HashMap<>(this.attributes);
vars.putAll(record);
vars.put("typePath", recordDefinition.getPath());
context.setVars(vars);
final String typePath = (String) JexlUtil.evaluateExpression(context, this.typePathTemplateExpression);
newRecordDefinition = new RecordDefinitionImpl(PathName.newPathName(typePath), recordDefinition.getFields());
if (this.distance > 0) {
geometry = geometry.buffer(this.distance, 1, LineCap.SQUARE, LineJoin.MITER, 1.0D);
}
geometry = DouglasPeuckerSimplifier.simplify(geometry, 2D);
preparedGeometry = geometry.prepare();
recordDefinitionGeometries.put(newRecordDefinition, preparedGeometry);
}
}
this.recordDefinitionGeometryMap.put(recordDefinition, recordDefinitionGeometries);
}
return recordDefinitionGeometries;
}
use of org.apache.commons.jexl.JexlContext in project com.revolsys.open by revolsys.
the class ScriptExecutorProcess method executeScript.
private void executeScript(final Record record) {
try {
final JexlContext context = new HashMapContext();
final Map<String, Object> vars = new HashMap<>(this.attributes);
vars.putAll(record);
context.setVars(vars);
final Map<String, Object> scriptParams = new HashMap<>();
scriptParams.putAll(this.attributes);
for (final Entry<String, Expression> param : this.expressions.entrySet()) {
final String key = param.getKey();
final Expression expression = param.getValue();
final Object value = JexlUtil.evaluateExpression(context, expression);
scriptParams.put(key, value);
}
final ScriptExecutorRunnable scriptRunner = new ScriptExecutorRunnable(this.script, scriptParams);
if (this.executor == null) {
scriptRunner.run();
} else {
while (this.tasks.size() >= this.maxConcurrentScripts) {
try {
synchronized (this) {
ThreadUtil.pause(1000);
for (final Iterator<Future<?>> taskIter = this.tasks.iterator(); taskIter.hasNext(); ) {
final Future<?> task = taskIter.next();
if (task.isDone()) {
taskIter.remove();
}
}
}
} catch (final ThreadInterruptedException e) {
throw new ClosedException(e);
}
}
final Future<?> future = this.executor.submit(scriptRunner);
this.tasks.add(future);
}
} catch (final ThreadDeath e) {
throw e;
} catch (final Throwable t) {
Logs.error(this, t);
}
}
Aggregations