All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.sii.ogham.template.thymeleaf.configure.DefaultThymeleafSmsConfigurer Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package fr.sii.ogham.template.thymeleaf.configure;

import static fr.sii.ogham.template.thymeleaf.ThymeleafConstants.DEFAULT_THYMELEAF_SMS_CONFIGURER_PRIORITY;

import fr.sii.ogham.core.builder.MessagingBuilder;
import fr.sii.ogham.core.builder.configurer.ConfigurerFor;
import fr.sii.ogham.core.builder.configurer.DefaultMessagingConfigurer;
import fr.sii.ogham.core.builder.configurer.MessagingConfigurer;
import fr.sii.ogham.core.builder.configurer.MessagingConfigurerAdapter;
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder;
import fr.sii.ogham.core.util.ClasspathUtils;
import fr.sii.ogham.template.thymeleaf.ThymeleafTemplateDetector;
import fr.sii.ogham.template.thymeleaf.buider.ThymeleafEmailBuilder;
import fr.sii.ogham.template.thymeleaf.buider.ThymeleafSmsBuilder;

/**
 * Default configurer for Thymeleaf template engine that is automatically
 * applied every time a {@link MessagingBuilder} instance is created through
 * {@link MessagingBuilder#standard()} or {@link MessagingBuilder#minimal()}.
 * 
 * 

* The configurer has a priority of 70000 in order to be applied after global * configurer but before any sender implementation. *

* * This configurer is applied only if {@code org.thymeleaf.TemplateEngine} is * present in the classpath. If not present, template engine is not registered * at all. * *

* This configurer inherits environment configuration (see * {@link EnvironmentBuilder}, * {@link ThymeleafEmailBuilder#environment(EnvironmentBuilder)} and * {@link ThymeleafSmsBuilder#environment(EnvironmentBuilder)}). *

*

* It also copies resource resolution configuration of * {@link DefaultMessagingConfigurer} to inherit resource resolution lookups * (see {@link ResourceResolutionBuilder}). *

* *

* This configurer applies the following configuration: *

    *
  • Configures template prefix/suffix paths: *
      *
    • Uses the first property that has a value for classpath resolution prefix: *
        *
      1. "ogham.sms.thymeleaf.classpath.path-prefix"
      2. *
      3. "ogham.sms.template.classpath.path-prefix"
      4. *
      5. "ogham.sms.thymeleaf.path-prefix"
      6. *
      7. "ogham.sms.template.path-prefix"
      8. *
      9. "ogham.template.path-prefix"
      10. *
      *
    • *
    • Uses the first property that has a value for classpath resolution suffix: *
        *
      1. "ogham.sms.thymeleaf.classpath.path-suffix"
      2. *
      3. "ogham.sms.template.classpath.path-suffix"
      4. *
      5. "ogham.sms.thymeleaf.path-suffix"
      6. *
      7. "ogham.sms.template.path-suffix"
      8. *
      9. "ogham.template.path-suffix"
      10. *
      *
    • *
    • Uses the first property that has a value for file resolution prefix: *
        *
      1. "ogham.sms.thymeleaf.file.path-prefix"
      2. *
      3. "ogham.sms.template.file.path-prefix"
      4. *
      5. "ogham.sms.thymeleaf.path-prefix"
      6. *
      7. "ogham.sms.template.path-prefix"
      8. *
      9. "ogham.template.path-prefix"
      10. *
      *
    • *
    • Uses the first property that has a value for file resolution suffix: *
        *
      1. "ogham.sms.thymeleaf.file.path-suffix"
      2. *
      3. "ogham.sms.template.file.path-suffix"
      4. *
      5. "ogham.sms.thymeleaf.path-suffix"
      6. *
      7. "ogham.sms.template.path-suffix"
      8. *
      9. "ogham.template.path-suffix"
      10. *
      *
    • *
    *
  • *
  • Configures template detection: *
      *
    • Uses {@link ThymeleafTemplateDetector} to detect if templates are * parseable by Thymeleaf
    • *
    *
  • *
* * @author Aurélien Baudet * */ @ConfigurerFor(targetedBuilder = { "minimal", "standard" }, priority = DEFAULT_THYMELEAF_SMS_CONFIGURER_PRIORITY) public class DefaultThymeleafSmsConfigurer implements MessagingConfigurer { private final MessagingConfigurerAdapter delegate; public DefaultThymeleafSmsConfigurer() { this(new DefaultMessagingConfigurer()); } public DefaultThymeleafSmsConfigurer(MessagingConfigurerAdapter delegate) { super(); this.delegate = delegate; } @Override public void configure(MessagingBuilder msgBuilder) { if (canUseThymeleaf()) { ThymeleafSmsBuilder builder = msgBuilder.sms().template(ThymeleafSmsBuilder.class); // use same environment as parent builder builder.environment(msgBuilder.environment()); // apply default resource resolution configuration if (delegate != null) { delegate.configure(builder); } // @formatter:off builder .classpath() .pathPrefix("${ogham.sms.thymeleaf.classpath.path-prefix}", "${ogham.sms.template.classpath.path-prefix}", "${ogham.sms.thymeleaf.path-prefix}", "${ogham.sms.template.path-prefix}", "${ogham.template.path-prefix}") .pathSuffix("${ogham.sms.thymeleaf.classpath.path-suffix}", "${ogham.sms.template.classpath.path-suffix}", "${ogham.sms.thymeleaf.path-suffix}", "${ogham.sms.template.path-suffix}", "${ogham.template.path-suffix}") .and() .file() .pathPrefix("${ogham.sms.thymeleaf.file.path-prefix}", "${ogham.sms.template.file.path-prefix}", "${ogham.sms.thymeleaf.path-prefix}", "${ogham.sms.template.path-prefix}", "${ogham.template.path-prefix}") .pathSuffix("${ogham.sms.thymeleaf.file.path-suffix}", "${ogham.sms.template.file.path-suffix}", "${ogham.sms.thymeleaf.path-suffix}", "${ogham.sms.template.path-suffix}", "${ogham.template.path-suffix}"); // @formatter:on } } private boolean canUseThymeleaf() { return ClasspathUtils.exists("org.thymeleaf.TemplateEngine"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy