AbstractDefaultThymeleafEmailConfigurer.java

1
package fr.sii.ogham.template.thymeleaf.common.configure;
2
3
import fr.sii.ogham.core.builder.MessagingBuilder;
4
import fr.sii.ogham.core.builder.configurer.DefaultMessagingConfigurer;
5
import fr.sii.ogham.core.builder.configurer.MessagingConfigurer;
6
import fr.sii.ogham.core.builder.configurer.MessagingConfigurerAdapter;
7
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
8
import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder;
9
import fr.sii.ogham.core.exception.configurer.ConfigureException;
10
import fr.sii.ogham.core.message.content.EmailVariant;
11
import fr.sii.ogham.template.thymeleaf.common.buider.AbstractThymeleafMultiContentBuilder;
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 90000 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.email.thymeleaf.classpath.path-prefix"</li>
45
 * <li>"ogham.email.template.classpath.path-prefix"</li>
46
 * <li>"ogham.email.thymeleaf.path-prefix"</li>
47
 * <li>"ogham.email.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.email.thymeleaf.classpath.path-suffix"</li>
54
 * <li>"ogham.email.template.classpath.path-suffix"</li>
55
 * <li>"ogham.email.thymeleaf.path-suffix"</li>
56
 * <li>"ogham.email.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.email.thymeleaf.file.path-prefix"</li>
63
 * <li>"ogham.email.template.file.path-prefix"</li>
64
 * <li>"ogham.email.thymeleaf.path-prefix"</li>
65
 * <li>"ogham.email.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.email.thymeleaf.file.path-suffix"</li>
72
 * <li>"ogham.email.template.file.path-suffix"</li>
73
 * <li>"ogham.email.thymeleaf.path-suffix"</li>
74
 * <li>"ogham.email.template.path-suffix"</li>
75
 * <li>"ogham.template.path-suffix"</li>
76
 * </ol>
77
 * </li>
78
 * </ul>
79
 * </li>
80
 * <li>Configures email alternative content:
81
 * <ul>
82
 * <li>Automatically loads HTML template if extension is .html</li>
83
 * <li>Automatically loads text template if extension is .txt</li>
84
 * </ul>
85
 * </li>
86
 * <li>Configures template detection:
87
 * <ul>
88
 * <li>Uses ThymeleafTemplateDetector to detect if templates are
89
 * parseable by Thymeleaf</li>
90
 * </ul>
91
 * </li>
92
 * </ul>
93
 * 
94
 * @author Aurélien Baudet
95
 *
96
 */
97
public abstract class AbstractDefaultThymeleafEmailConfigurer implements MessagingConfigurer {
98
	private final MessagingConfigurerAdapter delegate;
99
100
	public AbstractDefaultThymeleafEmailConfigurer() {
101
		this(new DefaultMessagingConfigurer());
102
	}
103
104
	public AbstractDefaultThymeleafEmailConfigurer(MessagingConfigurerAdapter delegate) {
105
		super();
106
		this.delegate = delegate;
107
	}
108
109
	@Override
110
	public void configure(MessagingBuilder msgBuilder) throws ConfigureException {
111 1 1. configure : removed call to fr/sii/ogham/template/thymeleaf/common/configure/AbstractDefaultThymeleafEmailConfigurer::checkCanUseThymeleaf → NO_COVERAGE
		checkCanUseThymeleaf();
112
113
		AbstractThymeleafMultiContentBuilder<?, ?, ?> builder = msgBuilder.email().template(getBuilderClass());
114
		// apply default resource resolution configuration
115 1 1. configure : negated conditional → NO_COVERAGE
		if (delegate != null) {
116 1 1. configure : removed call to fr/sii/ogham/core/builder/configurer/MessagingConfigurerAdapter::configure → NO_COVERAGE
			delegate.configure(builder);
117
		}
118
		// @formatter:off
119
		builder
120
			.classpath()
121
				.pathPrefix()
122
					.properties("${ogham.email.thymeleaf.classpath.path-prefix}", 
123
								"${ogham.email.template.classpath.path-prefix}", 
124
								"${ogham.email.thymeleaf.path-prefix}", 
125
								"${ogham.email.template.path-prefix}", 
126
								"${ogham.template.path-prefix}")
127
					.and()
128
				.pathSuffix()
129
					.properties("${ogham.email.thymeleaf.classpath.path-suffix}", 
130
								"${ogham.email.template.classpath.path-suffix}", 
131
								"${ogham.email.thymeleaf.path-suffix}", 
132
								"${ogham.email.template.path-suffix}", 
133
								"${ogham.template.path-suffix}")
134
					.and()
135
				.and()
136
			.file()
137
				.pathPrefix()
138
					.properties("${ogham.email.thymeleaf.file.path-prefix}", 
139
								"${ogham.email.template.file.path-prefix}", 
140
								"${ogham.email.thymeleaf.path-prefix}", 
141
								"${ogham.email.template.path-prefix}", 
142
								"${ogham.template.path-prefix}")
143
					.and()
144
				.pathSuffix()
145
					.properties("${ogham.email.thymeleaf.file.path-suffix}", 
146
								"${ogham.email.template.file.path-suffix}", 
147
								"${ogham.email.thymeleaf.path-suffix}", 
148
								"${ogham.email.template.path-suffix}", 
149
								"${ogham.template.path-suffix}")
150
					.and()
151
				.and()
152
			.string()
153
				.and()
154
			.variant(EmailVariant.HTML, "html")
155
			.variant(EmailVariant.HTML, "xhtml")
156
			.variant(EmailVariant.TEXT, "txt")
157
			.cache()
158
				.properties("${ogham.email.thymeleaf.cache}",
159
							"${ogham.email.template.cache}",
160
							"${ogham.template.cache}");
161
		// @formatter:on
162
	}
163
164
	protected abstract Class<? extends AbstractThymeleafMultiContentBuilder<?, ?, ?>> getBuilderClass();
165
166
	protected abstract void checkCanUseThymeleaf() throws ConfigureException;
167
168
}

Mutations

111

1.1
Location : configure
Killed by :
removed call to fr/sii/ogham/template/thymeleaf/common/configure/AbstractDefaultThymeleafEmailConfigurer::checkCanUseThymeleaf → NO_COVERAGE

115

1.1
Location : configure
Killed by :
negated conditional → NO_COVERAGE

116

1.1
Location : configure
Killed by :
removed call to fr/sii/ogham/core/builder/configurer/MessagingConfigurerAdapter::configure → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1