|
1 | 1 | package org.mvnsearch.config;
|
2 | 2 |
|
3 |
| -import org.thymeleaf.Arguments; |
4 |
| -import org.thymeleaf.dialect.AbstractDialect; |
5 |
| -import org.thymeleaf.dom.Element; |
| 3 | +import org.thymeleaf.context.ITemplateContext; |
| 4 | +import org.thymeleaf.dialect.AbstractProcessorDialect; |
| 5 | +import org.thymeleaf.dialect.IProcessorDialect; |
| 6 | +import org.thymeleaf.engine.AttributeName; |
| 7 | +import org.thymeleaf.model.IModel; |
6 | 8 | import org.thymeleaf.processor.IProcessor;
|
7 |
| -import org.thymeleaf.processor.attr.AbstractUnescapedTextChildModifierAttrProcessor; |
| 9 | +import org.thymeleaf.processor.element.AbstractAttributeModelProcessor; |
| 10 | +import org.thymeleaf.processor.element.IElementModelStructureHandler; |
| 11 | +import org.thymeleaf.templatemode.TemplateMode; |
8 | 12 |
|
9 |
| -import java.util.HashSet; |
| 13 | +import java.util.Collections; |
10 | 14 | import java.util.Set;
|
11 | 15 |
|
12 | 16 | /**
|
13 | 17 | * 自定义 thymeleaf cms 标签
|
14 | 18 | *
|
15 | 19 | * @author linux_china
|
16 | 20 | */
|
17 |
| -public class CmsDialect extends AbstractDialect { |
| 21 | +public class CmsDialect extends AbstractProcessorDialect { |
18 | 22 |
|
19 |
| - @Override |
20 |
| - public String getPrefix() { |
21 |
| - return "cms"; |
| 23 | + public CmsDialect() { |
| 24 | + super("CMS", "cms", 1); |
22 | 25 | }
|
23 | 26 |
|
24 |
| - @Override |
25 |
| - public Set<IProcessor> getProcessors() { |
26 |
| - final Set<IProcessor> processors = new HashSet<>(); |
27 |
| - processors.add(new AbstractUnescapedTextChildModifierAttrProcessor("fragment") { |
| 27 | + public Set<IProcessor> getProcessors(String dialectPrefix) { |
| 28 | + IProcessor processor = new AbstractAttributeModelProcessor(TemplateMode.HTML, dialectPrefix, null, false, "fragment", false, 1, true) { |
28 | 29 | @Override
|
29 |
| - protected String getText(Arguments arguments, Element element, String attributeName) { |
30 |
| - String attributeValue = element.getAttributeValue(attributeName); |
31 |
| - return "Load from cms fragment: <h3>"+attributeValue + "</h3>"; |
32 |
| - } |
| 30 | + protected void doProcess(ITemplateContext context, IModel model, AttributeName attributeName, String attributeValue, IElementModelStructureHandler structureHandler) { |
33 | 31 |
|
34 |
| - @Override |
35 |
| - public int getPrecedence() { |
36 |
| - return 100; |
37 | 32 | }
|
38 |
| - }); |
39 |
| - return processors; |
| 33 | + }; |
| 34 | + return Collections.singleton(processor); |
40 | 35 | }
|
| 36 | + |
41 | 37 | }
|
0 commit comments