DefaultThymeleafV3EmailConfigurer.java

1
package fr.sii.ogham.template.thymeleaf.v3.configure;
2
3
import fr.sii.ogham.core.builder.MessagingBuilder;
4
import fr.sii.ogham.core.builder.configurer.ConfigurerFor;
5
import fr.sii.ogham.core.builder.configurer.DefaultMessagingConfigurer;
6
import fr.sii.ogham.core.builder.configurer.MessagingConfigurerAdapter;
7
import fr.sii.ogham.core.builder.context.BuildContext;
8
import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder;
9
import fr.sii.ogham.core.exception.configurer.ConfigureException;
10
import fr.sii.ogham.core.exception.configurer.MissingImplementationException;
11
import fr.sii.ogham.core.util.ClasspathUtils;
12
import fr.sii.ogham.template.thymeleaf.common.buider.AbstractThymeleafMultiContentBuilder;
13
import fr.sii.ogham.template.thymeleaf.common.configure.AbstractDefaultThymeleafEmailConfigurer;
14
import fr.sii.ogham.template.thymeleaf.v3.ThymeleafV3TemplateDetector;
15
import fr.sii.ogham.template.thymeleaf.v3.buider.ThymeleafV3EmailBuilder;
16
17
import static fr.sii.ogham.template.thymeleaf.common.ThymeleafConstants.DEFAULT_THYMELEAF_EMAIL_CONFIGURER_PRIORITY;
18
19
/**
20
 * Default configurer for Thymeleaf template engine that is automatically
21
 * applied every time a {@link MessagingBuilder} instance is created through
22
 * {@link MessagingBuilder#standard()} or {@link MessagingBuilder#minimal()}.
23
 * 
24
 * <p>
25
 * The configurer has a priority of 90000 in order to be applied after global
26
 * configurer but before any sender implementation.
27
 * </p>
28
 * 
29
 * This configurer is applied only if {@code org.thymeleaf.TemplateEngine} is
30
 * present in the classpath. If not present, template engine is not registered
31
 * at all.
32
 * 
33
 * <p>
34
 * This configurer inherits environment configuration (see
35
 * {@link BuildContext}).
36
 * </p>
37
 * <p>
38
 * It also copies resource resolution configuration of
39
 * {@link DefaultMessagingConfigurer} to inherit resource resolution lookups
40
 * (see {@link ResourceResolutionBuilder}).
41
 * </p>
42
 * 
43
 * <p>
44
 * This configurer applies the following configuration:
45
 * <ul>
46
 * <li>Configures template prefix/suffix paths:
47
 * <ul>
48
 * <li>Uses the first property that has a value for classpath resolution prefix:
49
 * <ol>
50
 * <li>"ogham.email.thymeleaf.classpath.path-prefix"</li>
51
 * <li>"ogham.email.template.classpath.path-prefix"</li>
52
 * <li>"ogham.email.thymeleaf.path-prefix"</li>
53
 * <li>"ogham.email.template.path-prefix"</li>
54
 * <li>"ogham.template.path-prefix"</li>
55
 * </ol>
56
 * </li>
57
 * <li>Uses the first property that has a value for classpath resolution suffix:
58
 * <ol>
59
 * <li>"ogham.email.thymeleaf.classpath.path-suffix"</li>
60
 * <li>"ogham.email.template.classpath.path-suffix"</li>
61
 * <li>"ogham.email.thymeleaf.path-suffix"</li>
62
 * <li>"ogham.email.template.path-suffix"</li>
63
 * <li>"ogham.template.path-suffix"</li>
64
 * </ol>
65
 * </li>
66
 * <li>Uses the first property that has a value for file resolution prefix:
67
 * <ol>
68
 * <li>"ogham.email.thymeleaf.file.path-prefix"</li>
69
 * <li>"ogham.email.template.file.path-prefix"</li>
70
 * <li>"ogham.email.thymeleaf.path-prefix"</li>
71
 * <li>"ogham.email.template.path-prefix"</li>
72
 * <li>"ogham.template.path-prefix"</li>
73
 * </ol>
74
 * </li>
75
 * <li>Uses the first property that has a value for file resolution suffix:
76
 * <ol>
77
 * <li>"ogham.email.thymeleaf.file.path-suffix"</li>
78
 * <li>"ogham.email.template.file.path-suffix"</li>
79
 * <li>"ogham.email.thymeleaf.path-suffix"</li>
80
 * <li>"ogham.email.template.path-suffix"</li>
81
 * <li>"ogham.template.path-suffix"</li>
82
 * </ol>
83
 * </li>
84
 * </ul>
85
 * </li>
86
 * <li>Configures email alternative content:
87
 * <ul>
88
 * <li>Automatically loads HTML template if extension is .html</li>
89
 * <li>Automatically loads text template if extension is .txt</li>
90
 * </ul>
91
 * </li>
92
 * <li>Configures template detection:
93
 * <ul>
94
 * <li>Uses {@link ThymeleafV3TemplateDetector} to detect if templates are
95
 * parseable by Thymeleaf</li>
96
 * </ul>
97
 * </li>
98
 * </ul>
99
 * 
100
 * @author Aurélien Baudet
101
 *
102
 */
