diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/JuickApplication.java | 16 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/Login.java | 5 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/Main.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/PageTemplates.java | 9 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/RSS.java | 8 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/Settings.java | 5 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/User.java | 5 | ||||
-rw-r--r-- | src/main/java/com/juick/http/www/UserThread.java | 3 |
8 files changed, 34 insertions, 19 deletions
diff --git a/src/main/java/com/juick/JuickApplication.java b/src/main/java/com/juick/JuickApplication.java index c4a62c6f..ce242222 100644 --- a/src/main/java/com/juick/JuickApplication.java +++ b/src/main/java/com/juick/JuickApplication.java @@ -55,12 +55,20 @@ public class JuickApplication { @Override public void failed(Throwable exc, AsynchronousSocketChannel attachment) { - logger.log(Level.SEVERE, "www router failed", exc); + if (!isHttpDevMode()) { + logger.log(Level.SEVERE, "www router failed", exc); + } } }); - addComponent(new S2SComponent(this, conf)); - addComponent(new CrosspostComponent(sql, conf)); - addComponent(new PushComponent(sql, conf)); + if (!isHttpDevMode()) { + addComponent(new S2SComponent(this, conf)); + addComponent(new CrosspostComponent(sql, conf)); + addComponent(new PushComponent(sql, conf)); + } + } + + public static boolean isHttpDevMode() { + return "san".equals(System.getenv("USER")); } public Stream getRouter() { diff --git a/src/main/java/com/juick/http/www/Login.java b/src/main/java/com/juick/http/www/Login.java index 00775fc1..f1f670b1 100644 --- a/src/main/java/com/juick/http/www/Login.java +++ b/src/main/java/com/juick/http/www/Login.java @@ -17,6 +17,7 @@ */ package com.juick.http.www; +import com.juick.server.Endpoints; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -219,7 +220,7 @@ public class Login { response.addCookie(c); String referer = request.getHeader("Referer"); - if (referer != null && referer.startsWith("http://juick.com/") && !referer.equals("http://juick.com/login")) { + if (referer != null && referer.startsWith("http://"+Endpoints.wwwJuickCom+"/") && !referer.equals("http://"+Endpoints.wwwJuickCom+"/login")) { response.sendRedirect(referer); } else { response.sendRedirect("/"); @@ -235,7 +236,7 @@ public class Login { sql.update("DELETE FROM logins WHERE user_id=?", visitor.getUID()); Cookie c = new Cookie("hash", "-"); - c.setDomain(".juick.com"); + c.setDomain("." + Endpoints.getWwwJuickComDomain()); c.setMaxAge(0); response.addCookie(c); diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java index 08b92305..f37ae030 100644 --- a/src/main/java/com/juick/http/www/Main.java +++ b/src/main/java/com/juick/http/www/Main.java @@ -18,6 +18,7 @@ package com.juick.http.www; import com.juick.JuickApplication; +import com.juick.server.Endpoints; import com.juick.server.UserQueries; import com.juick.xmpp.Stream; import org.springframework.jdbc.core.JdbcTemplate; @@ -75,6 +76,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"), conf.getProperty("twitter_consumer_secret")); PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600); + Endpoints.wwwJuickCom = conf.getProperty("www_juick_com", "juick.com"); app = new JuickApplication(conf); sql = app.getSql(); sqlSearch = app.getSqlSearch(); diff --git a/src/main/java/com/juick/http/www/PageTemplates.java b/src/main/java/com/juick/http/www/PageTemplates.java index 5d70e9de..3eb66877 100644 --- a/src/main/java/com/juick/http/www/PageTemplates.java +++ b/src/main/java/com/juick/http/www/PageTemplates.java @@ -19,6 +19,7 @@ package com.juick.http.www; import com.juick.Message; import com.juick.Tag; +import com.juick.server.Endpoints; import com.juick.server.MessagesQueries; import com.juick.server.UserQueries; import org.springframework.jdbc.core.JdbcTemplate; @@ -375,11 +376,11 @@ public class PageTemplates { // #12345 // <a href="http://juick.com/12345">#12345</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"http://juick.com/$2\">#$2</a>$3"); + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"http://"+ Endpoints.wwwJuickCom+"/$2\">#$2</a>$3"); // #12345/65 // <a href="http://juick.com/12345#65">#12345/65</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2#$3\">#$2/$3</a>$4"); + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://"+Endpoints.wwwJuickCom+"/$2#$3\">#$2/$3</a>$4"); // *bold* // <b>bold</b> @@ -399,11 +400,11 @@ public class PageTemplates { // @username@jabber.org // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3"); + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://"+Endpoints.wwwJuickCom+"/$2/\">@$2</a>$3"); // @username // <a href="http://juick.com/username/">@username</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3"); + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://"+Endpoints.wwwJuickCom+"/$2/\">@$2</a>$3"); // (http://juick.com/last?page=2) // (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>) diff --git a/src/main/java/com/juick/http/www/RSS.java b/src/main/java/com/juick/http/www/RSS.java index c9c9df18..070fa1d5 100644 --- a/src/main/java/com/juick/http/www/RSS.java +++ b/src/main/java/com/juick/http/www/RSS.java @@ -18,6 +18,7 @@ package com.juick.http.www; import com.juick.Message; +import com.juick.server.Endpoints; import com.juick.server.MessagesQueries; import org.springframework.jdbc.core.JdbcTemplate; @@ -33,7 +34,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** - * * @author ugnich */ public class RSS { @@ -64,8 +64,8 @@ public class RSS { for (Message msg : msgs) { out.println("<item>"); - out.println("<link>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</link>"); - out.println("<guid>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</guid>"); + out.println("<link>http://" + Endpoints.wwwJuickCom + "/" + msg.getUser().getUName() + "/" + msg.getMID() + "</link>"); + out.println("<guid>http://" + Endpoints.wwwJuickCom + "/" + msg.getUser().getUName() + "/" + msg.getMID() + "</guid>"); out.print("<title><![CDATA[@" + msg.getUser().getUName() + ":"); if (!msg.Tags.isEmpty()) { @@ -76,7 +76,7 @@ public class RSS { out.println("]]></title>"); out.println("<description><![CDATA[" + PageTemplates.formatMessage(msg.getText()) + "]]></description>"); out.println("<pubDate>" + sdfRSS.format(msg.getDate()) + "</pubDate>"); - out.println("<comments>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</comments>"); + out.println("<comments>http://" + Endpoints.wwwJuickCom + "/" + msg.getUser().getUName() + "/" + msg.getMID() + "</comments>"); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { out.println("<category>" + msg.Tags.get(n) + "</category>"); diff --git a/src/main/java/com/juick/http/www/Settings.java b/src/main/java/com/juick/http/www/Settings.java index 3713157f..6c39138f 100644 --- a/src/main/java/com/juick/http/www/Settings.java +++ b/src/main/java/com/juick/http/www/Settings.java @@ -17,6 +17,7 @@ */ package com.juick.http.www; +import com.juick.server.Endpoints; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -71,7 +72,7 @@ public class Settings { if (uid > 0) { String hash = com.juick.server.UserQueries.getHashByUID(sql, uid); Cookie c = new Cookie("hash", hash); - c.setDomain(".juick.com"); + c.setDomain("." + Endpoints.getWwwJuickComDomain()); c.setMaxAge(365 * 24 * 60 * 60); response.addCookie(c); @@ -81,7 +82,7 @@ public class Settings { } String referer = request.getHeader("Referer"); - if (referer != null && referer.startsWith("http://juick.com/") && !referer.equals("http://juick.com/login")) { + if (referer != null && referer.startsWith("http://"+Endpoints.wwwJuickCom+"/") && !referer.equals("http://"+Endpoints.wwwJuickCom+"/login")) { response.sendRedirect(referer); } else { response.sendRedirect("/"); diff --git a/src/main/java/com/juick/http/www/User.java b/src/main/java/com/juick/http/www/User.java index 9ccf43ac..1f2b7dc0 100644 --- a/src/main/java/com/juick/http/www/User.java +++ b/src/main/java/com/juick/http/www/User.java @@ -18,6 +18,7 @@ package com.juick.http.www; import com.juick.Tag; +import com.juick.server.Endpoints; import com.juick.server.MessagesQueries; import com.juick.server.TagQueries; import com.juick.server.UserQueries; @@ -271,7 +272,7 @@ public class User { String hReferer = request.getHeader("Referer"); String ref = Utils.getCookie(request, "ref"); - if (ref == null && (hReferer == null || !(hReferer.startsWith("http://juick.com/") || hReferer.startsWith("https://juick.com/")))) { + if (ref == null && (hReferer == null || !(hReferer.startsWith("http://"+ Endpoints.wwwJuickCom+"/") || hReferer.startsWith("https://"+Endpoints.wwwJuickCom+"/")))) { Cookie c = new Cookie("ref", Integer.toString(uid)); c.setMaxAge(7 * 24 * 60 * 60); c.setPath("/"); @@ -361,7 +362,7 @@ public class User { }), user.getUID()); } - int maxUsageCnt = tags.stream().mapToInt(tag -> tag.UsageCnt).max().getAsInt(); + int maxUsageCnt = tags.size() > 0 ? tags.stream().mapToInt(tag -> tag.UsageCnt).max().getAsInt() : 1; return tags.stream().map(tag -> "<a href=\"./?tag=" + URLEncoder.encode(tag.Name) + "\" title=\"" + tag.UsageCnt + "\" rel=\"nofollow\">" + tag.Name + "</a>") diff --git a/src/main/java/com/juick/http/www/UserThread.java b/src/main/java/com/juick/http/www/UserThread.java index f54aa925..84d99788 100644 --- a/src/main/java/com/juick/http/www/UserThread.java +++ b/src/main/java/com/juick/http/www/UserThread.java @@ -19,6 +19,7 @@ package com.juick.http.www; import com.juick.Message; import com.juick.Tag; +import com.juick.server.Endpoints; import com.juick.server.MessagesQueries; import com.juick.server.UserQueries; import org.springframework.jdbc.core.JdbcTemplate; @@ -76,7 +77,7 @@ public class UserThread { try (PrintWriter out = response.getWriter()) { String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getUName() + "\" href=\"//rss.juick.com/" + msg.getUser().getUName() + "/blog\"/>"; if (paramView != null) { - headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "\"/>"; + headers += "<link rel=\"canonical\" href=\"http://"+ Endpoints.wwwJuickCom+"/" + msg.getUser().getUName() + "/" + msg.getMID() + "\"/>"; } if (msg.Hidden) { headers += "<meta name=\"robots\" content=\"noindex\"/>"; |