aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www/configuration
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/configuration')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java37
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java3
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java29
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();
+ }
}