String prefix = context.getExpressionPrefix(); String suffix = context.getExpressionSuffix(); int startIdx = 0;
@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()); }
/** * Returns true if the value contains an EL expression. * * @param value The value to check. * @return True if the value contains an EL expression. */ protected boolean hasExpression(String value) { return value != null && value.contains(templateContext.getExpressionPrefix()); } }
@Override public Expression parseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { if (context != null && context.isTemplate()) { return parseTemplate(expressionString, context); } else { return doParseExpression(expressionString, context); } }
private boolean isExpression(Object obj) { return (obj instanceof String && obj.toString().contains(parserContext.getExpressionPrefix())); }
@Override public Expression parseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { if (context != null && context.isTemplate()) { return parseTemplate(expressionString, context); } else { return doParseExpression(expressionString, context); } }
String prefix = context.getExpressionPrefix(); String suffix = context.getExpressionSuffix(); int startIdx = 0;
private boolean isExpression(Object obj) { return (obj instanceof String && obj.toString().contains(parserContext.getExpressionPrefix())); }
@Override public Expression parseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { if (context != null && context.isTemplate()) { return parseTemplate(expressionString, context); } else { return doParseExpression(expressionString, context); } }
/** * Set the topic to which to send any result from the method invocation. * May be a SpEL expression {@code !{...}} evaluated at runtime. * @param replyTopicParam the topic or expression. * @since 2.0 */ public void setReplyTopic(String replyTopicParam) { String replyTopic = replyTopicParam; if (!StringUtils.hasText(replyTopic)) { replyTopic = PARSER_CONTEXT.getExpressionPrefix() + "source.headers['" + KafkaHeaders.REPLY_TOPIC + "']" + PARSER_CONTEXT.getExpressionSuffix(); } if (replyTopic.contains(PARSER_CONTEXT.getExpressionPrefix())) { this.replyTopicExpression = PARSER.parseExpression(replyTopic, PARSER_CONTEXT); } else { this.replyTopicExpression = new LiteralExpression(replyTopic); } }
/** * @param o represents an object to convert to json * @return json representation of the said object */ static String toJson(Object o) { try { String converted = mapper.writeValueAsString(o); if (converted!= null && converted.contains(parserContext.getExpressionPrefix())) { throw new SpelHelperFunctionException("result for toJson cannot contain an expression"); } return converted; } catch (Exception e) { throw new SpelHelperFunctionException(String.format("#toJson(%s) failed", o.toString()), e); } }
private boolean isExpression(String val) { return val != null && val.contains(PARSER_CONTEXT.getExpressionPrefix()) && val.contains(PARSER_CONTEXT.getExpressionSuffix()); } }
/** * Set the default replyTo address to use when sending response messages. * This is only used if the replyTo from the received message is null. * <p> * Response destinations are only relevant for listener methods * that return result objects, which will be wrapped in * a response message and sent to a response destination. * <p> * It can be a string surrounded by "!{...}" in which case the expression is * evaluated at runtime; see the reference manual for more information. * @param defaultReplyTo The exchange. * @since 1.6 */ public void setResponseAddress(String defaultReplyTo) { if (defaultReplyTo.startsWith(PARSER_CONTEXT.getExpressionPrefix())) { this.responseExpression = PARSER.parseExpression(defaultReplyTo, PARSER_CONTEXT); } else { this.responseAddress = new Address(defaultReplyTo); } }
private boolean isExpression(String val) { return val != null && val.contains(PARSER_CONTEXT.getExpressionPrefix()) && val.contains(PARSER_CONTEXT.getExpressionSuffix()); } }
/** * Set the default replyTo address to use when sending response messages. * This is only used if the replyTo from the received message is null. * <p> * Response destinations are only relevant for listener methods * that return result objects, which will be wrapped in * a response message and sent to a response destination. * <p> * It can be a string surrounded by "!{...}" in which case the expression is * evaluated at runtime; see the reference manual for more information. * @param defaultReplyTo The exchange. * @since 1.6 */ public void setResponseAddress(String defaultReplyTo) { if (defaultReplyTo.startsWith(PARSER_CONTEXT.getExpressionPrefix())) { this.responseExpression = PARSER.parseExpression(defaultReplyTo, PARSER_CONTEXT); } else { this.responseAddress = new Address(defaultReplyTo); } }
String prefix = context.getExpressionPrefix(); String suffix = context.getExpressionSuffix(); int startIdx = 0;
@Override public String process(String value, PortletRequest request) { Map<String, Object> context = getContext(request); StandardEvaluationContext sec = new StandardEvaluationContext(context); sec.addPropertyAccessor(new MapAccessor()); sec.addPropertyAccessor(new ReflectivePropertyAccessor()); sec.addPropertyAccessor(new DefaultPropertyAccessor( PARSER_CONTEXT.getExpressionPrefix(), PARSER_CONTEXT.getExpressionSuffix())); if (beanResolver != null) { sec.setBeanResolver(beanResolver); } SpelExpressionParser parser = new SpelExpressionParser(); try { String processed = parser .parseExpression(value, PARSER_CONTEXT) .getValue(sec, String.class); return processed; } catch (SpelEvaluationException e) { throw new EvaluationException("Failed to process string '" + value + "'. See nested error message and check your SpEL tokens in your string", e); } }