From aa19744ae40767b2523ac0117792b47e08209cdf Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 22 Jun 2017 15:37:09 +0300 Subject: Webpack 3, chunknames in templates --- juick-www/src/main/java/com/juick/www/WebApp.java | 65 ++++++++++++++------- .../www/configuration/WwwAppConfiguration.java | 22 ++++++- .../www/configuration/WwwServletConfiguration.java | 6 +- .../com/juick/www/controllers/PageTemplates.java | 9 ++- juick-www/src/main/resources/favicon.png | Bin 0 -> 244 bytes juick-www/src/main/resources/logo.png | Bin 0 -> 1184 bytes juick-www/src/main/resources/tagscloud.png | Bin 0 -> 42316 bytes .../src/main/webapp/WEB-INF/layouts/content.html | 6 +- juick-www/src/main/webapp/favicon.png | Bin 244 -> 0 bytes juick-www/src/main/webapp/logo.png | Bin 1184 -> 0 bytes juick-www/src/main/webapp/tagscloud.png | Bin 42316 -> 0 bytes 11 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 juick-www/src/main/resources/favicon.png create mode 100644 juick-www/src/main/resources/logo.png create mode 100644 juick-www/src/main/resources/tagscloud.png delete mode 100644 juick-www/src/main/webapp/favicon.png delete mode 100644 juick-www/src/main/webapp/logo.png delete mode 100644 juick-www/src/main/webapp/tagscloud.png (limited to 'juick-www/src/main') 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; + } } diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java index 2cf1faed..a5bc3f73 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java @@ -1,13 +1,16 @@ package com.juick.www.configuration; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.www.HelpService; -import com.juick.www.controllers.PageTemplates; import com.juick.www.WebApp; +import com.juick.www.controllers.PageTemplates; +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; @@ -17,6 +20,9 @@ import org.springframework.core.env.Environment; import javax.annotation.Resource; import javax.inject.Inject; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; /** * Created by aalexeev on 11/22/16. @@ -31,10 +37,20 @@ public class WwwAppConfiguration { private UserService userService; @Inject private TagService tagService; + @Inject + private ObjectMapper jsonMapper; + @Value("#{servletContext.contextPath}") + private String servletContextPath; @Bean - public WebApp webApp() { - return new WebApp(env, templates(), userService, tagService); + public WebApp webApp() throws IOException { + WebApp app = new WebApp(); + String manifestString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("manifest.json"), StandardCharsets.UTF_8); + HashMap manifest = jsonMapper.readValue(manifestString, + new TypeReference>() {}); + app.setScriptsUrl(manifest.get("scripts.js")); + app.setStyleUrl(manifest.get("style.css")); + return app; } @Bean public PageTemplates templates() { diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 43ca37db..ae51f1cd 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -38,11 +38,11 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.setOrder(0); registry.addResourceHandler( - "/scripts.js*", - "/style.css*", + "/scripts*.js*", + "/style*.css*", "/*.png", "/favicon.ico") - .addResourceLocations("/") + .addResourceLocations("classpath:/") .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).mustRevalidate().cachePublic()) .resourceChain(true) .addResolver(new PathResourceResolver()); 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 925d1013..5f758608 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 @@ -23,6 +23,7 @@ import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.MessageUtils; +import com.juick.www.WebApp; import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.slf4j.Logger; @@ -64,19 +65,21 @@ public class PageTemplates { MessagesService messagesService; @Inject UserService userService; + @Inject + WebApp webApp; public void pageHead(PrintWriter out, com.juick.User visitor, String title, String headers) { out.println(""); out.print(""); out.print(""); out.println(""); - out.print(""); - out.print(""); + out.print(""); + out.print(""); if (headers != null) { out.print(headers); } out.print("" + title + ""); - out.println(""); + out.println(""); out.println(""); out.println("