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.dom.Node;
8 import org.thymeleaf.processor.AbstractProcessor;
9 import org.thymeleaf.processor.IProcessorMatcher;
10 import org.thymeleaf.processor.ProcessorMatchingContext;
11 import org.thymeleaf.processor.ProcessorResult;
12 import org.thymeleaf.processor.AttributeNameProcessorMatcher;
13 import org.thymeleaf.standard.expression.IStandardExpression;
14 import org.thymeleaf.standard.expression.IStandardExpressionParser;
15 import org.thymeleaf.standard.expression.StandardExpressions;
19 * Replaces the element by the tag <code><span></code>, if it is
23 public class InactiveElementProcessor extends AbstractProcessor
25 private final AttributeNameProcessorMatcher matcher =
26 new AttributeNameProcessorMatcher("inactive");
30 public IProcessorMatcher<? extends Node> getMatcher()
36 protected ProcessorResult doProcess(
38 ProcessorMatchingContext context,
42 // Because of the type of applicability being used, casts to Element here will not fail
43 final Element element = (Element) node;
44 final String[] names = this.matcher.getAttributeNames(context);
46 for (final String name : names)
48 if (element.hasNormalizedAttribute(name))
50 Configuration configuration = arguments.getConfiguration();
51 IStandardExpressionParser parser =
52 StandardExpressions.getExpressionParser(configuration);
53 String value = element.getAttributeValue(name);
54 IStandardExpression expression =
55 parser.parseExpression(configuration, arguments, value);
56 element.removeAttribute(name);
57 if ((Boolean)expression.execute(configuration, arguments))
59 // We must not clone the processors, because we remove attributes
61 element.cloneElementNodeWithNewName(element, "span", false);
62 strong.removeAttribute("charset");
63 strong.removeAttribute("th:charset");
64 strong.removeAttribute("coords");
65 strong.removeAttribute("href");
66 strong.removeAttribute("th:href");
67 strong.removeAttribute("hreflang");
68 strong.removeAttribute("th:hreflang");
69 strong.removeAttribute("media");
70 strong.removeAttribute("th:media");
71 strong.removeAttribute("name");
72 strong.removeAttribute("th:name");
73 strong.removeAttribute("rel");
74 strong.removeAttribute("th:rel");
75 strong.removeAttribute("ref");
76 strong.removeAttribute("th:ref");
77 strong.removeAttribute("shape");
78 strong.removeAttribute("target");
79 strong.removeAttribute("th:target");
80 strong.removeAttribute("type");
81 strong.removeAttribute("th:type");
82 element.clearChildren();
83 element.addChild(strong);
84 element.getParent().extractChild(element);
89 return ProcessorResult.OK;
93 public int getPrecedence()
95 // Be sure to be executed first