X-Git-Url: https://juplo.de/gitweb/?p=juplo-dialect;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fthymeleaf%2FInactiveAttrProcessor.java;h=f04074c44ff05ec8e4981ab0a276ee05be17715f;hp=30db2d56172bdb9f0c8d7f42ccfa05d79f36d2f2;hb=570d4491daed7c6f632774a130032b88de9ea81c;hpb=815df4f032e0cfdef9857f711420c772f9e2c0d5 diff --git a/src/main/java/de/juplo/thymeleaf/InactiveAttrProcessor.java b/src/main/java/de/juplo/thymeleaf/InactiveAttrProcessor.java index 30db2d5..f04074c 100644 --- a/src/main/java/de/juplo/thymeleaf/InactiveAttrProcessor.java +++ b/src/main/java/de/juplo/thymeleaf/InactiveAttrProcessor.java @@ -1,81 +1,15 @@ package de.juplo.thymeleaf; -import org.thymeleaf.Arguments; -import org.thymeleaf.Configuration; -import org.thymeleaf.dom.Element; -import org.thymeleaf.processor.ProcessorResult; -import org.thymeleaf.processor.attr.AbstractAttrProcessor; -import org.thymeleaf.standard.expression.IStandardExpression; -import org.thymeleaf.standard.expression.IStandardExpressionParser; -import org.thymeleaf.standard.expression.StandardExpressions; - - /** * Replaces the element by the tag <span>, if it is * marked as inactive. * @author Kai Moritz */ -public class InactiveAttrProcessor extends AbstractAttrProcessor +public class InactiveAttrProcessor extends AbstractSubstituteAttrProcessor { - public static final int ATTR_PRECEDENCE = 100; - - public InactiveAttrProcessor() { - super("inactive"); - } - - - @Override - protected ProcessorResult processAttribute( - Arguments arguments, - Element element, - String name - ) - { - Configuration configuration = arguments.getConfiguration(); - IStandardExpressionParser parser = - StandardExpressions.getExpressionParser(configuration); - String value = element.getAttributeValue(name); - IStandardExpression expression = - parser.parseExpression(configuration, arguments, value); - element.removeAttribute(name); - if ((Boolean)expression.execute(configuration, arguments)) - { - // We must not clone the processors, because we remove attributes - Element strong = - element.cloneElementNodeWithNewName(element, "span", false); - strong.removeAttribute("charset"); - strong.removeAttribute("th:charset"); - strong.removeAttribute("coords"); - strong.removeAttribute("href"); - strong.removeAttribute("th:href"); - strong.removeAttribute("hreflang"); - strong.removeAttribute("th:hreflang"); - strong.removeAttribute("media"); - strong.removeAttribute("th:media"); - strong.removeAttribute("name"); - strong.removeAttribute("th:name"); - strong.removeAttribute("rel"); - strong.removeAttribute("th:rel"); - strong.removeAttribute("ref"); - strong.removeAttribute("th:ref"); - strong.removeAttribute("shape"); - strong.removeAttribute("target"); - strong.removeAttribute("th:target"); - strong.removeAttribute("type"); - strong.removeAttribute("th:type"); - element.clearChildren(); - element.addChild(strong); - element.getParent().extractChild(element); - } - return ProcessorResult.OK; - } - - @Override - public int getPrecedence() - { - return ATTR_PRECEDENCE; + super("inactive", "span"); } }