X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fthymeleaf%2FAbstractSubstituteAttrProcessor.java;fp=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fthymeleaf%2FAbstractSubstituteAttrProcessor.java;h=0000000000000000000000000000000000000000;hb=8ecd49f95b2af21c0a546007edc4e3d5346e7356;hp=6274016d1a22ba459c641b2ab225797666f6a4fb;hpb=2ebd13014f98d349aa147185dac2dd860fccf225;p=juplo-dialect diff --git a/src/main/java/de/juplo/thymeleaf/AbstractSubstituteAttrProcessor.java b/src/main/java/de/juplo/thymeleaf/AbstractSubstituteAttrProcessor.java deleted file mode 100644 index 6274016..0000000 --- a/src/main/java/de/juplo/thymeleaf/AbstractSubstituteAttrProcessor.java +++ /dev/null @@ -1,89 +0,0 @@ -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; - - -/** - * Subsitutes the element, that is marked with this attribute-processor. - * - * @author kai - */ -public abstract class AbstractSubstituteAttrProcessor extends AbstractAttrProcessor -{ - public static final int ATTR_PRECEDENCE = 100; - - private final String substituteName; - - - public AbstractSubstituteAttrProcessor(String attribute, String substitute) - { - super(attribute); - this.substituteName = substitute; - } - - - @Override - protected final 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 substituteElement = - element.cloneElementNodeWithNewName(element, substituteName, false); - // Remove attributes, that are not allowed for or - substituteElement.removeAttribute("charset"); - substituteElement.removeAttribute("th:charset"); - substituteElement.removeAttribute("coords"); - substituteElement.removeAttribute("href"); - substituteElement.removeAttribute("th:href"); - substituteElement.removeAttribute("hreflang"); - substituteElement.removeAttribute("th:hreflang"); - substituteElement.removeAttribute("media"); - substituteElement.removeAttribute("th:media"); - substituteElement.removeAttribute("name"); - substituteElement.removeAttribute("th:name"); - substituteElement.removeAttribute("rel"); - substituteElement.removeAttribute("th:rel"); - substituteElement.removeAttribute("ref"); - substituteElement.removeAttribute("th:ref"); - substituteElement.removeAttribute("shape"); - substituteElement.removeAttribute("target"); - substituteElement.removeAttribute("th:target"); - substituteElement.removeAttribute("type"); - substituteElement.removeAttribute("th:type"); - // Also remove the title-attribute, because the mouse-over is confusing - substituteElement.removeAttribute("title"); - substituteElement.removeAttribute("th:title"); - // Replace the element - element.clearChildren(); - element.addChild(substituteElement); - element.getParent().extractChild(element); - } - return ProcessorResult.OK; - } - - @Override - public final int getPrecedence() - { - return ATTR_PRECEDENCE; - } -}