Java Code Examples for org.thymeleaf.templateresolver.ClassLoaderTemplateResolver#setTemplateMode()

The following examples show how to use org.thymeleaf.templateresolver.ClassLoaderTemplateResolver#setTemplateMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailNotifierTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() {
	repository = mock(InstanceRepository.class);
	when(repository.find(instance.getId())).thenReturn(Mono.just(instance));

	sender = mock(JavaMailSender.class);
	when(sender.createMimeMessage()).thenAnswer((args) -> new MimeMessage(Session.getInstance(new Properties())));

	SpringTemplateEngine templateEngine = new SpringTemplateEngine();
	ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
	resolver.setTemplateMode(TemplateMode.HTML);
	resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
	templateEngine.addTemplateResolver(resolver);

	notifier = new MailNotifier(sender, repository, templateEngine);
	notifier.setTo(new String[] { "[email protected]" });
	notifier.setCc(new String[] { "[email protected]" });
	notifier.setFrom("SBA <[email protected]>");
	notifier.setBaseUrl("http://localhost:8080");
	notifier.setTemplate("/META-INF/spring-boot-admin-server/mail/status-changed.html");
}
 
Example 2
Source File: SwaggerMappingSupport.java    From swagger with Apache License 2.0 6 votes vote down vote up
public SwaggerMappingSupport(ServletContext servletContext, String urlPatternMapping) throws ServletException {
    this.contextPath = servletContext.getContextPath();
    urlPrefix = contextPath + urlPatternMapping;
    urlPrefix = urlPrefix.replaceAll("/{2,}", "/");
    if (!"/".equals(urlPrefix) && urlPrefix.endsWith("/")) {
        urlPrefix = urlPrefix.substring(0, urlPrefix.length() - 1);
    }
    requestMatchers = Arrays.stream(RESOURCE_PATTERNS)
            .map(pattern -> String.join("/", this.contextPath, urlPatternMapping, pattern))
            .map(pattern -> pattern.replaceAll("/{2,}", "/"))
            .map(pattern -> new AntPathRequestMatcher(pattern, HttpMethod.GET.name()))
            .collect(Collectors.toList());

    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(SwaggerFilter.class.getClassLoader());
    templateResolver.setPrefix(TEMPLATES_PATH + "/");
    templateResolver.setTemplateMode(TemplateMode.HTML);
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    this.templateEngine = templateEngine;
}
 
Example 3
Source File: SpringMailTestConfiguration.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
@Bean
  public SpringTemplateEngine templateEngine() {
  	SpringTemplateEngine mock = spy(SpringTemplateEngine.class);
  	
  	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(2);
templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
templateResolver.setPrefix("/mail/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(false);
  	mock.addTemplateResolver(templateResolver);
  	
  	final ClassLoaderTemplateResolver templateResolverTxt = new ClassLoaderTemplateResolver();
templateResolverTxt.setOrder(1);
templateResolverTxt.setResolvablePatterns(Collections.singleton("text/*"));
templateResolverTxt.setPrefix("/mail/");
templateResolverTxt.setSuffix(".txt");
templateResolverTxt.setTemplateMode(TemplateMode.TEXT);
templateResolverTxt.setCharacterEncoding("UTF-8");
templateResolverTxt.setCacheable(false);
mock.addTemplateResolver(templateResolverTxt);
  	
return mock;
  }
 
Example 4
Source File: MailNotifierTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    repository = mock(InstanceRepository.class);
    when(repository.find(instance.getId())).thenReturn(Mono.just(instance));

    sender = mock(JavaMailSender.class);
    when(sender.createMimeMessage()).thenAnswer(args -> new MimeMessage(Session.getInstance(new Properties())));

    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setTemplateMode(TemplateMode.HTML);
    resolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
    templateEngine.addTemplateResolver(resolver);

    notifier = new MailNotifier(sender, repository, templateEngine);
    notifier.setTo(new String[]{"[email protected]"});
    notifier.setCc(new String[]{"[email protected]"});
    notifier.setFrom("SBA <[email protected]>");
    notifier.setBaseUrl("http://localhost:8080");
    notifier.setTemplate("/META-INF/spring-boot-admin-server/mail/status-changed.html");
}
 
Example 5
Source File: ThymeleafConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver defaultTemplateResolver() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setPrefix("/views/");
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML");
    return templateResolver;
}
 
Example 6
Source File: ThymeleafTemplateEngine.java    From spark-template-engines with Apache License 2.0 5 votes vote down vote up
private static ITemplateResolver createDefaultTemplateResolver(String prefix, String suffix) {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode(TemplateMode.HTML);

    templateResolver.setPrefix(
            prefix != null ? prefix : DEFAULT_PREFIX
    );

    templateResolver.setSuffix(
            suffix != null ? suffix : DEFAULT_SUFFIX
    );

    templateResolver.setCacheTTLMs(DEFAULT_CACHE_TTL_MS);
    return templateResolver;
}
 
Example 7
Source File: Config.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ITemplateResolver templateResolver() {
    ClassLoaderTemplateResolver resolver 
        = new ClassLoaderTemplateResolver();
    resolver.setPrefix("templates/sessionattrs/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode(TemplateMode.HTML);
    resolver.setCharacterEncoding("UTF-8");
    return resolver;
}
 
Example 8
Source File: ThymeleafTemplateProcessorImpl.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public ThymeleafTemplateProcessorImpl() {
  final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
  templateResolver.setTemplateMode(HTML);
  templateResolver.setSuffix(".html");
  templateResolver.setCacheTTLMs(3600000L);
  this.templateEngine = new TemplateEngine();
  this.templateEngine.setTemplateResolver(templateResolver);
}
 
Example 9
Source File: SpringMailConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver stringTemplateResolver() {
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setOrder(3);
	templateResolver.setTemplateMode(TemplateMode.HTML5);
	templateResolver.setCacheable(false);
	return templateResolver;
}
 
Example 10
Source File: SpringMailConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver htmlTemplateResolver() {
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setOrder(2);
	templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
	templateResolver.setPrefix("/mail/");
	templateResolver.setSuffix(".html");
	templateResolver.setTemplateMode(TemplateMode.HTML);
	templateResolver.setCharacterEncoding("UTF-8");
	templateResolver.setCacheable(false);
	return templateResolver;
}
 
Example 11
Source File: ShiroDialectTest.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
private static void setupThymeleaf() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setCacheable(false);
    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setTemplateMode(TemplateMode.HTML);

    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    templateEngine.addDialect("shiro", new ShiroDialect());

}
 
