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

The following examples show how to use org.thymeleaf.templateresolver.ClassLoaderTemplateResolver#setCharacterEncoding() . 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 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 2
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 3
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 4
Source File: ThymeleafConfig.java    From Project with Apache License 2.0 5 votes vote down vote up
@Bean
	public ClassLoaderTemplateResolver emailTemplateResolver() {
		ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
		templateResolver.setPrefix("/");
		templateResolver.setTemplateMode("HTML5");
		//减轻thymeleaf对HTML语法的疯狂检查
//	    templateResolver.setTemplateMode("LEGACYHTML5");
		templateResolver.setCharacterEncoding("UTF-8");
	    templateResolver.setOrder(1);
		return templateResolver;
	}
 
Example 5
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 6
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 7
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 8
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 9
Source File: SpringMailConfig.java    From konker-platform 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("/mail/");
	templateResolver.setSuffix(".txt");
	templateResolver.setTemplateMode(TemplateMode.TEXT);
	templateResolver.setCharacterEncoding("UTF-8");
	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: 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 12
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 13
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 14
Source File: AbstractThymeleafShiroDialectTest.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(Charsets.UTF_8.name());
    templateResolver.setTemplateMode(TemplateMode.HTML);

    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    final ShiroDialect dialect = new ShiroDialect();
    templateEngine.addDialect(dialect.getPrefix(), dialect);

}