From 2013ca7c8a174962c2c298b832b0642b845e2eac Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 29 Mar 2017 13:32:10 +0300 Subject: juick-www: Springify Sape --- juick-www/src/main/java/com/juick/www/WebApp.java | 8 -------- .../com/juick/www/configuration/SapeConfiguration.java | 18 ++++++++++++++++++ .../com/juick/www/configuration/WwwInitializer.java | 3 ++- .../java/com/juick/www/controllers/PageTemplates.java | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 juick-www/src/main/java/com/juick/www/configuration/SapeConfiguration.java (limited to 'juick-www/src/main/java') diff --git a/juick-www/src/main/java/com/juick/www/WebApp.java b/juick-www/src/main/java/com/juick/www/WebApp.java index 2f73229e..2d95cb85 100644 --- a/juick-www/src/main/java/com/juick/www/WebApp.java +++ b/juick-www/src/main/java/com/juick/www/WebApp.java @@ -35,14 +35,12 @@ import rocks.xmpp.core.session.Extension; import rocks.xmpp.core.session.XmppSessionConfiguration; import rocks.xmpp.core.session.debug.LogbackDebugger; import rocks.xmpp.extensions.component.accept.ExternalComponent; -import ru.sape.Sape; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; import java.util.stream.Stream; /** @@ -74,12 +72,6 @@ public class WebApp implements AutoCloseable { setupXmppComponent(Jid.of(env.getProperty("www_xmpp_jid", "www.juick.local")), env.getProperty("xmpp_password"), NumberUtils.toInt(env.getProperty("xmpp_port", StringUtils.EMPTY), 5347)); } - String sapeUser = env.getProperty("sape_user", StringUtils.EMPTY); - if (!Objects.equals(sapeUser, StringUtils.EMPTY)) { - templates.sape = new Sape(sapeUser, "juick.com", 2000, 3600); - } else { - logger.error("Sape is not initialized"); - } } @Override diff --git a/juick-www/src/main/java/com/juick/www/configuration/SapeConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/SapeConfiguration.java new file mode 100644 index 00000000..fe1bce60 --- /dev/null +++ b/juick-www/src/main/java/com/juick/www/configuration/SapeConfiguration.java @@ -0,0 +1,18 @@ +package com.juick.www.configuration; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import ru.sape.Sape; + +/** + * Created by vitalyster on 29.03.2017. + */ +public class SapeConfiguration { + @Value("${sape_user}") + private String token; + + @Bean + public Sape sape() { + return new Sape(token, "juick.com", 2000, 3600); + } +} diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java index 0e185447..204d8c6c 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java @@ -20,7 +20,8 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni return new Class[]{ WwwAppConfiguration.class, DataConfiguration.class, - SearchConfiguration.class + SearchConfiguration.class, + SapeConfiguration.class }; } diff --git a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java index c8e31729..3ea811a1 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java +++ b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java @@ -49,7 +49,8 @@ public class PageTemplates { private static final Logger logger = LoggerFactory.getLogger(PageTemplates.class); - public Sape sape = null; + @Inject + private Sape sape; protected static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM"); private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy"); -- cgit v1.2.3