diff options
author | Alexander Alexeev | 2016-11-23 16:19:26 +0700 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-23 13:03:09 +0300 |
commit | e7fd58f1023ce9e1c9ab880bf27c5c0b2a3cffca (patch) | |
tree | 5ce36019dffc5f6eb4f71756a9f91068d5efbd54 /juick-spring-www/src/main/java/com/juick/www/configuration | |
parent | 37a171892ba11c578ea947103ee7488801785eac (diff) |
thymeleaf layout plugin used
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/configuration')
3 files changed, 56 insertions, 13 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java new file mode 100644 index 00000000..5fb7848d --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java @@ -0,0 +1,37 @@ +package com.juick.www.configuration; + +import com.juick.www.settings.TemplateSettingsHolder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.core.env.Environment; + +import javax.annotation.Resource; + +/** + * Created by aalexeev on 11/22/16. + */ +@Configuration +@PropertySource("classpath:juick.conf") +public class WebAppConfiguration { + @Resource + private Environment env; + + @Bean + public ResourceBundleMessageSource messageSource() { + ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); + + messageSource.setBasenames("messages", "errors"); + messageSource.setDefaultEncoding("UTF-8"); + messageSource.setFallbackToSystemLocale(false); + messageSource.setUseCodeAsDefaultMessage(true); + + return messageSource; + } + + @Bean + public TemplateSettingsHolder settingsHolder() { + return new TemplateSettingsHolder(env); + } +} diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java index 6abb9f79..d5a3bbef 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java @@ -16,7 +16,8 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{DataConfiguration.class, SearchConfiguration.class, WebSecurityConfig.class}; + return new Class<?>[]{ + WebAppConfiguration.class, DataConfiguration.class, SearchConfiguration.class, WebSecurityConfig.class}; } @Override diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 869fd651..089e43a8 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -2,11 +2,13 @@ package com.juick.www.configuration; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.juick.www.formatter.DateFormatter; +import nz.net.ultraq.thymeleaf.LayoutDialect; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -57,6 +59,9 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { // across different data types, so this flag is "false" by default // for safer backwards compatibility. templateEngine.setEnableSpringELCompiler(true); + // Thymeleaf Layout Dialect + templateEngine.addDialect(new LayoutDialect()); + return templateEngine; } @@ -93,17 +98,7 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { .addResourceLocations("/") .resourceChain(true) .addResolver(new PathResourceResolver()); - } - - @Bean - public ResourceBundleMessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - - messageSource.setBasenames("messages", "errors"); - messageSource.setDefaultEncoding("UTF-8"); - messageSource.setFallbackToSystemLocale(false); - - return messageSource; + registry.addResourceHandler("/static/**").addResourceLocations("/static/"); } @Override @@ -114,4 +109,14 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { return result; } + + @Override + public void addFormatters(final FormatterRegistry registry) { + registry.addFormatter(dateFormatter()); + } + + @Bean + public DateFormatter dateFormatter() { + return new DateFormatter(); + } } |