aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/WebApp.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/WebApp.java')
-rw-r--r--juick-www/src/main/java/com/juick/www/WebApp.java65
1 files changed, 43 insertions, 22 deletions
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 72eb3fbc..6d809245 100644
--- a/juick-www/src/main/java/com/juick/www/WebApp.java
+++ b/juick-www/src/main/java/com/juick/www/WebApp.java
@@ -20,14 +20,10 @@ package com.juick.www;
import com.juick.Message;
import com.juick.Tag;
import com.juick.service.TagService;
-import com.juick.service.UserService;
-import com.juick.www.controllers.PageTemplates;
-import org.apache.commons.lang3.BooleanUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.env.Environment;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.annotation.Value;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.XmppException;
import rocks.xmpp.core.session.Extension;
@@ -35,6 +31,8 @@ import rocks.xmpp.core.session.XmppSessionConfiguration;
import rocks.xmpp.core.session.debug.LogbackDebugger;
import rocks.xmpp.extensions.component.accept.ExternalComponent;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -44,35 +42,42 @@ import java.util.stream.Stream;
*
* @author Ugnich Anton
*/
-public class WebApp implements AutoCloseable {
+public class WebApp implements DisposableBean {
private static Logger logger = LoggerFactory.getLogger(WebApp.class);
private ExternalComponent xmpp;
- Environment env;
- PageTemplates templates;
- UserService userService;
+ @Inject
TagService tagService;
+ @Value("${img_path:/var/www/juick.com/i/}")
private String imgDir;
+ @Value("${upload_tmp_dir:/var/www/juick.com/i/tmp/}")
private String tmpDir;
+ @Value("${xmpp_host:localhost}")
+ private String xmppHost;
+ @Value("${xmpp_password:secret}")
+ private String xmppPassword;
+ @Value("${www_xmpp_jid:www.juick.local}")
+ private String xmppJid;
+ @Value("${xmpp_port:5347}")
+ private int xmppPort;
+ @Value("${xmpp_disabled:false}")
+ private boolean isXmppDisabled;
- public WebApp(Environment env, PageTemplates templates, UserService userService, TagService tagService) {
- this.env = env;
- this.templates = templates;
- this.userService = userService;
- this.tagService = tagService;
- tmpDir = env.getProperty("upload_tmp_dir", "/var/www/juick.com/i/tmp/");
- imgDir = env.getProperty("img_path", "/var/www/juick.com/i/");
- boolean isXmppDisabled = BooleanUtils.toBoolean(env.getProperty("xmpp_disabled"));
+ private String scriptsUrl;
+ private String styleUrl;
+
+ @PostConstruct
+ public void init() {
if (!isXmppDisabled) {
- setupXmppComponent(Jid.of(env.getProperty("www_xmpp_jid", "www.juick.local")),
- env.getProperty("xmpp_password"), NumberUtils.toInt(env.getProperty("xmpp_port", StringUtils.EMPTY), 5347));
+ setupXmppComponent(Jid.of(xmppJid),
+ xmppPassword, xmppPort);
}
}
@Override
- public void close() {
+ public void destroy() {
try {
if (xmpp != null)
xmpp.close();
@@ -87,7 +92,7 @@ public class WebApp implements AutoCloseable {
.extensions(Extension.of(Message.class))
.debugger(LogbackDebugger.class)
.build();
- xmpp = ExternalComponent.create(componentJid.toString(), password, configuration, "localhost", port);
+ xmpp = ExternalComponent.create(componentJid.toString(), password, configuration, xmppHost, port);
xmpp.addConnectionListener(e -> logger.error(e.toString(), e.getCause()));
try {
xmpp.connect();
@@ -128,4 +133,20 @@ public class WebApp implements AutoCloseable {
}
return tags;
}
+
+ public String getStyleUrl() {
+ return styleUrl;
+ }
+
+ public String getScriptsUrl() {
+ return scriptsUrl;
+ }
+
+ public void setScriptsUrl(String scriptsUrl) {
+ this.scriptsUrl = scriptsUrl;
+ }
+
+ public void setStyleUrl(String styleUrl) {
+ this.styleUrl = styleUrl;
+ }
}