Search in sources :

Example 1 with JexlContext

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;
}
Also used : Expression(org.apache.commons.jexl.Expression) HashMapContext(org.apache.commons.jexl.context.HashMapContext) JexlContext(org.apache.commons.jexl.JexlContext)

Example 2 with JexlContext

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;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) HashMapContext(org.apache.commons.jexl.context.HashMapContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JexlContext(org.apache.commons.jexl.JexlContext) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 3 with JexlContext

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);
    }
}
Also used : ClosedException(com.revolsys.parallel.channel.ClosedException) HashMap(java.util.HashMap) ThreadInterruptedException(com.revolsys.parallel.ThreadInterruptedException) HashMapContext(org.apache.commons.jexl.context.HashMapContext) Expression(org.apache.commons.jexl.Expression) JexlContext(org.apache.commons.jexl.JexlContext) Future(java.util.concurrent.Future) ScriptExecutorRunnable(com.revolsys.parallel.tools.ScriptExecutorRunnable)

Aggregations

JexlContext (org.apache.commons.jexl.JexlContext)3 HashMapContext (org.apache.commons.jexl.context.HashMapContext)3 HashMap (java.util.HashMap)2 Expression (org.apache.commons.jexl.Expression)2 Geometry (com.revolsys.geometry.model.Geometry)1 ThreadInterruptedException (com.revolsys.parallel.ThreadInterruptedException)1 ClosedException (com.revolsys.parallel.channel.ClosedException)1 ScriptExecutorRunnable (com.revolsys.parallel.tools.ScriptExecutorRunnable)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 Record (com.revolsys.record.Record)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1 LinkedHashMap (java.util.LinkedHashMap)1 Future (java.util.concurrent.Future)1