use of org.springframework.expression.common.TemplateParserContext in project camel by apache.
the class SpelExpression method parseExpression.
private Expression parseExpression() {
// Support template parsing with #{ } delimiters
ParserContext parserContext = new TemplateParserContext();
Expression expression = expressionParser.parseExpression(expressionString, parserContext);
return expression;
}
use of org.springframework.expression.common.TemplateParserContext 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.common.TemplateParserContext in project spring-framework by spring-projects.
the class TemplateExpressionParsingTests method testTemplateParserContext.
@Test
public void testTemplateParserContext() {
TemplateParserContext tpc = new TemplateParserContext("abc", "def");
assertEquals("abc", tpc.getExpressionPrefix());
assertEquals("def", tpc.getExpressionSuffix());
assertTrue(tpc.isTemplate());
tpc = new TemplateParserContext();
assertEquals("#{", tpc.getExpressionPrefix());
assertEquals("}", tpc.getExpressionSuffix());
assertTrue(tpc.isTemplate());
ParserContext pc = ParserContext.TEMPLATE_EXPRESSION;
assertEquals("#{", pc.getExpressionPrefix());
assertEquals("}", pc.getExpressionSuffix());
assertTrue(pc.isTemplate());
}
Aggregations