use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class BSFEngineHandler method accepts.
/**
* Accepts.
* <p>If the engine doesn't have filter, the method will return true.</p>
* <p>If the method has a filter, it will be evaluated.</p>
*
* @param alarm the alarm
* @return true, if successful
*/
public boolean accepts(NorthboundAlarm alarm) {
if (getFilter() != null) {
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(m_filter);
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
} catch (Exception e) {
LOG.warn("accepts: can't evaluate expression {} for alarm {} because: {}", getFilter(), alarm.getUei(), e.getMessage());
}
LOG.debug("accepts: checking {} ? {}", m_filter, passed);
return passed;
}
return true;
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class VarbindMapping method evaluate.
/**
* Evaluates a SPEL expression based on a given northbound alarm
*
* @param expression the expression
* @param alarm the northbound alarm
* @return the string
*/
private String evaluate(String expression, NorthboundAlarm alarm) {
if (expression == null) {
return null;
}
try {
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(expression);
return (String) exp.getValue(context, String.class);
} catch (Exception e) {
LOG.warn("Can't evaluate expression {} for alarm {} because: {}", getValue(), alarm.getUei(), e.getMessage());
}
return null;
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class SyslogEventForwarder method getTranslatedMessage.
/**
* Gets the translated message.
*
* @param event the event
* @param node the node
* @param msgFormat the message format
* @return the translated message
*/
private String getTranslatedMessage(Event event, OnmsNode node, String msgFormat) {
StandardEvaluationContext context = new StandardEvaluationContext(event);
if (node != null) {
context.setVariable("node", node);
}
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(msgFormat, new TemplateParserContext("${", "}"));
try {
final String msg = (String) exp.getValue(context, String.class);
LOG.debug("getTranslatedMessage: {} ==> {}", msgFormat, msg);
return msg;
} catch (Exception e) {
LOG.warn("getTranslatedMessage: can't evaluate expression {} for alarm {} because: {}", msgFormat, event.getUei(), e.getMessage());
}
return null;
}
use of org.springframework.expression.ExpressionParser in project engine by craftercms.
the class ConfigAwareUrlAccessRestrictionCheckingProcessor method getUrlRestrictions.
@Override
@SuppressWarnings("unchecked")
protected Map<String, Expression> getUrlRestrictions() {
Callback<Map<String, Expression>> callback = new Callback<Map<String, Expression>>() {
@Override
public Map<String, Expression> execute() {
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
Map<String, Expression> customRestrictions = null;
if (config != null) {
List<HierarchicalConfiguration> restrictionsConfig = config.configurationsAt(URL_RESTRICTION_KEY);
if (CollectionUtils.isNotEmpty(restrictionsConfig)) {
customRestrictions = new LinkedHashMap<>(restrictionsConfig.size());
ExpressionParser parser = new SpelExpressionParser();
for (HierarchicalConfiguration restrictionConfig : restrictionsConfig) {
String url = restrictionConfig.getString(URL_RESTRICTION_URL_KEY);
String expression = restrictionConfig.getString(URL_RESTRICTION_EXPRESSION_KEY);
if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(expression)) {
try {
customRestrictions.put(url, parser.parseExpression(expression));
} catch (ParseException e) {
throw new ConfigurationException(expression + " is not a valid SpEL expression", e);
}
}
}
}
}
if (customRestrictions != null) {
return customRestrictions;
} else {
return urlRestrictions;
}
}
};
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
return cacheTemplate.getObject(siteContext.getContext(), callback, URL_RESTRICTIONS_CACHE_KEY);
} else {
return urlRestrictions;
}
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class DroolsEngine method accepts.
/**
* Accepts.
* <p>If the engine doesn't have filter, the method will return true.</p>
* <p>If the method has a filter, it will be evaluated.</p>
*
* @param alarm the alarm
* @return true, if successful
*/
public boolean accepts(NorthboundAlarm alarm) {
if (getFilter() != null) {
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(m_filter);
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
} catch (Exception e) {
LOG.warn("accepts: can't evaluate expression {} for alarm {} because: {}", getFilter(), alarm.getUei(), e.getMessage());
}
LOG.debug("accepts: checking {} ? {}", m_filter, passed);
return passed;
}
return true;
}
Aggregations