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