From: Kai Moritz Date: Fri, 8 Jul 2016 16:34:55 +0000 (+0200) Subject: juplo:variables accepts expressions as arguments X-Git-Tag: juplo-dialect-1.0.0~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=821382582b5e3c55042accfabcd3bbbcedf3df5e;p=juplo-dialect 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. --- 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;