103
public final class DefaultThymeleafV3EmailConfigurer {
104
105
	@ConfigurerFor(targetedBuilder = { "minimal", "standard" }, priority = DEFAULT_THYMELEAF_EMAIL_CONFIGURER_PRIORITY)
106
	public static class ThymeleafV3EmailConfigurer extends AbstractDefaultThymeleafEmailConfigurer {
107
		public ThymeleafV3EmailConfigurer() {
108
			super();
109
		}
110
111
		public ThymeleafV3EmailConfigurer(MessagingConfigurerAdapter delegate) {
112
			super(delegate);
113
		}
114
115
		@Override
116
		protected void checkCanUseThymeleaf() throws ConfigureException {
117 1 1. checkCanUseThymeleaf : negated conditional → RUN_ERROR
			if (!isThymeleafV3Present()) {
118
				throw new MissingImplementationException("Can't parse templates using Thymeleaf v3 engine because Thymeleaf v3 implementation is not present in the classpath", "org.thymeleaf.TemplateEngine", "org.thymeleaf.IEngineConfiguration");
119
			}
120
		}
121
122
		@Override
123
		protected Class<? extends AbstractThymeleafMultiContentBuilder<?, ?, ?>> getBuilderClass() {
124 1 1. getBuilderClass : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/configure/DefaultThymeleafV3EmailConfigurer$ThymeleafV3EmailConfigurer::getBuilderClass → RUN_ERROR
			return ThymeleafV3EmailBuilder.class;
125
		}
126
127
		private static boolean isThymeleafV3Present() {
128 3 1. isThymeleafV3Present : negated conditional → RUN_ERROR
2. isThymeleafV3Present : negated conditional → RUN_ERROR
3. isThymeleafV3Present : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/configure/DefaultThymeleafV3EmailConfigurer$ThymeleafV3EmailConfigurer::isThymeleafV3Present → RUN_ERROR
			return ClasspathUtils.exists("org.thymeleaf.TemplateEngine") && ClasspathUtils.exists("org.thymeleaf.IEngineConfiguration");
129
		}
130
	}
131
132
133
	private DefaultThymeleafV3EmailConfigurer() {
134
		super();
135
	}
136
}

Mutations

117

1.1
Location : checkCanUseThymeleaf
Killed by :
negated conditional → RUN_ERROR

124

1.1
Location : getBuilderClass
Killed by :
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/configure/DefaultThymeleafV3EmailConfigurer$ThymeleafV3EmailConfigurer::getBuilderClass → RUN_ERROR

128

1.1
Location : isThymeleafV3Present
Killed by :
negated conditional → RUN_ERROR

2.2
Location : isThymeleafV3Present
Killed by :
negated conditional → RUN_ERROR

3.3
Location : isThymeleafV3Present
Killed by :
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/configure/DefaultThymeleafV3EmailConfigurer$ThymeleafV3EmailConfigurer::isThymeleafV3Present → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1