TMP
[juplo-dialect] / src / main / java / de / juplo / thymeleaf / ImportVariablesAttrProcessor.java
index e864ab1..d41b33c 100644 (file)
@@ -15,16 +15,19 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.thymeleaf.Arguments;
-import org.thymeleaf.Configuration;
-import org.thymeleaf.TemplateProcessingParameters;
 import org.thymeleaf.context.IContext;
-import org.thymeleaf.context.VariablesMap;
-import org.thymeleaf.dom.Element;
-import org.thymeleaf.dom.Node;
-import org.thymeleaf.processor.ProcessorResult;
-import org.thymeleaf.processor.attr.AbstractAttrProcessor;
-import org.thymeleaf.resourceresolver.IResourceResolver;
+import org.thymeleaf.context.ITemplateContext;
+import org.thymeleaf.engine.AttributeName;
+import org.thymeleaf.engine.EngineEventUtils;
+import org.thymeleaf.exceptions.TemplateProcessingException;
+import org.thymeleaf.model.IModel;
+import org.thymeleaf.model.IProcessableElementTag;
+import org.thymeleaf.processor.element.AbstractAttributeModelProcessor;
+import org.thymeleaf.processor.element.IElementModelStructureHandler;
+import org.thymeleaf.standard.expression.IStandardExpression;
+import org.thymeleaf.standard.expression.IStandardExpressionParser;
+import org.thymeleaf.standard.expression.StandardExpressions;
+import org.thymeleaf.templatemode.TemplateMode;
 import org.thymeleaf.templateresolver.ITemplateResolver;
 import org.thymeleaf.templateresolver.TemplateResolution;
 
@@ -35,7 +38,7 @@ import org.thymeleaf.templateresolver.TemplateResolution;
  * variables.
  * @author Kai Moritz
  */
-public class ImportVariablesAttrProcessor extends AbstractAttrProcessor
+public class ImportVariablesAttrProcessor extends AbstractAttributeModelProcessor
 {
   private static final Logger LOG =
       LoggerFactory.getLogger(ImportVariablesAttrProcessor.class);
@@ -51,21 +54,49 @@ public class ImportVariablesAttrProcessor extends AbstractAttrProcessor
   public static final int ATTR_PRECEDENCE = 200;
 
 
-  public ImportVariablesAttrProcessor()
+  public ImportVariablesAttrProcessor(
+      final String prefix,
+      final String attribute,
+      final String substitute
+      )
   {
-    super("variables");
+    super(
+        TemplateMode.HTML,
+        prefix,
+        null,
+        false,
+        attribute,
+        true,
+        ATTR_PRECEDENCE,
+        false
+        );
   }
 
 
   @Override
-  public final ProcessorResult processAttribute(
-      final Arguments arguments,
-      final Element element,
-      final String name
+  protected void doProcess(
+      final ITemplateContext context,
+      final IModel model,
+      final AttributeName attributeName,
+      final String attributeValue,
+      final IElementModelStructureHandler handler
       )
   {
-    Configuration config = arguments.getConfiguration();
-    String parameter = element.getAttributeValue(name);
+    final IProcessableElementTag element = (IProcessableElementTag) model.get(0);
+    final String parameter =
+        EngineEventUtils.computeAttributeExpression(
+            context,
+            element,
+            attributeName,
+            attributeValue
+            )
+            .execute(context).toString();
+
+    if (parameter != null && !parameter.trim().isEmpty())
+    {
+      LOG.info("ignoring empty parameter");
+      return;
+    }
 
     Iterator<Entry<String, Object>> it = null;