| 1 | package fr.sii.ogham.template.thymeleaf.v2.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.context.BuildContext; | |
| 7 | import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder; | |
| 8 | import fr.sii.ogham.core.exception.configurer.ConfigureException; | |
| 9 | import fr.sii.ogham.core.exception.configurer.MissingImplementationException; | |
| 10 | import fr.sii.ogham.core.exception.configurer.NewerImplementationAvailableException; | |
| 11 | import fr.sii.ogham.core.util.ClasspathUtils; | |
| 12 | import fr.sii.ogham.template.thymeleaf.common.buider.AbstractThymeleafBuilder; | |
| 13 | import fr.sii.ogham.template.thymeleaf.common.configure.AbstractDefaultThymeleafSmsConfigurer; | |
| 14 | import fr.sii.ogham.template.thymeleaf.v2.ThymeleafV2TemplateDetector; | |
| 15 | import fr.sii.ogham.template.thymeleaf.v2.buider.ThymeleafV2SmsBuilder; | |
| 16 | ||
| 17 | import static fr.sii.ogham.template.thymeleaf.common.ThymeleafConstants.DEFAULT_THYMELEAF_SMS_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 70000 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.sms.thymeleaf.classpath.path-prefix"</li> | |
| 51 | * <li>"ogham.sms.template.classpath.path-prefix"</li> | |
| 52 | * <li>"ogham.sms.thymeleaf.path-prefix"</li> | |
| 53 | * <li>"ogham.sms.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.sms.thymeleaf.classpath.path-suffix"</li> | |
| 60 | * <li>"ogham.sms.template.classpath.path-suffix"</li> | |
| 61 | * <li>"ogham.sms.thymeleaf.path-suffix"</li> | |
| 62 | * <li>"ogham.sms.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.sms.thymeleaf.file.path-prefix"</li> | |
| 69 | * <li>"ogham.sms.template.file.path-prefix"</li> | |
| 70 | * <li>"ogham.sms.thymeleaf.path-prefix"</li> | |
| 71 | * <li>"ogham.sms.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.sms.thymeleaf.file.path-suffix"</li> | |
| 78 | * <li>"ogham.sms.template.file.path-suffix"</li> | |
| 79 | * <li>"ogham.sms.thymeleaf.path-suffix"</li> | |
| 80 | * <li>"ogham.sms.template.path-suffix"</li> | |
| 81 | * <li>"ogham.template.path-suffix"</li> | |
| 82 | * </ol> | |
| 83 | * </li> | |
| 84 | * </ul> | |
| 85 | * </li> | |
| 86 | * <li>Configures template detection: | |
| 87 | * <ul> | |
| 88 | * <li>Uses {@link ThymeleafV2TemplateDetector} 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 final class DefaultThymeleafV2SmsConfigurer { | |
| 98 | @ConfigurerFor(targetedBuilder = { "minimal", "standard" }, priority = DEFAULT_THYMELEAF_SMS_CONFIGURER_PRIORITY) | |
| 99 | public static class ThymeleafV2SmsConfigurer extends AbstractDefaultThymeleafSmsConfigurer { | |
| 100 | public ThymeleafV2SmsConfigurer() { | |
| 101 | super(); | |
| 102 | } | |
| 103 | ||
| 104 | @Override | |
| 105 | protected void checkCanUseThymeleaf() throws ConfigureException { | |
| 106 |
1
1. checkCanUseThymeleaf : negated conditional → NO_COVERAGE |
if (!isThymeleafV2Present()) { |
| 107 | throw new MissingImplementationException("Can't parse templates using Thymeleaf v2 engine because Thymeleaf v2 implementation is not present in the classpath", "org.thymeleaf.TemplateEngine"); | |
| 108 | } | |
| 109 |
1
1. checkCanUseThymeleaf : negated conditional → NO_COVERAGE |
if (isThymeleafV3Present()) { |
| 110 | throw new NewerImplementationAvailableException("Can't parse templates using Thymeleaf v2 engine because Thymeleaf v3 is present in the classpath. Therefore Thymeleaf v3 is preferred"); | |
| 111 | } | |
| 112 | } | |
| 113 | ||
| 114 | @Override | |
| 115 | protected Class<? extends AbstractThymeleafBuilder<?, ?, ?>> getBuilderClass() { | |
| 116 |
1
1. getBuilderClass : replaced return value with null for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2SmsConfigurer$ThymeleafV2SmsConfigurer::getBuilderClass → NO_COVERAGE |
return ThymeleafV2SmsBuilder.class; |
| 117 | } | |
| 118 | ||
| 119 | ||
| 120 | private static boolean isThymeleafV2Present() { | |
| 121 |
3
1. isThymeleafV2Present : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2SmsConfigurer$ThymeleafV2SmsConfigurer::isThymeleafV2Present → NO_COVERAGE 2. isThymeleafV2Present : negated conditional → NO_COVERAGE 3. isThymeleafV2Present : negated conditional → NO_COVERAGE |
return ClasspathUtils.exists("org.thymeleaf.TemplateEngine") && !ClasspathUtils.exists("org.thymeleaf.IEngineConfiguration"); |
| 122 | } | |
| 123 | ||
| 124 | private boolean isThymeleafV3Present() { | |
| 125 |
2
1. isThymeleafV3Present : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2SmsConfigurer$ThymeleafV2SmsConfigurer::isThymeleafV3Present → NO_COVERAGE 2. isThymeleafV3Present : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2SmsConfigurer$ThymeleafV2SmsConfigurer::isThymeleafV3Present → NO_COVERAGE |
return ClasspathUtils.exists("org.thymeleaf.IEngineConfiguration"); |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | private DefaultThymeleafV2SmsConfigurer() { | |
| 130 | super(); | |
| 131 | } | |
| 132 | } | |
Mutations | ||
| 106 |
1.1 |
|
| 109 |
1.1 |
|
| 116 |
1.1 |
|
| 121 |
1.1 2.2 3.3 |
|
| 125 |
1.1 2.2 |