org.thymeleaf.templatemode.TemplateMode Java Examples
The following examples show how to use
org.thymeleaf.templatemode.TemplateMode.
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 |
@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: SpringMailTestConfiguration.java From konker-platform with Apache License 2.0 | 6 votes |
@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: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #4
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #5
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #6
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #7
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #8
Source File: MailNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@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 #9
Source File: TemplateUtilsTest.java From SkaETL with Apache License 2.0 | 6 votes |
@Test public void ashtml() { StringTemplateResolver templateResolver = new StringTemplateResolver(); templateResolver.setOrder(1); templateResolver.setTemplateMode(TemplateMode.HTML); // TODO Cacheable or Not ? templateResolver.setCacheable(false); TemplateEngine templateEngine = new TemplateEngine(); templateEngine.setTemplateResolver(templateResolver); Context context = new Context(); context.setVariable("mavar","cela"); String process = templateEngine.process("ceci [[${mavar}]]", context); assertThat(process).isEqualTo("ceci cela"); String variant = templateEngine.process("ceci <span th:text=\"${mavar}\"></span>", context); assertThat(variant).isEqualTo("ceci <span>cela</span>"); }
Example #10
Source File: TemplateUtilsTest.java From SkaETL with Apache License 2.0 | 6 votes |
@Test public void astext() { StringTemplateResolver templateResolver = new StringTemplateResolver(); templateResolver.setOrder(1); templateResolver.setTemplateMode(TemplateMode.TEXT); // TODO Cacheable or Not ? templateResolver.setCacheable(false); TemplateEngine templateEngine = new TemplateEngine(); templateEngine.setTemplateResolver(templateResolver); Context context = new Context(); context.setVariable("mavar","cela"); String process = templateEngine.process("ceci [[${mavar}]]", context); assertThat(process).isEqualTo("ceci cela"); String notInterpreted = templateEngine.process("ceci <span th:text=\"${mavar}\"></span>", context); assertThat(notInterpreted).isEqualTo("ceci <span th:text=\"${mavar}\"></span>"); }
Example #11
Source File: AdminServerNotifierAutoConfiguration.java From Moss with Apache License 2.0 | 5 votes |
@Bean public TemplateEngine mailNotifierTemplateEngine() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(this.applicationContext); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.addTemplateResolver(resolver); return templateEngine; }
Example #12
Source File: WebMvcConfig.java From spring-comparing-template-engines with Apache License 2.0 | 5 votes |
@Bean public SpringResourceTemplateResolver thymeleafTemplateResolver() { SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setApplicationContext(this.applicationContext); templateResolver.setPrefix("/WEB-INF/thymeleaf/"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode(TemplateMode.HTML); templateResolver.setCacheable(false); templateResolver.setCharacterEncoding("UTF-8"); return templateResolver; }
Example #13
Source File: AdminServerUiAutoConfiguration.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Bean public SpringResourceTemplateResolver adminTemplateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(this.applicationContext); resolver.setPrefix(this.adminUi.getTemplateLocation()); resolver.setSuffix(".html"); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); resolver.setCacheable(this.adminUi.isCacheTemplates()); resolver.setOrder(10); resolver.setCheckExistence(true); return resolver; }
Example #14
Source File: PrincipalElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public PrincipalElementProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching ELEMENT_NAME, // Tag name: match specifically this tag true, // Apply dialect prefix to tag name null, // No attribute name: will match by tag name false, // No prefix to be applied to attribute name PRECEDENCE); // Precedence (inside dialect's own precedence) }
Example #15
Source File: DataProcessor.java From thymeleaf-extras-data-attribute with Apache License 2.0 | 5 votes |
@Override public void process(ITemplateContext context, IProcessableElementTag tag, IElementTagStructureHandler structureHandler) { TemplateMode templateMode = getTemplateMode(); IAttribute[] attributes = tag.getAllAttributes(); for (IAttribute attribute : attributes) { AttributeName attributeName = attribute.getAttributeDefinition().getAttributeName(); if (attributeName.isPrefixed()) { if (TextUtil.equals(templateMode.isCaseSensitive(), attributeName.getPrefix(), dialectPrefix)) { processDataAttribute(context, tag, attribute, structureHandler); } } } }
Example #16
Source File: DataAttributeDialect.java From thymeleaf-extras-data-attribute with Apache License 2.0 | 5 votes |
@Override public Set<IProcessor> getProcessors(String dialectPrefix) { HashSet<IProcessor> processors = new HashSet<IProcessor>(); processors.add(new StandardXmlNsTagProcessor(TemplateMode.HTML, dialectPrefix)); processors.add(new DataProcessor(TemplateMode.HTML, dialectPrefix)); return processors; }
Example #17
Source File: LacksPermissionAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public LacksPermissionAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #18
Source File: WebMvcConfig.java From thymeleafexamples-layouts with Apache License 2.0 | 5 votes |
@Bean public ITemplateResolver templateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setPrefix(VIEWS); resolver.setSuffix(".html"); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding("UTF-8"); resolver.setCacheable(false); return resolver; }
Example #19
Source File: HasAnyRolesAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public HasAnyRolesAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #20
Source File: HasRoleAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public HasRoleAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #21
Source File: AdminServerNotifierAutoConfiguration.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Bean public TemplateEngine mailNotifierTemplateEngine() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(this.applicationContext); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.addTemplateResolver(resolver); return templateEngine; }
Example #22
Source File: UserAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public UserAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #23
Source File: GuestElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public GuestElementProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching ELEMENT_NAME, // Tag name: match specifically this tag true, // Apply dialect prefix to tag name null, // No attribute name: will match by tag name false, // No prefix to be applied to attribute name PRECEDENCE); // Precedence (inside dialect's own precedence) }
Example #24
Source File: HasAllRolesAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public HasAllRolesAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #25
Source File: PrincipalAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public PrincipalAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #26
Source File: AuthenticatedAttrProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public AuthenticatedAttrProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching null, // No tag name: match any tag name false, // No prefix to be applied to tag name ATTRIBUTE_NAME, // Name of the attribute that will be matched true, // Apply dialect prefix to attribute name PRECEDENCE, // Precedence (inside dialect's precedence) true); // Remove the matched attribute afterwards }
Example #27
Source File: TemplateEngineModule.java From EDDI with Apache License 2.0 | 5 votes |
private TemplateEngine createTemplateEngine(TemplateMode templateMode) { TemplateEngine templateEngine = new TemplateEngine(); StringTemplateResolver templateResolver = new StringTemplateResolver(); templateResolver.setTemplateMode(templateMode); templateEngine.addTemplateResolver(templateResolver); return templateEngine; }
Example #28
Source File: AbstractThymeleafShiroDialectTest.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
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); }
Example #29
Source File: LacksPermissionElementProcessor.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
public LacksPermissionElementProcessor(String dialectPrefix) { super( TemplateMode.HTML, // This processor will apply only to HTML mode dialectPrefix, // Prefix to be applied to name for matching ELEMENT_NAME, // Tag name: match specifically this tag true, // Apply dialect prefix to tag name null, // No attribute name: will match by tag name false, // No prefix to be applied to attribute name PRECEDENCE); // Precedence (inside dialect's own precedence) }
Example #30
Source File: Test.java From code with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // 1.上下文 Context context = new Context(); //创建数据模型 Map<String, Object> dataModel = new HashMap<String, Object>(1); dataModel.put("name", "青橙电商系统"); context.setVariables(dataModel); // 2.准备文件 File dest = new File("d:/test_out.html"); // 3.生成页面 try { PrintWriter writer = new PrintWriter(dest, "UTF-8"); //模板解析器 ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver(); //模板模型 resolver.setTemplateMode(TemplateMode.HTML); //后缀 resolver.setSuffix(".html"); //创建模板引擎 TemplateEngine engine = new TemplateEngine(); //设置模板解析器 engine.setTemplateResolver(resolver); //执行模板引擎 engine.process("test", context, writer); } catch (Exception e) { e.printStackTrace(); } }