use of org.apache.commons.jexl.Expression 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);
}
}
use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.
the class JavaComponent method includeComponent.
@Override
public void includeComponent(final PageContext context) throws ServletException, IOException {
Object instance;
try {
instance = this.componentClass.newInstance();
} catch (final Exception e) {
throw new ServletException("Unable to create component instance", e);
}
try {
final Iterator propertyNames = this.properties.keySet().iterator();
while (propertyNames.hasNext()) {
final String propertyName = (String) propertyNames.next();
Object value = this.properties.get(propertyName);
final WebUiContext niceContext = WebUiContext.get();
try {
final Expression expression = JexlUtil.newExpression(value.toString());
if (expression != null) {
value = niceContext.evaluateExpression(expression);
}
} catch (final Exception e) {
throw new ServletException(e.getMessage(), e);
}
this.setPropertyMethod.invoke(instance, new Object[] { propertyName, value });
}
} catch (final IllegalAccessException e) {
log.error("Unable to set component properties", e.getCause());
throw new ServletException("Unable to set component properties", e);
} catch (final InvocationTargetException e) {
log.error("Unable to set component properties", e.getCause());
throw new ServletException("Unable to set component properties", e.getCause());
}
try {
final Writer out = context.getOut();
this.serializeMethod.invoke(instance, new Object[] { out });
} catch (final IllegalAccessException e) {
throw new ServletException("Unable to serialize component", e);
} catch (final InvocationTargetException e) {
final Throwable cause = e.getCause();
log.error(cause.getMessage(), cause);
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw new ServletException("Unable to serialize component", cause);
}
}
use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.
the class Menu method getLink.
public String getLink(final JexlContext context) {
String baseUri = this.uri;
if (this.uriExpression != null) {
if (context != null) {
baseUri = (String) JexlUtil.evaluateExpression(context, this.uriExpression);
} else {
baseUri = null;
}
}
if (baseUri == null) {
if (this.anchor != null) {
return "#" + this.anchor;
} else {
return null;
}
} else {
baseUri = HttpServletUtils.getAbsoluteUrl(PathAliasController.getPath(baseUri));
Map<String, Object> params;
if (context != null) {
params = new HashMap<>(this.staticParameters);
for (final Entry<String, Expression> param : this.dynamicParameters.entrySet()) {
final String key = param.getKey();
final Expression expression = param.getValue();
final Object value = JexlUtil.evaluateExpression(context, expression);
params.put(key, value);
}
} else {
params = this.staticParameters;
}
final String link = UrlUtil.getUrl(baseUri, params);
if (this.anchor == null) {
return link;
} else {
return link + "#" + this.anchor;
}
}
}
use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.
the class MenuItem method setTitle.
public void setTitle(final String title) {
if (title != null) {
Expression titleExpression = null;
try {
titleExpression = JexlUtil.newExpression(title);
} catch (final Exception e) {
log.error(e.getMessage(), e);
}
if (titleExpression == null) {
this.title = title;
this.titleExpression = null;
} else {
this.title = null;
this.titleExpression = titleExpression;
}
} else {
this.title = null;
this.titleExpression = null;
}
}
use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.
the class MenuItem method addParameter.
public void addParameter(final String name, final Object value) throws Exception {
if (value instanceof String) {
final String stringValue = (String) value;
final Expression expression = JexlUtil.newExpression(stringValue);
if (expression != null) {
this.parameters.put(name, expression);
} else {
this.staticParameters.put(name, value);
}
} else {
this.staticParameters.put(name, value);
}
}
Aggregations