diff options
author | Vitaly Takmazov | 2016-01-14 12:16:49 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-14 12:16:49 +0300 |
commit | c492429b25c1ef711620a4f509975c7edc3ffa4a (patch) | |
tree | 5bc6b5746381d970760cd6ae5c5561e66a1f95e7 /src/main/java/com/juick/http/www/Main.java | |
parent | 7e93e142b6dd75c22c057962447eec014c4e15b4 (diff) |
Update libraries and refactoring
Diffstat (limited to 'src/main/java/com/juick/http/www/Main.java')
-rw-r--r-- | src/main/java/com/juick/http/www/Main.java | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java index cc4edd49..cabd50af 100644 --- a/src/main/java/com/juick/http/www/Main.java +++ b/src/main/java/com/juick/http/www/Main.java @@ -21,7 +21,14 @@ import com.juick.server.UserQueries; import com.juick.xmpp.JID; import com.juick.xmpp.Stream; import com.juick.xmpp.StreamComponent; -import java.io.FileInputStream; +import ru.sape.Sape; + +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.Socket; import java.net.URLEncoder; @@ -29,14 +36,6 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; -import java.util.logging.Level; -import javax.servlet.ServletException; -import javax.servlet.annotation.MultipartConfig; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import ru.sape.Sape; /** * @@ -107,18 +106,14 @@ public class Main extends HttpServlet implements Stream.StreamListener { return sqlSearch; } public void setupXmppComponent(final String password) { - Thread thr = new Thread(new Runnable() { - - @Override - public void run() { - try { - Socket socket = new Socket("localhost", 5347); - xmpp = new StreamComponent(new JID("", "www.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); - xmpp.addListener(Main.this); - xmpp.startParsing(); - } catch (IOException e) { - System.err.println(e); - } + Thread thr = new Thread(() -> { + try { + Socket socket = new Socket("localhost", 5347); + xmpp = new StreamComponent(new JID("", "www.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); + xmpp.addListener(Main.this); + xmpp.startParsing(); + } catch (IOException e) { + log("xmpp exception", e); } }); thr.start(); @@ -194,12 +189,16 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (visitor == null) { Utils.sendTemporaryRedirect(response, "/login"); } else { - if (uri.equals("/pm/inbox")) { - pm.doGetInbox(sql, request, response, visitor); - } else if (uri.equals("/pm/sent")) { - pm.doGetSent(sql, request, response, visitor); - } else { - Errors.doGet404(sql, request, response); + switch (uri) { + case "/pm/inbox": + pm.doGetInbox(sql, request, response, visitor); + break; + case "/pm/sent": + pm.doGetSent(sql, request, response, visitor); + break; + default: + Errors.doGet404(sql, request, response); + break; } } } else if (uri.startsWith("/rss/")) { @@ -239,7 +238,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (mid > 0) { com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid); if (author != null) { - Utils.sendPermanentRedirect(response, "/" + author.UName + "/" + mid); + Utils.sendPermanentRedirect(response, "/" + author.getUName() + "/" + mid); return; } } @@ -247,14 +246,14 @@ public class Main extends HttpServlet implements Stream.StreamListener { } else if (uri.matches("^/[^/]+$")) { com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, request.getRequestURI().substring(1)); if (user != null) { - Utils.sendPermanentRedirect(response, "/" + user.UName + "/"); + Utils.sendPermanentRedirect(response, "/" + user.getUName() + "/"); } else { Errors.doGet404(sql, request, response); } } else if (uri.matches("^/.+/.*")) { String uriparts[] = uri.split("/"); com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, uriparts[1]); - if (user != null && user.UName.equals(uriparts[1]) && user.Banned == false) { + if (user != null && user.getUName().equals(uriparts[1]) && !user.Banned) { if (uriparts.length == 2) { // http://juick.com/username/ pagesUser.doGetBlog(sql, getSqlSearch(), request, response, user); closeSqlSearch(); @@ -273,8 +272,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (mid > 0) { com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid); if (author != null) { - if (!author.UName.equals(user.UName)) { - Utils.sendPermanentRedirect(response, "/" + author.UName + "/" + mid); + if (!author.getUName().equals(user.getUName())) { + Utils.sendPermanentRedirect(response, "/" + author.getUName() + "/" + mid); } else { pagesUserThread.doGetThread(sql, request, response, mid); } @@ -285,8 +284,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { Errors.doGet404(sql, request, response); } } - } else if (user != null && user.Banned == false) { - Utils.sendPermanentRedirect(response, "/" + user.UName + "/" + (uriparts.length > 2 ? uriparts[2] : "")); + } else if (user != null && !user.Banned) { + Utils.sendPermanentRedirect(response, "/" + user.getUName() + "/" + (uriparts.length > 2 ? uriparts[2] : "")); } else { Errors.doGet404(sql, request, response); } |