diff options
Diffstat (limited to 'juick-spring-www/src/main/java/com')
3 files changed, 13 insertions, 41 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 index a6632289..28a0f29a 100644 --- 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 @@ -2,7 +2,6 @@ package com.juick.www.configuration; import com.juick.www.HelpService; import com.juick.www.WebApp; -import com.juick.www.settings.TemplateSettingsHolder; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.guava.GuavaCacheManager; import org.springframework.cache.interceptor.KeyGenerator; @@ -38,11 +37,6 @@ public class WebAppConfiguration { } @Bean - public TemplateSettingsHolder settingsHolder() { - return new TemplateSettingsHolder(env); - } - - @Bean public WebApp webApp() { return new WebApp(env); } 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 8da3321e..15f85c9a 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 @@ -4,10 +4,12 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.www.formatter.SpringDateFormatter; import nz.net.ultraq.thymeleaf.LayoutDialect; +import org.apache.commons.lang3.BooleanUtils; 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.core.env.Environment; import org.springframework.format.FormatterRegistry; import org.springframework.http.CacheControl; import org.springframework.http.converter.HttpMessageConverter; @@ -25,6 +27,7 @@ import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templatemode.TemplateMode; +import javax.annotation.Resource; import java.util.List; import java.util.concurrent.TimeUnit; @@ -35,6 +38,8 @@ import java.util.concurrent.TimeUnit; @ComponentScan(basePackages = {"com.juick.www.controllers"}) @PropertySource("classpath:juick.conf") public class WwwServletConfiguration extends WebMvcConfigurationSupport { + @Resource + private Environment env; @Bean public SpringResourceTemplateResolver templateResolver() { @@ -79,6 +84,14 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine()); viewResolver.setCharacterEncoding("UTF-8"); + + viewResolver.addStaticVariable( + "showSape", BooleanUtils.toBoolean(env.getProperty("template.showSape", "true"))); + viewResolver.addStaticVariable( + "showAdv", BooleanUtils.toBoolean(env.getProperty("template.showAdv", "true"))); + viewResolver.addStaticVariable( + "showSponsors", BooleanUtils.toBoolean(env.getProperty("template.showSponsors", "false"))); + return viewResolver; } diff --git a/juick-spring-www/src/main/java/com/juick/www/settings/TemplateSettingsHolder.java b/juick-spring-www/src/main/java/com/juick/www/settings/TemplateSettingsHolder.java deleted file mode 100644 index c6df73da..00000000 --- a/juick-spring-www/src/main/java/com/juick/www/settings/TemplateSettingsHolder.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.juick.www.settings; - -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.springframework.core.env.Environment; - -/** - * Created by aalexeev on 11/22/16. - */ -public class TemplateSettingsHolder { - private final boolean showSponsors; - private final boolean showSape; - - - public TemplateSettingsHolder(Environment settingsEnv) { - showSponsors = BooleanUtils.toBoolean(settingsEnv.getProperty("template.showSponsors", "false")); - showSape = BooleanUtils.toBoolean(settingsEnv.getProperty("template.showSape", "true")); - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("showSponsors", showSponsors) - .append("showSape", showSape) - .toString(); - } - - public boolean isShowSponsors() { - return showSponsors; - } - - public boolean isShowSape() { - return showSape; - } -} |