Search in sources :

Example 1 with Expression

use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.

the class ScriptExecutorProcess method setParameters.

public void setParameters(final Map<String, String> parameters) {
    this.parameters = parameters;
    for (final Entry<String, String> param : parameters.entrySet()) {
        final String key = param.getKey();
        final String value = param.getValue();
        try {
            final Expression expression = JexlUtil.newExpression(value, "#\\{([^\\}]+)\\}");
            this.expressions.put(key, expression);
        } catch (final Exception e) {
            throw new IllegalArgumentException("Expression not valid " + key + "=" + value);
        }
    }
}
Also used : Expression(org.apache.commons.jexl.Expression) ClosedException(com.revolsys.parallel.channel.ClosedException) BeansException(org.springframework.beans.BeansException) ThreadInterruptedException(com.revolsys.parallel.ThreadInterruptedException)

Example 2 with Expression

use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.

the class Menu method addParameter.

public void addParameter(final String name, final Object value) {
    if (value != null) {
        this.parameters.put(name, value);
        Expression expression = null;
        try {
            expression = JexlUtil.newExpression(value.toString());
        } catch (final Exception e) {
            LOG.error("Invalid Jexl Expression '" + value + "': " + e.getMessage(), e);
        }
        if (expression != null) {
            this.dynamicParameters.put(name, expression);
            this.staticParameters.remove(name);
        } else {
            this.dynamicParameters.remove(name);
            this.staticParameters.put(name, value);
        }
    } else {
        removeParameter(name);
    }
}
Also used : Expression(org.apache.commons.jexl.Expression)

Example 3 with Expression

use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.

the class PhoneNumber method format.

/**
 * Parse a phone number using the regular expression and if it matches the
 * phone number, format it using the specified format otherwise return null.
 *
 * @param phoneNumber The normalized phone number to format.
 * @param regex The regular expression to match phone numbers.
 * @param format The format specification.
 * @return The formatted phone number.
 */
public static String format(final String phoneNumber, final String regex, final String format) {
    if (phoneNumber != null && regex != null && format != null) {
        final Pattern pattern = Pattern.compile(regex);
        final Matcher matcher = pattern.matcher(phoneNumber);
        if (matcher.matches()) {
            final Map values = new HashMap();
            for (int i = 1; i <= matcher.groupCount(); i++) {
                values.put("n" + i, matcher.group(i));
            }
            Expression expression;
            try {
                expression = JexlUtil.newExpression(format);
            } catch (final Exception e) {
                throw new IllegalArgumentException(regex + " is not a valid regular expression: " + e.getMessage());
            }
            final HashMapContext context = new HashMapContext();
            context.setVars(values);
            try {
                return (String) expression.evaluate(context);
            } catch (final Exception e) {
                throw new IllegalArgumentException(format + " is not a valid format: " + e.getMessage());
            }
        }
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Expression(org.apache.commons.jexl.Expression) HashMapContext(org.apache.commons.jexl.context.HashMapContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Expression

use of org.apache.commons.jexl.Expression in project com.revolsys.open by revolsys.

the class MenuItem method setUri.

public void setUri(final String uri) {
    if (uri != null) {
        Expression uriExpression = null;
        try {
            uriExpression = JexlUtil.newExpression(uri.replaceAll(" ", "%20"));
        } catch (final Exception e) {
            log.error(e.getMessage(), e);
        }
        if (uriExpression == null) {
            this.uri = uri.replaceAll(" ", "%20");
            this.uriExpression = null;
        } else {
            this.uri = null;
            this.uriExpression = uriExpression;
        }
    } else {
        this.uri = null;
        this.uriExpression = null;
    }
}
Also used : Expression(org.apache.commons.jexl.Expression)

Example 5 with Expression

use of org.apache.commons.jexl.Expression 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)

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