use of org.apache.commons.jexl3.JexlExpression in project syncope by apache.
the class JexlUtils method evaluate.
public static String evaluate(final String expression, final JexlContext jexlContext) {
String result = StringUtils.EMPTY;
if (StringUtils.isNotBlank(expression) && jexlContext != null) {
try {
JexlExpression jexlExpression = getEngine().createExpression(expression);
Object evaluated = jexlExpression.evaluate(jexlContext);
if (evaluated != null) {
result = evaluated.toString();
}
} catch (Exception e) {
LOG.error("Error while evaluating JEXL expression: " + expression, e);
}
} else {
LOG.debug("Expression not provided or invalid context");
}
return result;
}
use of org.apache.commons.jexl3.JexlExpression in project com.revolsys.open by revolsys.
the class ScriptTool method processArguments.
public boolean processArguments(final String[] args) {
try {
loadProperties("script.properties");
final CommandLineParser parser = new PosixParser();
this.commandLine = parser.parse(this.options, args);
final Option[] options = this.commandLine.getOptions();
for (final Option option : options) {
final String shortOpt = option.getOpt();
if (shortOpt != null && shortOpt.equals("D")) {
final Properties properties = this.commandLine.getOptionProperties("D");
for (final Entry<Object, Object> property : properties.entrySet()) {
final String key = (String) property.getKey();
final String value = (String) property.getValue();
this.parameters.put(key, value);
System.setProperty(key, value);
ThreadSharedProperties.setProperty(key, value);
}
}
}
if (this.commandLine.hasOption(SCRIPT_OPTION)) {
if (!setScriptFileName(this.commandLine.getOptionValue(SCRIPT_OPTION))) {
return false;
}
}
if (this.commandLine.hasOption(PROPERTIES_OPTION)) {
this.propertiesName = this.commandLine.getOptionValue(PROPERTIES_OPTION);
try {
final File propertiesFile = new File(this.propertiesName);
if (propertiesFile.exists()) {
final InputStream in = new FileInputStream(propertiesFile);
loadProperties(this.propertiesName, in);
} else {
if (!loadProperties(this.propertiesName)) {
System.err.println("Properties file '" + this.propertiesName + "' does not exist");
return false;
}
}
} catch (final IOException e) {
System.err.println("Properties file '" + this.propertiesName + "' could not be read:" + e.getMessage());
return false;
}
}
if (this.commandLine.hasOption(LOG_FILE_OPTION)) {
this.logFile = new File(this.commandLine.getOptionValue(LOG_FILE_OPTION));
final File logDirectory = this.logFile.getParentFile();
if (!logDirectory.exists()) {
if (!logDirectory.mkdirs()) {
System.err.println("Unable to create Log directory '" + logDirectory.getAbsolutePath() + "'");
return false;
}
}
} else {
String logFileName = System.getProperty("logFile");
if (logFileName != null) {
try {
while (logFileName.contains("${")) {
final JexlExpression expression = JexlUtil.newExpression(logFileName);
final MapContext context = new MapContext(ThreadSharedProperties.getProperties());
logFileName = (String) JexlUtil.evaluateExpression(context, expression);
}
} catch (final Exception e) {
e.printStackTrace();
logFileName = null;
}
}
}
if (this.logFile != null) {
if (this.logFile.exists() && !this.logFile.isFile()) {
System.err.println("Log file '" + this.logFile.getAbsolutePath() + "' is not a file");
return false;
}
System.setProperty("logFile", this.logFile.getAbsolutePath());
}
if (this.commandLine.hasOption(VERSION_OPTION)) {
displayVersion();
return false;
}
if (this.scriptFileName == null) {
final String[] extraArgs = this.commandLine.getArgs();
if (extraArgs.length > 0) {
if (!setScriptFileName(extraArgs[0])) {
return false;
}
}
}
return true;
} catch (final MissingOptionException e) {
if (this.commandLine.hasOption(VERSION_OPTION)) {
displayVersion();
} else {
System.err.println("Missing " + e.getMessage() + " argument");
}
return false;
} catch (final ParseException e) {
System.err.println("Unable to process command line arguments: " + e.getMessage());
return false;
}
}
use of org.apache.commons.jexl3.JexlExpression in project syncope by apache.
the class JexlUtils method evaluate.
public static String evaluate(final String expression, final JexlContext jexlContext) {
String result = StringUtils.EMPTY;
if (StringUtils.isNotBlank(expression) && jexlContext != null) {
try {
JexlExpression jexlExpression = getEngine().createExpression(expression);
Object evaluated = jexlExpression.evaluate(jexlContext);
if (evaluated != null) {
result = evaluated.toString();
}
} catch (Exception e) {
LOG.error("Error while evaluating JEXL expression: " + expression, e);
}
} else {
LOG.debug("Expression not provided or invalid context");
}
return result;
}
use of org.apache.commons.jexl3.JexlExpression 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 JexlExpression 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.jexl3.JexlExpression in project com.revolsys.open by revolsys.
the class MenuItem method setTitle.
public void setTitle(final String title) {
if (title != null) {
JexlExpression 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;
}
}
Aggregations