Search in sources :

Example 6 with Expression

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);
    }
}
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)

Example 7 with Expression

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) Expression(org.apache.commons.jexl.Expression) Iterator(java.util.Iterator) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Writer(java.io.Writer)

Example 8 with Expression

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

Example 9 with Expression

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

Example 10 with Expression

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

Aggregations

Expression (org.apache.commons.jexl.Expression)11 HashMapContext (org.apache.commons.jexl.context.HashMapContext)4 ThreadInterruptedException (com.revolsys.parallel.ThreadInterruptedException)2 ClosedException (com.revolsys.parallel.channel.ClosedException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 JexlContext (org.apache.commons.jexl.JexlContext)2 ThreadSharedProperties (com.revolsys.collection.map.ThreadSharedProperties)1 ScriptExecutorRunnable (com.revolsys.parallel.tools.ScriptExecutorRunnable)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Future (java.util.concurrent.Future)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1