1 package de.juplo.thymeleaf;
4 import org.thymeleaf.Arguments;
5 import org.thymeleaf.Configuration;
6 import org.thymeleaf.dom.Element;
7 import org.thymeleaf.processor.ProcessorResult;
8 import org.thymeleaf.processor.attr.AbstractAttrProcessor;
9 import org.thymeleaf.standard.expression.IStandardExpression;
10 import org.thymeleaf.standard.expression.IStandardExpressionParser;
11 import org.thymeleaf.standard.expression.StandardExpressions;
15 * Replaces the element by the tag <code><strong></code>, if it is
19 public class ActiveAttrProcessor extends AbstractAttrProcessor
21 public static final int ATTR_PRECEDENCE = 100;
24 public ActiveAttrProcessor()
31 protected ProcessorResult processAttribute(
37 Configuration configuration = arguments.getConfiguration();
38 IStandardExpressionParser parser =
39 StandardExpressions.getExpressionParser(configuration);
40 String value = element.getAttributeValue(name);
41 IStandardExpression expression =
42 parser.parseExpression(configuration, arguments, value);
43 element.removeAttribute(name);
44 if ((Boolean)expression.execute(configuration, arguments))
46 // We must not clone the processors, because we remove attributes
48 element.cloneElementNodeWithNewName(element, "strong", false);
49 strong.removeAttribute("charset");
50 strong.removeAttribute("th:charset");
51 strong.removeAttribute("coords");
52 strong.removeAttribute("href");
53 strong.removeAttribute("th:href");
54 strong.removeAttribute("hreflang");
55 strong.removeAttribute("th:hreflang");
56 strong.removeAttribute("media");
57 strong.removeAttribute("th:media");
58 strong.removeAttribute("name");
59 strong.removeAttribute("th:name");
60 strong.removeAttribute("rel");
61 strong.removeAttribute("th:rel");
62 strong.removeAttribute("ref");
63 strong.removeAttribute("th:ref");
64 strong.removeAttribute("shape");
65 strong.removeAttribute("target");
66 strong.removeAttribute("th:target");
67 strong.removeAttribute("type");
68 strong.removeAttribute("th:type");
69 element.clearChildren();
70 element.addChild(strong);
71 element.getParent().extractChild(element);
73 return ProcessorResult.OK;
77 public int getPrecedence()
79 return ATTR_PRECEDENCE;