From 821382582b5e3c55042accfabcd3bbbcedf3df5e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 8 Jul 2016 18:34:55 +0200 Subject: [PATCH] juplo:variables accepts expressions as arguments juplo.variables now also accepts an expression as argument. If the parameter can not be parsed as an expression, it is handeld as before (i.e. parsed as JSON, if possible, tried to be reolved, if not). If the expression evaluates to an empty string, the parameter is ignored. --- .../ImportVariablesAttrProcessor.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/de/juplo/thymeleaf/ImportVariablesAttrProcessor.java b/src/main/java/de/juplo/thymeleaf/ImportVariablesAttrProcessor.java index e864ab1..aac37a6 100644 --- a/src/main/java/de/juplo/thymeleaf/ImportVariablesAttrProcessor.java +++ b/src/main/java/de/juplo/thymeleaf/ImportVariablesAttrProcessor.java @@ -22,9 +22,13 @@ import org.thymeleaf.context.IContext; import org.thymeleaf.context.VariablesMap; import org.thymeleaf.dom.Element; import org.thymeleaf.dom.Node; +import org.thymeleaf.exceptions.TemplateProcessingException; import org.thymeleaf.processor.ProcessorResult; import org.thymeleaf.processor.attr.AbstractAttrProcessor; import org.thymeleaf.resourceresolver.IResourceResolver; +import org.thymeleaf.standard.expression.IStandardExpression; +import org.thymeleaf.standard.expression.IStandardExpressionParser; +import org.thymeleaf.standard.expression.StandardExpressions; import org.thymeleaf.templateresolver.ITemplateResolver; import org.thymeleaf.templateresolver.TemplateResolution; @@ -65,7 +69,25 @@ public class ImportVariablesAttrProcessor extends AbstractAttrProcessor ) { Configuration config = arguments.getConfiguration(); + + Configuration configuration = arguments.getConfiguration(); + String parameter = element.getAttributeValue(name); + try + { + IStandardExpressionParser parser = + StandardExpressions.getExpressionParser(configuration); + IStandardExpression expression = + parser.parseExpression(configuration, arguments, parameter); + parameter = (String)expression.execute(configuration, arguments); + } + catch (TemplateProcessingException e) { } + + if (parameter != null && !parameter.trim().isEmpty()) + { + LOG.info("ignoring empty parameter"); + return ProcessorResult.OK; + } Iterator> it = null; -- 2.20.1