1 | package fr.sii.ogham.template.thymeleaf.common.configure; | |
2 | ||
3 | import org.slf4j.Logger; | |
4 | ||
5 | import fr.sii.ogham.core.builder.MessagingBuilder; | |
6 | import fr.sii.ogham.core.builder.configurer.DefaultMessagingConfigurer; | |
7 | import fr.sii.ogham.core.builder.configurer.MessagingConfigurer; | |
8 | import fr.sii.ogham.core.builder.configurer.MessagingConfigurerAdapter; | |
9 | import fr.sii.ogham.core.builder.env.EnvironmentBuilder; | |
10 | import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder; | |
11 | import fr.sii.ogham.template.thymeleaf.common.buider.AbstractThymeleafBuilder; | |
12 | ||
13 | /** | |
14 | * Default configurer for Thymeleaf template engine that is automatically | |
15 | * applied every time a {@link MessagingBuilder} instance is created through | |
16 | * {@link MessagingBuilder#standard()} or {@link MessagingBuilder#minimal()}. | |
17 | * | |
18 | * <p> | |
19 | * The configurer has a priority of 70000 in order to be applied after global | |
20 | * configurer but before any sender implementation. | |
21 | * </p> | |
22 | * | |
23 | * This configurer is applied only if {@code org.thymeleaf.TemplateEngine} is | |
24 | * present in the classpath. If not present, template engine is not registered | |
25 | * at all. | |
26 | * | |
27 | * <p> | |
28 | * This configurer inherits environment configuration (see | |
29 | * {@link EnvironmentBuilder}). | |
30 | * </p> | |
31 | * <p> | |
32 | * It also copies resource resolution configuration of | |
33 | * {@link DefaultMessagingConfigurer} to inherit resource resolution lookups | |
34 | * (see {@link ResourceResolutionBuilder}). | |
35 | * </p> | |
36 | * | |
37 | * <p> | |
38 | * This configurer applies the following configuration: | |
39 | * <ul> | |
40 | * <li>Configures template prefix/suffix paths: | |
41 | * <ul> | |
42 | * <li>Uses the first property that has a value for classpath resolution prefix: | |
43 | * <ol> | |
44 | * <li>"ogham.sms.thymeleaf.classpath.path-prefix"</li> | |
45 | * <li>"ogham.sms.template.classpath.path-prefix"</li> | |
46 | * <li>"ogham.sms.thymeleaf.path-prefix"</li> | |
47 | * <li>"ogham.sms.template.path-prefix"</li> | |
48 | * <li>"ogham.template.path-prefix"</li> | |
49 | * </ol> | |
50 | * </li> | |
51 | * <li>Uses the first property that has a value for classpath resolution suffix: | |
52 | * <ol> | |
53 | * <li>"ogham.sms.thymeleaf.classpath.path-suffix"</li> | |
54 | * <li>"ogham.sms.template.classpath.path-suffix"</li> | |
55 | * <li>"ogham.sms.thymeleaf.path-suffix"</li> | |
56 | * <li>"ogham.sms.template.path-suffix"</li> | |
57 | * <li>"ogham.template.path-suffix"</li> | |
58 | * </ol> | |
59 | * </li> | |
60 | * <li>Uses the first property that has a value for file resolution prefix: | |
61 | * <ol> | |
62 | * <li>"ogham.sms.thymeleaf.file.path-prefix"</li> | |
63 | * <li>"ogham.sms.template.file.path-prefix"</li> | |
64 | * <li>"ogham.sms.thymeleaf.path-prefix"</li> | |
65 | * <li>"ogham.sms.template.path-prefix"</li> | |
66 | * <li>"ogham.template.path-prefix"</li> | |
67 | * </ol> | |
68 | * </li> | |
69 | * <li>Uses the first property that has a value for file resolution suffix: | |
70 | * <ol> | |
71 | * <li>"ogham.sms.thymeleaf.file.path-suffix"</li> | |
72 | * <li>"ogham.sms.template.file.path-suffix"</li> | |
73 | * <li>"ogham.sms.thymeleaf.path-suffix"</li> | |
74 | * <li>"ogham.sms.template.path-suffix"</li> | |
75 | * <li>"ogham.template.path-suffix"</li> | |
76 | * </ol> | |
77 | * </li> | |
78 | * </ul> | |
79 | * </li> | |
80 | * <li>Configures template detection: | |
81 | * <ul> | |
82 | * <li>Uses ThymeleafTemplateDetector to detect if templates are | |
83 | * parseable by Thymeleaf</li> | |
84 | * </ul> | |
85 | * </li> | |
86 | * </ul> | |
87 | * | |
88 | * @author Aurélien Baudet | |
89 | * | |
90 | */ | |
91 | public abstract class AbstractDefaultThymeleafSmsConfigurer implements MessagingConfigurer { | |
92 | private final Logger log; | |
93 | private final MessagingConfigurerAdapter delegate; | |
94 | ||
95 | public AbstractDefaultThymeleafSmsConfigurer(Logger log) { | |
96 | this(log, new DefaultMessagingConfigurer()); | |
97 | } | |
98 | ||
99 | public AbstractDefaultThymeleafSmsConfigurer(Logger log, MessagingConfigurerAdapter delegate) { | |
100 | super(); | |
101 | this.log = log; | |
102 | this.delegate = delegate; | |
103 | } | |
104 | ||
105 | @Override | |
106 | public void configure(MessagingBuilder msgBuilder) { | |
107 |
4
1. configure : negated conditional → NO_COVERAGE 2. configure : negated conditional → KILLED 3. configure : negated conditional → KILLED 4. configure : negated conditional → KILLED |
if (!canUseThymeleaf()) { |
108 | log.debug("[{}] skip configuration", this); | |
109 | return; | |
110 | } | |
111 | log.debug("[{}] apply configuration", this); | |
112 | AbstractThymeleafBuilder<?, ?, ?> builder = msgBuilder.sms().template(getBuilderClass()); | |
113 | // apply default resource resolution configuration | |
114 |
4
1. configure : negated conditional → NO_COVERAGE 2. configure : negated conditional → KILLED 3. configure : negated conditional → KILLED 4. configure : negated conditional → KILLED |
if (delegate != null) { |
115 |
4
1. configure : removed call to fr/sii/ogham/core/builder/configurer/MessagingConfigurerAdapter::configure → NO_COVERAGE 2. configure : removed call to fr/sii/ogham/core/builder/configurer/MessagingConfigurerAdapter::configure → KILLED 3. configure : removed call to fr/sii/ogham/core/builder/configurer/MessagingConfigurerAdapter::configure → KILLED 4. configure : removed call to fr/sii/ogham/core/builder/configurer/MessagingConfigurerAdapter::configure → KILLED |
delegate.configure(builder); |
116 | } | |
117 | // @formatter:off | |
118 | builder | |
119 | .classpath() | |
120 | .pathPrefix() | |
121 | .properties("${ogham.sms.thymeleaf.classpath.path-prefix}", | |
122 | "${ogham.sms.template.classpath.path-prefix}", | |
123 | "${ogham.sms.thymeleaf.path-prefix}", | |
124 | "${ogham.sms.template.path-prefix}", | |
125 | "${ogham.template.path-prefix}") | |
126 | .and() | |
127 | .pathSuffix() | |
128 | .properties("${ogham.sms.thymeleaf.classpath.path-suffix}", | |
129 | "${ogham.sms.template.classpath.path-suffix}", | |
130 | "${ogham.sms.thymeleaf.path-suffix}", | |
131 | "${ogham.sms.template.path-suffix}", | |
132 | "${ogham.template.path-suffix}") | |
133 | .and() | |
134 | .and() | |
135 | .file() | |
136 | .pathPrefix() | |
137 | .properties("${ogham.sms.thymeleaf.file.path-prefix}", | |
138 | "${ogham.sms.template.file.path-prefix}", | |
139 | "${ogham.sms.thymeleaf.path-prefix}", | |
140 | "${ogham.sms.template.path-prefix}", | |
141 | "${ogham.template.path-prefix}") | |
142 | .and() | |
143 | .pathSuffix() | |
144 | .properties("${ogham.sms.thymeleaf.file.path-suffix}", | |
145 | "${ogham.sms.template.file.path-suffix}", | |
146 | "${ogham.sms.thymeleaf.path-suffix}", | |
147 | "${ogham.sms.template.path-suffix}", | |
148 | "${ogham.template.path-suffix}") | |
149 | .and() | |
150 | .and() | |
151 | .cache() | |
152 | .properties("${ogham.sms.thymeleaf.cache}", | |
153 | "${ogham.sms.template.cache}", | |
154 | "${ogham.template.cache}"); | |
155 | // @formatter:on | |
156 | } | |
157 | ||
158 | protected abstract Class<? extends AbstractThymeleafBuilder<?, ?, ?>> getBuilderClass(); | |
159 | ||
160 | protected abstract boolean canUseThymeleaf(); | |
161 | ||
162 | } | |
Mutations | ||
107 |
1.1 2.2 3.3 4.4 |
|
114 |
1.1 2.2 3.3 4.4 |
|
115 |
1.1 2.2 3.3 4.4 |