From c4eebb74f520c122800c000c2329d3b6b7520c65 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Wed, 30 Jul 2014 16:47:29 +0700 Subject: Reader link tracking --- src/java/com/juick/http/www/Main.java | 26 +++++++++--------- src/java/com/juick/http/www/PageTemplates.java | 2 +- src/java/com/juick/http/www/Reader.java | 37 ++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 15 deletions(-) (limited to 'src/java/com/juick') diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index 1d5e64d3..0fe93173 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -43,7 +43,7 @@ import ru.sape.Sape; @WebServlet(name = "Main", urlPatterns = {"/"}) @MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10) public class Main extends HttpServlet implements Stream.StreamListener { - + Connection sql; Connection sqlSearch; Stream xmpp; @@ -60,29 +60,29 @@ public class Main extends HttpServlet implements Stream.StreamListener { VKontakteLogin loginVK = new VKontakteLogin(); SignUp signup = new SignUp(); Settings settings = new Settings(); - + @Override public void init() throws ServletException { super.init(); try { Properties conf = new Properties(); conf.load(new FileInputStream("/etc/juick/www.conf")); - + Class.forName("com.mysql.jdbc.Driver"); sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", "")); sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000", "", ""); - + setupXmppComponent(conf.getProperty("xmpp_password")); - + PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600); } catch (Exception e) { log(null, e); } } - + public void setupXmppComponent(final String password) { Thread thr = new Thread(new Runnable() { - + @Override public void run() { try { @@ -97,17 +97,17 @@ public class Main extends HttpServlet implements Stream.StreamListener { }); thr.start(); } - + @Override public void onStreamFail(String msg) { System.err.println("XMPP STREAM FAIL: " + msg); } - + @Override public void onStreamReady() { System.err.println("XMPP STREAM READY"); } - + @Override public void destroy() { super.destroy(); @@ -142,7 +142,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { request.setCharacterEncoding("UTF-8"); } String uri = request.getRequestURI(); - + if (uri.equals("/")) { String tag = request.getParameter("tag"); if (tag != null) { @@ -153,6 +153,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { } } else if (uri.equals("/reader")) { reader.doGet(sql, request, response); + } else if (uri.equals("/_out")) { + reader.doGetOut(sql, request, response); } else if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor != null) { @@ -272,7 +274,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); } - + String uri = request.getRequestURI(); if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index afffc334..dc8c7c59 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -53,7 +53,7 @@ public class PageTemplates { out.print("
"); out.print(""); out.print(""); - out.print(""); + out.print(""); if (headers != null) { out.print(headers); } diff --git a/src/java/com/juick/http/www/Reader.java b/src/java/com/juick/http/www/Reader.java index dc356482..75a0e774 100644 --- a/src/java/com/juick/http/www/Reader.java +++ b/src/java/com/juick/http/www/Reader.java @@ -54,11 +54,11 @@ public class Reader { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100"); + stmt = sql.prepareStatement("SELECT link_id,rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100"); rs = stmt.executeQuery(); rs.beforeFirst(); while (rs.next()) { - out.println("