Example 12
Source File: ThymeleafConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver defaultTemplateResolver() {
    ClassLoaderTemplateResolver templateResolver = new CustomClassLoaderTemplateResolver();
    templateResolver.setPrefix("/webroot/views/");
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML");
    return templateResolver;
}
 
Example 13
Source File: ThymeleafTemplateEngine.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
private ITemplateResolver createDefaultTemplateResolver() {
    if (classLoader == null) {
        classLoader = Thread.currentThread().getContextClassLoader();
    }
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver(classLoader);
    resolver.setTemplateMode(TemplateMode.HTML);
    resolver.setPrefix(prefix);
    resolver.setSuffix(suffix);
    resolver.setCharacterEncoding(encoding);
    return resolver;
}
 
Example 14
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver jsTemplateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setOrder(3);
    templateResolver.setResolvablePatterns(Collections.singleton("js/*"));
    templateResolver.setPrefix(TEMPLATE_PREFIX);
    templateResolver.setSuffix(".js");
    templateResolver.setTemplateMode(TemplateMode.JAVASCRIPT);
    templateResolver.setCharacterEncoding(TEMPLATE_ENCODING);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example 15
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver htmlTemplateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setOrder(2);
    templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
    templateResolver.setPrefix(TEMPLATE_PREFIX);
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setCharacterEncoding(TEMPLATE_ENCODING);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example 16
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver textTemplateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setOrder(1);
    templateResolver.setResolvablePatterns(Collections.singleton("text/*"));
    templateResolver.setPrefix(TEMPLATE_PREFIX);
    templateResolver.setSuffix(".txt");
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    templateResolver.setCharacterEncoding(TEMPLATE_ENCODING);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example 17
Source File: GithubPullRequestReporter.java    From cover-checker with Apache License 2.0 5 votes vote down vote up
private void templateInit() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    templateResolver.setPrefix("/templates/");
    templateResolver.setSuffix(".md");
    templateResolver.setCacheable(false);

    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
}
 
Example 18
Source File: MailUtils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
* Formate common fix body.
*
* @param silentautoFixTrans the silentauto fix trans
* @param ruleParam the rule param
* @param resourceOwner the resource owner
* @return the string
*/
public static String formateCommonFixBody(List<AutoFixTransaction> silentautoFixTrans,Map<String, String> ruleParam,ResourceOwner resourceOwner) {
    TemplateEngine templateEngine = new TemplateEngine();
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode("HTML");
    templateResolver.setSuffix(".html");
    templateEngine.setTemplateResolver(templateResolver);
    
    List<String> columnsList = Arrays.asList(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_MAIL_TEMPLATE_COLUMNS
            + ruleParam.get(PacmanSdkConstants.RULE_ID)).split("\\s*,\\s*"));
   
    Context context = new Context(); 
  
    context.setVariable("columns", columnsList);
    context.setVariable("resources", silentautoFixTrans);
    String policyUrl = getPolicyKnowledgeBasePathURL(ruleParam);
    String name =CommonUtils.getPropValue(PacmanSdkConstants.SEND_EMAIL_SILENT_FIX_ADMIN
            + ruleParam.get(PacmanSdkConstants.RULE_ID));
    
    if(StringUtils.isNullOrEmpty(name)){
  	 name = resourceOwner.getName(); 
    }
    String postFixMessage = CommonUtils.getPropValue(PacmanSdkConstants.EMAIL_FIX_MESSAGE_PREFIX
            + ruleParam.get(PacmanSdkConstants.RULE_ID));
    context.setVariable("AUTOFIX_POST_FIX_MESSAGE", postFixMessage);
    context.setVariable("POLICY_URL", policyUrl);
    context.setVariable("NAME", "Hello "+name);
    context.setVariable("RESOURCE_TYPE", " Resource Type : "+ruleParam.get(PacmanSdkConstants.TARGET_TYPE));
    context.setVariable("AUTO_FIX_APPLIED", "Total AutoFixs Applied : "+silentautoFixTrans.size());
    StringWriter writer = new StringWriter();
    
  if(CommonUtils.getPropValue("pacman.auto.fix.common.email.notifications."
            + ruleParam.get(PacmanSdkConstants.RULE_ID)).equals("commonTemplate")){
    	templateEngine.process("/template/autofix-user-notification-action-common.html", context, writer);
}else{
    	templateEngine.process("/template/autofix-silent-autodelete-usernotification-info.html", context, writer);
    }
    return writer.toString();
    
}
 
Example 19
Source File: Config.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ITemplateResolver templateResolver() {
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setPrefix("templates/books/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode(TemplateMode.HTML);
    resolver.setCharacterEncoding("UTF-8");
    return resolver;
}
 
Example 20
Source File: PDFThymeleafUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
private String parseThymeleafTemplate() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode(TemplateMode.HTML);

    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context context = new Context();
    context.setVariable("to", "Baeldung.com");

    return templateEngine.process("thymeleaf_template", context);
}