| 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.AbstractThymeleafBuilder; | |
| 13 | import fr.sii.ogham.template.thymeleaf.common.configure.AbstractDefaultThymeleafSmsConfigurer; | |
| 14 | import fr.sii.ogham.template.thymeleaf.v3.ThymeleafV3TemplateDetector; | |
| 15 | import fr.sii.ogham.template.thymeleaf.v3.buider.ThymeleafV3SmsBuilder; | |
| 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 ap | |
| 21 | * {@link MessagingBuilder#standard()} or {@link MessagingBuilder#minimal()}. | |
| 22 | * | |
| 23 | * <p> | |
| 24 | * The configurer has a priority of 70000 in order to be applied after global | |
| 25 | * configurer but before any sender implementation. | |
| 26 | * </p> | |
| 27 | * | |
| 28 | * This configurer is applied only if {@code org.thymeleaf.TemplateEngine} is | |
| 29 | * present in the classpath. If not present, template engine is not registered | |
| 30 | * at all. | |
| 31 | * | |
| 32 | * <p> | |
| 33 | * This configurer inherits environment configuration (see | |
| 34 | * {@link BuildContext}). | |
| 35 | * </p> | |
| 36 | * <p> | |
| 37 | * It also copies resource resolution configuration of | |
| 38 | * {@link DefaultMessagingConfigurer} to inherit resource resolution lookups | |
| 39 | * (see {@link ResourceResolutionBuilder}). | |
| 40 | * </p> | |
| 41 | * | |
| 42 | * <p> | |
| 43 | * This configurer applies the following configuration: | |
| 44 | * <ul> | |
| 45 | * <li>Configures template prefix/suffix paths: | |
| 46 | * <ul> | |
| 47 | * <li>Uses the first property that has a value for classpath resolution prefix: | |
| 48 | * <ol> | |
| 49 | * <li>"ogham.sms.thymeleaf.classpath.path-prefix"</li> | |
| 50 | * <li>"ogham.sms.template.classpath.path-prefix"</li> | |
| 51 | * <li>"ogham.sms.thymeleaf.path-prefix"</li> | |
| 52 | * <li>"ogham.sms.template.path-prefix"</li> | |
| 53 | * <li>"ogham.template.path-prefix"</li> | |
| 54 | * </ol> | |
| 55 | * </li> | |
| 56 | * <li>Uses the first property that has a value for classpath resolution suffix: | |
| 57 | * <ol> | |
| 58 | * <li>"ogham.sms.thymeleaf.classpath.path-suffix"</li> | |
| 59 | * <li>"ogham.sms.template.classpath.path-suffix"</li> | |
| 60 | * <li>"ogham.sms.thymeleaf.path-suffix"</li> | |
| 61 | * <li>"ogham.sms.template.path-suffix"</li> | |
| 62 | * <li>"ogham.template.path-suffix"</li> | |
| 63 | * </ol> | |
| 64 | * </li> | |
| 65 | * <li>Uses the first property that has a value for file resolution prefix: | |
| 66 | * <ol> | |
| 67 | * <li>"ogham.sms.thymeleaf.file.path-prefix"</li> | |
| 68 | * <li>"ogham.sms.template.file.path-prefix"</li> | |
| 69 | * <li>"ogham.sms.thymeleaf.path-prefix"</li> | |
| 70 | * <li>"ogham.sms.template.path-prefix"</li> | |
| 71 | * <li>"ogham.template.path-prefix"</li> | |
| 72 | * </ol> | |
| 73 | * </li> | |
| 74 | * <li>Uses the first property that has a value for file resolution suffix: | |
| 75 | * <ol> | |
| 76 | * <li>"ogham.sms.thymeleaf.file.path-suffix"</li> | |
| 77 | * <li>"ogham.sms.template.file.path-suffix"</li> | |
| 78 | * <li>"ogham.sms.thymeleaf.path-suffix"</li> | |
| 79 | * <li>"ogham.sms.template.path-suffix"</li> | |
| 80 | * <li>"ogham.template.path-suffix"</li> | |
| 81 | * </ol> | |
| 82 | * </li> | |
| 83 | * </ul> | |
| 84 | * </li> | |
| 85 | * <li>Configures template detection: | |
| 86 | * <ul> | |
| 87 | * <li>Uses {@link ThymeleafV3TemplateDetector} to detect if templates are | |
| 88 | * parseable by Thymeleaf</li> | |
| 89 | * </ul> | |
| 90 | * </li> | |
| 91 | * </ul> | |
| 92 | * | |
| 93 | * @author Aurélien Baudet | |
| 94 | * | |
| 95 | */ | |
| 96 | public final class DefaultThymeleafV3SmsConfigurer { | |
| 97 | @ConfigurerFor(targetedBuilder = { "minimal", "standard" }, priority = DEFAULT_THYMELEAF_SMS_CONFIGURER_PRIORITY) | |
| 98 | public static class ThymeleafV3SmsConfigurer extends AbstractDefaultThymeleafSmsConfigurer { | |
| 99 | public ThymeleafV3SmsConfigurer() { | |
| 100 | super(); | |
| 101 | } | |
| 102 | ||
| 103 | public ThymeleafV3SmsConfigurer(MessagingConfigurerAdapter delegate) { | |
| 104 | super(delegate); | |
| 105 | } | |
| 106 | ||
| 107 | @Override | |
| 108 | protected void checkCanUseThymeleaf() throws ConfigureException { | |
| 109 |
1
1. checkCanUseThymeleaf : negated conditional → RUN_ERROR |
if (!isThymeleafV3Present()) { |
| 110 | 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"); | |
| 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/v3/configure/DefaultThymeleafV3SmsConfigurer$ThymeleafV3SmsConfigurer::getBuilderClass → RUN_ERROR |
return ThymeleafV3SmsBuilder.class; |
| 117 | } | |
| 118 | ||
| 119 | private static boolean isThymeleafV3Present() { | |
| 120 |
3
1. isThymeleafV3Present : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/configure/DefaultThymeleafV3SmsConfigurer$ThymeleafV3SmsConfigurer::isThymeleafV3Present → RUN_ERROR 2. isThymeleafV3Present : negated conditional → RUN_ERROR 3. isThymeleafV3Present : negated conditional → RUN_ERROR |
return ClasspathUtils.exists("org.thymeleaf.TemplateEngine") && ClasspathUtils.exists("org.thymeleaf.IEngineConfiguration"); |
| 121 | } | |
| 122 | } | |
| 123 | ||
| 124 | ||
| 125 | private DefaultThymeleafV3SmsConfigurer() { | |
| 126 | super(); | |
| 127 | } | |
| 128 | } | |
Mutations | ||
| 109 |
1.1 |
|
| 116 |
1.1 |
|
| 120 |
1.1 2.2 3.3 |