1 | package fr.sii.ogham.template.thymeleaf.common.buider; | |
2 | ||
3 | import java.util.HashMap; | |
4 | import java.util.HashSet; | |
5 | import java.util.Map; | |
6 | import java.util.Set; | |
7 | ||
8 | import org.thymeleaf.TemplateEngine; | |
9 | import org.thymeleaf.cache.ICacheManager; | |
10 | import org.thymeleaf.dialect.IDialect; | |
11 | import org.thymeleaf.messageresolver.IMessageResolver; | |
12 | import org.thymeleaf.templateresolver.ITemplateResolver; | |
13 | ||
14 | import fr.sii.ogham.core.builder.Builder; | |
15 | import fr.sii.ogham.core.builder.context.BuildContext; | |
16 | import fr.sii.ogham.core.fluent.AbstractParent; | |
17 | ||
18 | public abstract class AbstractThymeleafEngineConfigBuilder<MYSELF extends AbstractThymeleafEngineConfigBuilder<MYSELF, P>, P> extends AbstractParent<P> implements Builder<TemplateEngine> { | |
19 | protected final MYSELF myself; | |
20 | protected final BuildContext buildContext; | |
21 | protected Set<IDialect> dialects; | |
22 | protected Map<String, IDialect> dialectsByPrefix; | |
23 | protected Set<ITemplateResolver> templateResolvers; | |
24 | protected ICacheManager cacheManager; | |
25 | protected Set<IMessageResolver> messageResolvers; | |
26 | ||
27 | @SuppressWarnings("unchecked") | |
28 | public AbstractThymeleafEngineConfigBuilder(Class<?> selfType, P parent, BuildContext buildContext) { | |
29 | super(parent); | |
30 | myself = (MYSELF) selfType.cast(this); | |
31 | this.buildContext = buildContext; | |
32 | } | |
33 | | |
34 | ||
35 | /** | |
36 | * <p> | |
37 | * Sets a new unique dialect for this template engine. | |
38 | * </p> | |
39 | * <p> | |
40 | * This operation is equivalent to removing all the currently configured | |
41 | * dialects and then adding this one. | |
42 | * </p> | |
43 | * <p> | |
44 | * This operation can only be executed before processing templates for the | |
45 | * first time. Once a template is processed, the template engine is | |
46 | * considered to be <i>initialized</i>, and from then on any attempt to | |
47 | * change its configuration will result in an exception. | |
48 | * </p> | |
49 | * | |
50 | * @param dialect | |
51 | * the new unique {@link IDialect} to be used. | |
52 | * @return this for fluent use | |
53 | */ | |
54 | public MYSELF setDialect(final IDialect dialect) { | |
55 |
1
1. setDialect : removed call to java/util/Set::clear → NO_COVERAGE |
dialects().clear(); |
56 | dialects().add(dialect); | |
57 |
1
1. setDialect : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setDialect → NO_COVERAGE |
return myself; |
58 | } | |
59 | ||
60 | /** | |
61 | * <p> | |
62 | * Adds a new dialect for this template engine, using the specified prefix. | |
63 | * </p> | |
64 | * <p> | |
65 | * This dialect will be added to the set of currently configured ones. | |
66 | * </p> | |
67 | * <p> | |
68 | * This operation can only be executed before processing templates for the | |
69 | * first time. Once a template is processed, the template engine is | |
70 | * considered to be <i>initialized</i>, and from then on any attempt to | |
71 | * change its configuration will result in an exception. | |
72 | * </p> | |
73 | * | |
74 | * @param prefix | |
75 | * the prefix that will be used for this dialect | |
76 | * @param dialect | |
77 | * the new {@link IDialect} to be added to the existing ones. | |
78 | * @return this for fluent use | |
79 | */ | |
80 | public MYSELF addDialect(final String prefix, final IDialect dialect) { | |
81 | this.dialectsByPrefix().put(prefix, dialect); | |
82 |
1
1. addDialect : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::addDialect → NO_COVERAGE |
return myself; |
83 | } | |
84 | ||
85 | /** | |
86 | * <p> | |
87 | * Adds a new dialect for this template engine, using the dialect's | |
88 | * specified default dialect. | |
89 | * </p> | |
90 | * <p> | |
91 | * This dialect will be added to the set of currently configured ones. | |
92 | * </p> | |
93 | * <p> | |
94 | * This operation can only be executed before processing templates for the | |
95 | * first time. Once a template is processed, the template engine is | |
96 | * considered to be <i>initialized</i>, and from then on any attempt to | |
97 | * change its configuration will result in an exception. | |
98 | * </p> | |
99 | * | |
100 | * @param dialect | |
101 | * the new {@link IDialect} to be added to the existing ones. | |
102 | * @return this for fluent use | |
103 | */ | |
104 | public MYSELF addDialect(final IDialect dialect) { | |
105 | dialects().add(dialect); | |
106 |
1
1. addDialect : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::addDialect → NO_COVERAGE |
return myself; |
107 | } | |
108 | ||
109 | /** | |
110 | * <p> | |
111 | * Sets a new set of dialects for this template engine, referenced by the | |
112 | * prefixes they will be using. | |
113 | * </p> | |
114 | * <p> | |
115 | * This operation can only be executed before processing templates for the | |
116 | * first time. Once a template is processed, the template engine is | |
117 | * considered to be <i>initialized</i>, and from then on any attempt to | |
118 | * change its configuration will result in an exception. | |
119 | * </p> | |
120 | * | |
121 | * @param dialects | |
122 | * the new map of {@link IDialect} objects to be used, referenced | |
123 | * by their prefixes. | |
124 | * @return this for fluent use | |
125 | */ | |
126 | public MYSELF setDialectsByPrefix(final Map<String, IDialect> dialects) { | |
127 |
1
1. setDialectsByPrefix : removed call to java/util/Map::clear → NO_COVERAGE |
dialectsByPrefix().clear(); |
128 |
1
1. setDialectsByPrefix : removed call to java/util/Map::putAll → NO_COVERAGE |
dialectsByPrefix().putAll(dialects); |
129 |
1
1. setDialectsByPrefix : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setDialectsByPrefix → NO_COVERAGE |
return myself; |
130 | } | |
131 | ||
132 | /** | |
133 | * <p> | |
134 | * Sets a new set of dialects for this template engine, all of them using | |
135 | * their default prefixes. | |
136 | * </p> | |
137 | * <p> | |
138 | * This operation can only be executed before processing templates for the | |
139 | * first time. Once a template is processed, the template engine is | |
140 | * considered to be <i>initialized</i>, and from then on any attempt to | |
141 | * change its configuration will result in an exception. | |
142 | * </p> | |
143 | * | |
144 | * @param dialects | |
145 | * the new set of {@link IDialect} objects to be used. | |
146 | * @return this for fluent use | |
147 | */ | |
148 | public MYSELF setDialects(final Set<IDialect> dialects) { | |
149 |
1
1. setDialects : removed call to java/util/Set::clear → NO_COVERAGE |
this.dialects().clear(); |
150 | this.dialects().addAll(dialects); | |
151 |
1
1. setDialects : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setDialects → NO_COVERAGE |
return myself; |
152 | } | |
153 | ||
154 | /** | |
155 | * <p> | |
156 | * Sets an additional set of dialects for this template engine, all of them | |
157 | * using their default prefixes. | |
158 | * </p> | |
159 | * <p> | |
160 | * This operation can only be executed before processing templates for the | |
161 | * first time. Once a template is processed, the template engine is | |
162 | * considered to be <i>initialized</i>, and from then on any attempt to | |
163 | * change its configuration will result in an exception. | |
164 | * </p> | |
165 | * | |
166 | * @param additionalDialects | |
167 | * the new set of {@link IDialect} objects to be used. | |
168 | * | |
169 | * @since 2.0.9 | |
170 | * @return this for fluent use | |
171 | */ | |
172 | public MYSELF setAdditionalDialects(final Set<IDialect> additionalDialects) { | |
173 | dialects().addAll(additionalDialects); | |
174 |
1
1. setAdditionalDialects : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setAdditionalDialects → NO_COVERAGE |
return myself; |
175 | } | |
176 | ||
177 | /** | |
178 | * <p> | |
179 | * Removes all the currently configured dialects. | |
180 | * </p> | |
181 | * <p> | |
182 | * This operation can only be executed before processing templates for the | |
183 | * first time. Once a template is processed, the template engine is | |
184 | * considered to be <i>initialized</i>, and from then on any attempt to | |
185 | * change its configuration will result in an exception. | |
186 | * </p> | |
187 | * | |
188 | * @return this for fluent use | |
189 | */ | |
190 | public MYSELF clearDialects() { | |
191 |
1
1. clearDialects : removed call to java/util/Set::clear → NO_COVERAGE |
dialects().clear(); |
192 |
1
1. clearDialects : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::clearDialects → NO_COVERAGE |
return myself; |
193 | } | |
194 | ||
195 | /** | |
196 | * <p> | |
197 | * Sets the entire set of template resolvers. | |
198 | * </p> | |
199 | * | |
200 | * @param templateResolvers | |
201 | * the new template resolvers. | |
202 | * @return this for fluent use | |
203 | */ | |
204 | public MYSELF setTemplateResolvers(final Set<? extends ITemplateResolver> templateResolvers) { | |
205 |
1
1. setTemplateResolvers : removed call to java/util/Set::clear → NO_COVERAGE |
this.templateResolvers().clear(); |
206 | this.templateResolvers().addAll(templateResolvers); | |
207 |
1
1. setTemplateResolvers : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setTemplateResolvers → NO_COVERAGE |
return myself; |
208 | } | |
209 | ||
210 | /** | |
211 | * <p> | |
212 | * Adds a new template resolver to the current set. | |
213 | * </p> | |
214 | * | |
215 | * @param templateResolver | |
216 | * the new template resolver. | |
217 | * @return this for fluent use | |
218 | */ | |
219 | public MYSELF addTemplateResolver(final ITemplateResolver templateResolver) { | |
220 | templateResolvers().add(templateResolver); | |
221 |
1
1. addTemplateResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::addTemplateResolver → NO_COVERAGE |
return myself; |
222 | } | |
223 | ||
224 | /** | |
225 | * <p> | |
226 | * Sets a single template resolver for this template engine. | |
227 | * </p> | |
228 | * <p> | |
229 | * Calling this method is equivalent to calling | |
230 | * {@link #setTemplateResolvers(Set)} passing a Set with only one template | |
231 | * resolver. | |
232 | * </p> | |
233 | * | |
234 | * @param templateResolver | |
235 | * the template resolver to be set. | |
236 | * @return this for fluent use | |
237 | */ | |
238 | public MYSELF setTemplateResolver(final ITemplateResolver templateResolver) { | |
239 |
1
1. setTemplateResolver : removed call to java/util/Set::clear → NO_COVERAGE |
templateResolvers().clear(); |
240 | templateResolvers().add(templateResolver); | |
241 |
1
1. setTemplateResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setTemplateResolver → NO_COVERAGE |
return myself; |
242 | } | |
243 | ||
244 | /** | |
245 | * <p> | |
246 | * Sets the Cache Manager to be used. If set to null, no caches will be used | |
247 | * throughout the engine. | |
248 | * </p> | |
249 | * <p> | |
250 | * By default, an instance of | |
251 | * {@link org.thymeleaf.cache.StandardCacheManager} is set. | |
252 | * </p> | |
253 | * <p> | |
254 | * This operation can only be executed before processing templates for the | |
255 | * first time. Once a template is processed, the template engine is | |
256 | * considered to be <i>initialized</i>, and from then on any attempt to | |
257 | * change its configuration will result in an exception. | |
258 | * </p> | |
259 | * | |
260 | * @param cacheManager | |
261 | * the cache manager to be set. | |
262 | * @return this for fluent use | |
263 | * | |
264 | */ | |
265 | public MYSELF setCacheManager(final ICacheManager cacheManager) { | |
266 | this.cacheManager = cacheManager; | |
267 |
1
1. setCacheManager : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setCacheManager → NO_COVERAGE |
return myself; |
268 | } | |
269 | ||
270 | /** | |
271 | * <p> | |
272 | * Sets the message resolvers to be used by this template engine. | |
273 | * </p> | |
274 | * <p> | |
275 | * This operation can only be executed before processing templates for the | |
276 | * first time. Once a template is processed, the template engine is | |
277 | * considered to be <i>initialized</i>, and from then on any attempt to | |
278 | * change its configuration will result in an exception. | |
279 | * </p> | |
280 | * | |
281 | * @param messageResolvers | |
282 | * the Set of template resolvers. | |
283 | * @return this for fluent use | |
284 | */ | |
285 | public MYSELF setMessageResolvers(final Set<? extends IMessageResolver> messageResolvers) { | |
286 |
1
1. setMessageResolvers : removed call to java/util/Set::clear → NO_COVERAGE |
this.messageResolvers().clear(); |
287 | this.messageResolvers().addAll(messageResolvers); | |
288 |
1
1. setMessageResolvers : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setMessageResolvers → NO_COVERAGE |
return myself; |
289 | } | |
290 | ||
291 | /** | |
292 | * <p> | |
293 | * Adds a message resolver to the set of message resolvers to be used by the | |
294 | * template engine. | |
295 | * </p> | |
296 | * <p> | |
297 | * This operation can only be executed before processing templates for the | |
298 | * first time. Once a template is processed, the template engine is | |
299 | * considered to be <i>initialized</i>, and from then on any attempt to | |
300 | * change its configuration will result in an exception. | |
301 | * </p> | |
302 | * | |
303 | * @param messageResolver | |
304 | * the new message resolver to be added. | |
305 | * @return this for fluent use | |
306 | */ | |
307 | public MYSELF addMessageResolver(final IMessageResolver messageResolver) { | |
308 | messageResolvers().add(messageResolver); | |
309 |
1
1. addMessageResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::addMessageResolver → NO_COVERAGE |
return myself; |
310 | } | |
311 | ||
312 | /** | |
313 | * <p> | |
314 | * Sets a single message resolver for this template engine. | |
315 | * </p> | |
316 | * <p> | |
317 | * Calling this method is equivalent to calling | |
318 | * {@link #setMessageResolvers(Set)} passing a Set with only one message | |
319 | * resolver. | |
320 | * </p> | |
321 | * <p> | |
322 | * This operation can only be executed before processing templates for the | |
323 | * first time. Once a template is processed, the template engine is | |
324 | * considered to be <i>initialized</i>, and from then on any attempt to | |
325 | * change its configuration will result in an exception. | |
326 | * </p> | |
327 | * | |
328 | * @param messageResolver | |
329 | * the message resolver to be set. | |
330 | * @return this for fluent use | |
331 | */ | |
332 | public MYSELF setMessageResolver(final IMessageResolver messageResolver) { | |
333 |
1
1. setMessageResolver : removed call to java/util/Set::clear → NO_COVERAGE |
messageResolvers().clear(); |
334 | messageResolvers().add(messageResolver); | |
335 |
1
1. setMessageResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::setMessageResolver → NO_COVERAGE |
return myself; |
336 | } | |
337 | ||
338 | | |
339 | @Override | |
340 | public TemplateEngine build() { | |
341 | TemplateEngine engine = buildContext.register(new TemplateEngine()); | |
342 |
1
1. build : removed call to fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::configureDialects → NO_COVERAGE |
configureDialects(engine); |
343 |
1
1. build : removed call to fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::configureMessageResolvers → NO_COVERAGE |
configureMessageResolvers(engine); |
344 |
1
1. build : removed call to fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::configureTemplateResolvers → NO_COVERAGE |
configureTemplateResolvers(engine); |
345 |
1
1. build : removed call to fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::configureCacheManager → NO_COVERAGE |
configureCacheManager(engine); |
346 |
1
1. build : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::build → NO_COVERAGE |
return engine; |
347 | } | |
348 | ||
349 | protected void configureTemplateResolvers(TemplateEngine engine) { | |
350 |
1
1. configureTemplateResolvers : negated conditional → NO_COVERAGE |
if (templateResolvers != null) { |
351 |
1
1. configureTemplateResolvers : removed call to org/thymeleaf/TemplateEngine::setTemplateResolvers → NO_COVERAGE |
engine.setTemplateResolvers(templateResolvers); |
352 | } | |
353 | } | |
354 | ||
355 | protected void configureMessageResolvers(TemplateEngine engine) { | |
356 |
1
1. configureMessageResolvers : negated conditional → NO_COVERAGE |
if (messageResolvers != null) { |
357 |
1
1. configureMessageResolvers : removed call to org/thymeleaf/TemplateEngine::setMessageResolvers → NO_COVERAGE |
engine.setMessageResolvers(messageResolvers); |
358 | } | |
359 | } | |
360 | ||
361 | protected void configureCacheManager(TemplateEngine engine) { | |
362 |
1
1. configureCacheManager : negated conditional → NO_COVERAGE |
if (cacheManager != null) { |
363 |
1
1. configureCacheManager : removed call to org/thymeleaf/TemplateEngine::setCacheManager → NO_COVERAGE |
engine.setCacheManager(cacheManager); |
364 | } | |
365 | } | |
366 | ||
367 | protected void configureDialects(TemplateEngine engine) { | |
368 |
1
1. configureDialects : negated conditional → NO_COVERAGE |
if (dialects != null) { |
369 |
1
1. configureDialects : removed call to org/thymeleaf/TemplateEngine::setDialects → NO_COVERAGE |
engine.setDialects(dialects); |
370 | } | |
371 |
1
1. configureDialects : negated conditional → NO_COVERAGE |
if (dialectsByPrefix != null) { |
372 |
1
1. configureDialects : removed call to org/thymeleaf/TemplateEngine::setDialectsByPrefix → NO_COVERAGE |
engine.setDialectsByPrefix(dialectsByPrefix); |
373 | } | |
374 | } | |
375 | ||
376 | protected Set<IDialect> dialects() { | |
377 |
1
1. dialects : negated conditional → NO_COVERAGE |
if (dialects == null) { |
378 | dialects = new HashSet<>(); | |
379 | } | |
380 |
1
1. dialects : replaced return value with Collections.emptyList for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::dialects → NO_COVERAGE |
return dialects; |
381 | } | |
382 | ||
383 | protected Map<String, IDialect> dialectsByPrefix() { | |
384 |
1
1. dialectsByPrefix : negated conditional → NO_COVERAGE |
if (dialectsByPrefix == null) { |
385 | dialectsByPrefix = new HashMap<>(); | |
386 | } | |
387 |
1
1. dialectsByPrefix : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::dialectsByPrefix → NO_COVERAGE |
return dialectsByPrefix; |
388 | } | |
389 | ||
390 | protected Set<IMessageResolver> messageResolvers() { | |
391 |
1
1. messageResolvers : negated conditional → NO_COVERAGE |
if (messageResolvers == null) { |
392 | messageResolvers = new HashSet<>(); | |
393 | } | |
394 |
1
1. messageResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::messageResolvers → NO_COVERAGE |
return messageResolvers; |
395 | } | |
396 | ||
397 | protected Set<ITemplateResolver> templateResolvers() { | |
398 |
1
1. templateResolvers : negated conditional → NO_COVERAGE |
if (templateResolvers == null) { |
399 | templateResolvers = new HashSet<>(); | |
400 | } | |
401 |
1
1. templateResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/template/thymeleaf/common/buider/AbstractThymeleafEngineConfigBuilder::templateResolvers → NO_COVERAGE |
return templateResolvers; |
402 | } | |
403 | } | |
Mutations | ||
55 |
1.1 |
|
57 |
1.1 |
|
82 |
1.1 |
|
106 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
149 |
1.1 |
|
151 |
1.1 |
|
174 |
1.1 |
|
191 |
1.1 |
|
192 |
1.1 |
|
205 |
1.1 |
|
207 |
1.1 |
|
221 |
1.1 |
|
239 |
1.1 |
|
241 |
1.1 |
|
267 |
1.1 |
|
286 |
1.1 |
|
288 |
1.1 |
|
309 |
1.1 |
|
333 |
1.1 |
|
335 |
1.1 |
|
342 |
1.1 |
|
343 |
1.1 |
|
344 |
1.1 |
|
345 |
1.1 |
|
346 |
1.1 |
|
350 |
1.1 |
|
351 |
1.1 |
|
356 |
1.1 |
|
357 |
1.1 |
|
362 |
1.1 |
|
363 |
1.1 |
|
368 |
1.1 |
|
369 |
1.1 |
|
371 |
1.1 |
|
372 |
1.1 |
|
377 |
1.1 |
|
380 |
1.1 |
|
384 |
1.1 |
|
387 |
1.1 |
|
391 |
1.1 |
|
394 |
1.1 |
|
398 |
1.1 |
|
401 |
1.1 |