From 1002c2f14fadcfc00991489fe715437d3c1ac7d7 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Fri, 29 Nov 2013 12:19:08 +0700 Subject: Initial commit --- src/conf/MANIFEST.MF | 2 + src/java/com/juick/rss/Main.java | 333 ++++++++++++++++++++++++++++++++++++++ src/java/com/juick/rss/Utils.java | 74 +++++++++ 3 files changed, 409 insertions(+) create mode 100644 src/conf/MANIFEST.MF create mode 100644 src/java/com/juick/rss/Main.java create mode 100644 src/java/com/juick/rss/Utils.java (limited to 'src') diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/java/com/juick/rss/Main.java b/src/java/com/juick/rss/Main.java new file mode 100644 index 00000000..65169fbb --- /dev/null +++ b/src/java/com/juick/rss/Main.java @@ -0,0 +1,333 @@ +/* + * Juick + * Copyright (C) 2008-2013, ugnich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.juick.rss; + +import com.juick.Message; +import com.juick.server.MessagesQueries; +import com.juick.server.UserQueries; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author ugnich + */ +@WebServlet(name = "Main", urlPatterns = {"/"}) +public class Main extends HttpServlet { + + private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); + Connection sql; + + @Override + public void init() throws ServletException { + super.init(); + try { + Properties conf = new Properties(); + conf.load(new FileInputStream("/etc/juick/rss.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", "")); + + } catch (Exception e) { + log(null, e); + } + } + + @Override + public void destroy() { + super.destroy(); + if (sql != null) { + try { + sql.close(); + sql = null; + } catch (SQLException e) { + log(null, e); + } + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + if (request.getCharacterEncoding() == null) { + request.setCharacterEncoding("UTF-8"); + } + + String uri = request.getRequestURI(); + if (uri.equals("/")) { + int hours = Utils.parseInt(request.getParameter("hours"), 0); + if (hours > 0 && hours < 13) { + ArrayList mids = getLastMessages(hours); + ArrayList msgs = MessagesQueries.getMessages(sql, mids); + responseMessages(response, 0, null, msgs); + } else { + response.sendError(404); + } + } else if (uri.equals("/comments")) { + int hours = Utils.parseInt(request.getParameter("hours"), 0); + if (hours > 0 && hours < 13) { + responseReplies(response, hours); + } else { + response.sendError(404); + } + } else if (uri.matches("^/[a-zA-Z0-9\\-]{2,16}/blog$")) { + String uname = uri.substring(1, uri.length() - 5); + int uid = UserQueries.getUIDbyName(sql, uname); + if (uid > 0) { + ArrayList mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); + ArrayList msgs = MessagesQueries.getMessages(sql, mids); + responseMessages(response, uid, uname, msgs); + } else { + response.sendError(404); + } + } else { + response.sendError(404); + } + } + + private void responseMessages(HttpServletResponse response, int uid, String uname, ArrayList msgs) throws IOException { + response.setContentType("application/rss+xml; charset=UTF-8"); + + PrintWriter out = response.getWriter(); + try { + out.println(""); + out.println(""); + out.println(""); + if (uid > 0) { + out.println(""); + out.println("" + uname + " - Juick"); + out.println("http://juick.com/" + uname + "/"); + out.println("The latest messages by @" + uname + " at Juick"); + out.println("http://i.juick.com/a/" + uid + ".png" + uname + " - Juickhttp://juick.com/" + uname + "/"); + } else { + out.println("Juick"); + out.println("http://juick.com/"); + out.println("The latest messages at Juick"); + } + + Iterator i = msgs.iterator(); + while (i.hasNext()) { + Message msg = i.next(); + + out.println(""); + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + + out.print("<![CDATA[@" + msg.User.UName + ":"); + if (!msg.Tags.isEmpty()) { + for (int n = 0; n < msg.Tags.size(); n++) { + out.print(" *" + msg.Tags.get(n)); + } + } + out.println("]]>"); + out.println(""); + + try { + Date date = sdfSQL.parse(msg.TimestampString); + out.println("" + sdfRSS.format(date) + ""); + } catch (ParseException e) { + } + + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + if (!msg.Tags.isEmpty()) { + for (int n = 0; n < msg.Tags.size(); n++) { + out.println("" + msg.Tags.get(n) + ""); + } + } + if (msg.AttachmentType != null) { + if (msg.AttachmentType.equals("jpg")) { + out.println(""); + out.println(""); + } else if (msg.AttachmentType.equals("png")) { + out.println(""); + out.println(""); + } + } + out.println(""); + out.println(""); + } + + out.println(""); + } finally { + out.close(); + } + } + + private void responseReplies(HttpServletResponse response, int hours) throws IOException { + response.setContentType("application/rss+xml; charset=UTF-8"); + + PrintWriter out = response.getWriter(); + try { + + out.println(""); + out.println(""); + out.println(""); + out.println("Juick"); + out.println("http://juick.com/"); + out.println("The latest comments at Juick"); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users2.nick,replies.message_id,replies.reply_id,users.nick,replies.txt,DATE_FORMAT(replies.ts,'%a, %d %b %Y %T UT'),replies.attach,replies.ts+0 FROM ((replies INNER JOIN users ON replies.user_id=users.id) INNER JOIN messages ON replies.message_id=messages.message_id) INNER JOIN users AS users2 ON messages.user_id=users2.id WHERE replies.ts>TIMESTAMPADD(HOUR,?,NOW()) AND messages.privacy>0"); + stmt.setInt(1, -hours); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + String muname = rs.getString(1); + int mid = rs.getInt(2); + int rid = rs.getInt(3); + String uname = rs.getString(4); + + out.println(""); + out.println("http://juick.com/" + muname + "/" + mid + ""); + out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); + out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); + out.println("http://juick.com/" + uname + "/"); + out.println("@" + uname + ":"); + out.println(""); + out.println("" + rs.getString(6) + ""); + String attachment = rs.getString(7); + if (attachment != null && !attachment.isEmpty()) { + if (attachment.equals("jpg")) { + out.println(""); + out.println(""); + } else if (attachment.equals("png")) { + out.println(""); + out.println(""); + } + } + out.println(""); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println(""); + } finally { + out.close(); + } + } + + private ArrayList getLastMessages(int hours) { + ArrayList mids = new ArrayList(20); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())"); + stmt.setInt(1, -hours); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + mids.add(rs.getInt(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return mids; + } + private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?", ">"); + + // -- + // — + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2"); + + // http://juick.com/last?page=2 + // juick.com + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1$3"); + + // #12345 + // #12345 + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1#$2$3"); + + // #12345/65 + // #12345/65 + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1#$2/$3$4"); + + // *bold* + // bold + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); + + // /italic/ + // italic + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); + + // _underline_ + // underline + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); + + // /12 + // /12 + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1/$2$3"); + + // @username@jabber.org + // @username@jabber.org + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3"); + + // @username + // @username + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3"); + + // (http://juick.com/last?page=2) + // (juick.com) + Matcher m = regexLinks2.matcher(msg); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", ""); + m.appendReplacement(sb, "$1$2$4$5"); + } + m.appendTail(sb); + msg = sb.toString(); + + // > citate + msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); + msg = msg.replaceAll("
", "\n"); + + msg = msg.replaceAll("\n", "
\n"); + return msg; + } +} diff --git a/src/java/com/juick/rss/Utils.java b/src/java/com/juick/rss/Utils.java new file mode 100644 index 00000000..a6842fe1 --- /dev/null +++ b/src/java/com/juick/rss/Utils.java @@ -0,0 +1,74 @@ +/* + * Juick + * Copyright (C) 2008-2011, ugnich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.juick.rss; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +/** + * + * @author ugnich + */ +public class Utils { + + public static void finishSQL(ResultSet rs, Statement stmt) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + } + } + } + + public static String convertArray2String(ArrayList mids) { + String q = ""; + for (int i = 0; i < mids.size(); i++) { + if (i > 0) { + q += ","; + } + q += mids.get(i); + } + return q; + } + + public static String encodeHTML(String str) { + String ret = str; + ret = ret.replaceAll("<", "<"); + ret = ret.replaceAll(">", ">"); + return str; + } + + public static int parseInt(String str, int def) { + int ret = def; + if (str != null) { + try { + ret = Integer.parseInt(str); + } catch (Exception e) { + } + } + return ret; + } +} -- cgit v1.2.3 From b20f7633312b2f9af6207150e5288f583e9e1024 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Mon, 27 Jan 2014 03:18:29 +0700 Subject: mids.isEmpty bugfix --- nbproject/project.properties | 2 +- src/java/com/juick/rss/Main.java | 58 +++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/nbproject/project.properties b/nbproject/project.properties index 94d97248..7c8e7334 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -30,7 +30,7 @@ includes=** j2ee.compile.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.6-web -j2ee.platform.classpath=${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/ecj-3.7.1.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/annotations-api.jar +j2ee.platform.classpath=${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat7-websocket.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.2.2.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/annotations-api.jar j2ee.server.type=Tomcat jar.compress=false javac.classpath=\ diff --git a/src/java/com/juick/rss/Main.java b/src/java/com/juick/rss/Main.java index 65169fbb..827ecf39 100644 --- a/src/java/com/juick/rss/Main.java +++ b/src/java/com/juick/rss/Main.java @@ -48,26 +48,26 @@ import javax.servlet.http.HttpServletResponse; */ @WebServlet(name = "Main", urlPatterns = {"/"}) public class Main extends HttpServlet { - + private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); Connection sql; - + @Override public void init() throws ServletException { super.init(); try { Properties conf = new Properties(); conf.load(new FileInputStream("/etc/juick/rss.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", "")); - + } catch (Exception e) { log(null, e); } } - + @Override public void destroy() { super.destroy(); @@ -80,13 +80,13 @@ public class Main extends HttpServlet { } } } - + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); } - + String uri = request.getRequestURI(); if (uri.equals("/")) { int hours = Utils.parseInt(request.getParameter("hours"), 0); @@ -109,8 +109,12 @@ public class Main extends HttpServlet { int uid = UserQueries.getUIDbyName(sql, uname); if (uid > 0) { ArrayList mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); - ArrayList msgs = MessagesQueries.getMessages(sql, mids); - responseMessages(response, uid, uname, msgs); + if (!mids.isEmpty()) { + ArrayList msgs = MessagesQueries.getMessages(sql, mids); + responseMessages(response, uid, uname, msgs); + } else { + response.sendError(404); + } } else { response.sendError(404); } @@ -118,10 +122,10 @@ public class Main extends HttpServlet { response.sendError(404); } } - + private void responseMessages(HttpServletResponse response, int uid, String uname, ArrayList msgs) throws IOException { response.setContentType("application/rss+xml; charset=UTF-8"); - + PrintWriter out = response.getWriter(); try { out.println(""); @@ -138,15 +142,15 @@ public class Main extends HttpServlet { out.println("http://juick.com/"); out.println("The latest messages at Juick"); } - + Iterator i = msgs.iterator(); while (i.hasNext()) { Message msg = i.next(); - + out.println(""); out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); - + out.print("<![CDATA[@" + msg.User.UName + ":"); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { @@ -155,13 +159,13 @@ public class Main extends HttpServlet { } out.println("]]>"); out.println(""); - + try { Date date = sdfSQL.parse(msg.TimestampString); out.println("" + sdfRSS.format(date) + ""); } catch (ParseException e) { } - + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { @@ -180,26 +184,26 @@ public class Main extends HttpServlet { out.println(""); out.println(""); } - + out.println(""); } finally { out.close(); } } - + private void responseReplies(HttpServletResponse response, int hours) throws IOException { response.setContentType("application/rss+xml; charset=UTF-8"); - + PrintWriter out = response.getWriter(); try { - + out.println(""); out.println(""); out.println(""); out.println("Juick"); out.println("http://juick.com/"); out.println("The latest comments at Juick"); - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -212,7 +216,7 @@ public class Main extends HttpServlet { int mid = rs.getInt(2); int rid = rs.getInt(3); String uname = rs.getString(4); - + out.println(""); out.println("http://juick.com/" + muname + "/" + mid + ""); out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); @@ -238,16 +242,16 @@ public class Main extends HttpServlet { } finally { Utils.finishSQL(rs, stmt); } - + out.println(""); } finally { out.close(); } } - + private ArrayList getLastMessages(int hours) { ArrayList mids = new ArrayList(20); - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -266,7 +270,7 @@ public class Main extends HttpServlet { return mids; } private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](? citate msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); msg = msg.replaceAll("
", "\n"); - + msg = msg.replaceAll("\n", "
\n"); return msg; } -- cgit v1.2.3 From ba4ddf62ddd1df23a95bfe15fe48e03791d4754d Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 5 Aug 2014 04:55:16 +0700 Subject: pubDate bugfix --- src/java/com/juick/rss/Main.java | 66 +++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/java/com/juick/rss/Main.java b/src/java/com/juick/rss/Main.java index 827ecf39..9c0d803c 100644 --- a/src/java/com/juick/rss/Main.java +++ b/src/java/com/juick/rss/Main.java @@ -28,7 +28,6 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -48,26 +47,26 @@ import javax.servlet.http.HttpServletResponse; */ @WebServlet(name = "Main", urlPatterns = {"/"}) public class Main extends HttpServlet { - - private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); + + private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); Connection sql; - + @Override public void init() throws ServletException { super.init(); try { Properties conf = new Properties(); conf.load(new FileInputStream("/etc/juick/rss.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", "")); - + } catch (Exception e) { log(null, e); } } - + @Override public void destroy() { super.destroy(); @@ -80,13 +79,13 @@ public class Main extends HttpServlet { } } } - + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); } - + String uri = request.getRequestURI(); if (uri.equals("/")) { int hours = Utils.parseInt(request.getParameter("hours"), 0); @@ -122,10 +121,10 @@ public class Main extends HttpServlet { response.sendError(404); } } - + private void responseMessages(HttpServletResponse response, int uid, String uname, ArrayList msgs) throws IOException { response.setContentType("application/rss+xml; charset=UTF-8"); - + PrintWriter out = response.getWriter(); try { out.println(""); @@ -142,15 +141,15 @@ public class Main extends HttpServlet { out.println("http://juick.com/"); out.println("The latest messages at Juick"); } - + Iterator i = msgs.iterator(); while (i.hasNext()) { Message msg = i.next(); - + out.println(""); out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); - + out.print("<![CDATA[@" + msg.User.UName + ":"); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { @@ -159,13 +158,16 @@ public class Main extends HttpServlet { } out.println("]]>"); out.println(""); - - try { - Date date = sdfSQL.parse(msg.TimestampString); - out.println("" + sdfRSS.format(date) + ""); - } catch (ParseException e) { + + synchronized (sdfSQL) { + try { + Date date = sdfSQL.parse(msg.TimestampString); + out.println("" + sdfRSS.format(date) + ""); + } catch (Exception e) { + System.err.println("PARSE EXCEPTION: " + msg.TimestampString); + } } - + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { @@ -184,26 +186,26 @@ public class Main extends HttpServlet { out.println(""); out.println(""); } - + out.println(""); } finally { out.close(); } } - + private void responseReplies(HttpServletResponse response, int hours) throws IOException { response.setContentType("application/rss+xml; charset=UTF-8"); - + PrintWriter out = response.getWriter(); try { - + out.println(""); out.println(""); out.println(""); out.println("Juick"); out.println("http://juick.com/"); out.println("The latest comments at Juick"); - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -216,7 +218,7 @@ public class Main extends HttpServlet { int mid = rs.getInt(2); int rid = rs.getInt(3); String uname = rs.getString(4); - + out.println(""); out.println("http://juick.com/" + muname + "/" + mid + ""); out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); @@ -242,16 +244,16 @@ public class Main extends HttpServlet { } finally { Utils.finishSQL(rs, stmt); } - + out.println(""); } finally { out.close(); } } - + private ArrayList getLastMessages(int hours) { ArrayList mids = new ArrayList(20); - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -270,7 +272,7 @@ public class Main extends HttpServlet { return mids; } private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](? citate msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); msg = msg.replaceAll("
", "\n"); - + msg = msg.replaceAll("\n", "
\n"); return msg; } -- cgit v1.2.3 From 9487b904edb1619c7379c9f75d49fb5ee3743488 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 1 Dec 2015 03:14:41 +0300 Subject: moving to Gradle --- .gitignore | 4 +- .gitmodules | 6 + build.gradle | 52 ++ build.xml | 71 -- deps/com.juick | 1 + deps/com.juick.server | 1 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++ gradlew.bat | 90 +++ nbproject/ant-deploy.xml | 37 - nbproject/build-impl.xml | 1090 ------------------------------ nbproject/genfiles.properties | 8 - nbproject/project.properties | 87 --- nbproject/project.xml | 45 -- settings.gradle | 1 + src/conf/MANIFEST.MF | 2 - src/java/com/juick/rss/Main.java | 339 ---------- src/java/com/juick/rss/Utils.java | 74 -- src/main/java/com/juick/rss/Main.java | 339 ++++++++++ src/main/java/com/juick/rss/Utils.java | 74 ++ web/META-INF/context.xml | 2 - 22 files changed, 733 insertions(+), 1756 deletions(-) create mode 100644 .gitmodules create mode 100644 build.gradle delete mode 100644 build.xml create mode 160000 deps/com.juick create mode 160000 deps/com.juick.server create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat delete mode 100644 nbproject/ant-deploy.xml delete mode 100644 nbproject/build-impl.xml delete mode 100644 nbproject/genfiles.properties delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml create mode 100644 settings.gradle delete mode 100644 src/conf/MANIFEST.MF delete mode 100644 src/java/com/juick/rss/Main.java delete mode 100644 src/java/com/juick/rss/Utils.java create mode 100644 src/main/java/com/juick/rss/Main.java create mode 100644 src/main/java/com/juick/rss/Utils.java delete mode 100644 web/META-INF/context.xml (limited to 'src') diff --git a/.gitignore b/.gitignore index 2a2d339d..48cc0990 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /nbproject/private/ /dist/ -/build/ \ No newline at end of file +/build/ +.gradle/* +deps/* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..53c541e2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "deps/com.juick"] + path = deps/com.juick + url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.git +[submodule "deps/com.juick.server"] + path = deps/com.juick.server + url = ssh://den.jabber.ru:2205/var/lib/git/com.juick.server.git diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..ec4bede2 --- /dev/null +++ b/build.gradle @@ -0,0 +1,52 @@ +subprojects { + apply plugin: 'java' + repositories { + mavenCentral() + } +} + +buildscript { + repositories { + mavenCentral() + jcenter() + } + dependencies { + classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.+' + } +} + +apply plugin: 'java' +apply plugin: 'war' +apply plugin: 'com.bmuschko.tomcat' + +repositories { + mavenCentral() +} + +def core = project(':deps:com.juick') +def server = project(':deps:com.juick.server') + +project(':deps:com.juick.server') { + dependencies { + compile core + } +} + +dependencies { + compile core + compile server + providedCompile 'javax.servlet:javax.servlet-api:3.1.0' + def tomcatVersion = '7.0.+' + tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", + "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", + "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}" + testCompile 'junit:junit:4.12' + runtime 'mysql:mysql-connector-java:5.1.37' +} + +compileJava.options.encoding = 'UTF-8' + +tomcat { + httpPort = 8080 + contextPath = '/' +} diff --git a/build.xml b/build.xml deleted file mode 100644 index 01dbb680..00000000 --- a/build.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project com.juick.rss. - - - diff --git a/deps/com.juick b/deps/com.juick new file mode 160000 index 00000000..5f08b8b1 --- /dev/null +++ b/deps/com.juick @@ -0,0 +1 @@ +Subproject commit 5f08b8b1cfaacf1e78c56e7752277533eb84b02e diff --git a/deps/com.juick.server b/deps/com.juick.server new file mode 160000 index 00000000..23666546 --- /dev/null +++ b/deps/com.juick.server @@ -0,0 +1 @@ +Subproject commit 23666546ca2c0f1ee492b1bea8c0ea83c8c04a2b diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..05ef575b Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..65a9525c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Oct 29 12:36:21 MSK 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..9d82f789 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/nbproject/ant-deploy.xml b/nbproject/ant-deploy.xml deleted file mode 100644 index cbfe67c3..00000000 --- a/nbproject/ant-deploy.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml deleted file mode 100644 index aead195a..00000000 --- a/nbproject/build-impl.xml +++ /dev/null @@ -1,1090 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set build.web.dir - Must set build.generated.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.war - - - - - - - - - -The Java EE server classpath is not correctly set up - server home directory is missing. -Either open the project in the IDE and assign the server or setup the server classpath manually. -For example like this: - ant -Dj2ee.server.home=<app_server_installation_directory> - - -The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. -Either open the project in the IDE and assign the server or setup the server classpath manually. -For example like this: - ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) -or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -The libs.CopyLibs.classpath property is not set up. -This property must point to -org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part -of NetBeans IDE installation and is usually located at -<netbeans_installation>/java<version>/ant/extra folder. -Either open the project in the IDE and make sure CopyLibs library -exists or setup the property manually. For example like this: - ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.jsp.includes - - - - - - - - - - - - - - - - - - - - - - - - - - Must select a file in the IDE or set jsp.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. - - - Launching ${browse.url} - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties deleted file mode 100644 index 2333623f..00000000 --- a/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=78b22342 -build.xml.script.CRC32=6eff49b5 -build.xml.stylesheet.CRC32=651128d4@1.33.1.1 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=78b22342 -nbproject/build-impl.xml.script.CRC32=16237861 -nbproject/build-impl.xml.stylesheet.CRC32=0cbf5bb7@1.33.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 7c8e7334..00000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,87 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=true -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.web.dir}/WEB-INF/classes -build.classes.excludes=**/*.java,**/*.form -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -build.web.dir=${build.dir}/web -build.web.excludes=${build.classes.excludes} -client.urlPart= -compile.jsps=false -conf.dir=${source.root}/conf -debug.classpath=${build.classes.dir}:${javac.classpath} -debug.test.classpath=\ - ${run.test.classpath} -display.browser=true -dist.dir=dist -dist.ear.war=${dist.dir}/${war.ear.name} -dist.javadoc.dir=${dist.dir}/javadoc -dist.war=${dist.dir}/${war.name} -endorsed.classpath=\ - ${libs.javaee-endorsed-api-6.0.classpath} -excludes= -includes=** -j2ee.compile.on.save=true -j2ee.deploy.on.save=true -j2ee.platform=1.6-web -j2ee.platform.classpath=${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat7-websocket.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.2.2.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/annotations-api.jar -j2ee.server.type=Tomcat -jar.compress=false -javac.classpath=\ - ${reference.com_juick_server.jar}:\ - ${reference.com_juick.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.debug=true -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.6 -javac.target=1.6 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.preview=true -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -lib.dir=${web.docbase.dir}/WEB-INF/lib -no.dependencies=false -persistence.xml.dir=${conf.dir} -platform.active=default_platform -project.com_juick=../com.juick -project.com_juick_server=../com.juick.server -reference.com_juick.jar=${project.com_juick}/dist/com.juick.jar -reference.com_juick_server.jar=${project.com_juick_server}/dist/com.juick.server.jar -resource.dir=setup -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -# Space-separated list of JVM arguments used when running a class with a main method or a unit test -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): -runmain.jvmargs= -source.encoding=UTF-8 -source.root=src -src.dir=${source.root}/java -test.src.dir=test -war.content.additional= -war.ear.name=com.juick.rss.war -war.name=com.juick.rss.war -web.docbase.dir=web -webinf.dir=web/WEB-INF diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index acca5996..00000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - org.netbeans.modules.web.project - - - com.juick.rss - 1.6.5 - - - ${reference.com_juick_server.jar} - WEB-INF/lib - - - ${reference.com_juick.jar} - WEB-INF/lib - - - - - - - - - - - - - com_juick - jar - - jar - clean - jar - - - com_juick_server - jar - - jar - clean - jar - - - - diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..05d9c6b2 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':deps:com.juick', ':deps:com.juick.server' diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF deleted file mode 100644 index 59499bce..00000000 --- a/src/conf/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/src/java/com/juick/rss/Main.java b/src/java/com/juick/rss/Main.java deleted file mode 100644 index 9c0d803c..00000000 --- a/src/java/com/juick/rss/Main.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Juick - * Copyright (C) 2008-2013, ugnich - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.juick.rss; - -import com.juick.Message; -import com.juick.server.MessagesQueries; -import com.juick.server.UserQueries; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * - * @author ugnich - */ -@WebServlet(name = "Main", urlPatterns = {"/"}) -public class Main extends HttpServlet { - - private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); - Connection sql; - - @Override - public void init() throws ServletException { - super.init(); - try { - Properties conf = new Properties(); - conf.load(new FileInputStream("/etc/juick/rss.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", "")); - - } catch (Exception e) { - log(null, e); - } - } - - @Override - public void destroy() { - super.destroy(); - if (sql != null) { - try { - sql.close(); - sql = null; - } catch (SQLException e) { - log(null, e); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (request.getCharacterEncoding() == null) { - request.setCharacterEncoding("UTF-8"); - } - - String uri = request.getRequestURI(); - if (uri.equals("/")) { - int hours = Utils.parseInt(request.getParameter("hours"), 0); - if (hours > 0 && hours < 13) { - ArrayList mids = getLastMessages(hours); - ArrayList msgs = MessagesQueries.getMessages(sql, mids); - responseMessages(response, 0, null, msgs); - } else { - response.sendError(404); - } - } else if (uri.equals("/comments")) { - int hours = Utils.parseInt(request.getParameter("hours"), 0); - if (hours > 0 && hours < 13) { - responseReplies(response, hours); - } else { - response.sendError(404); - } - } else if (uri.matches("^/[a-zA-Z0-9\\-]{2,16}/blog$")) { - String uname = uri.substring(1, uri.length() - 5); - int uid = UserQueries.getUIDbyName(sql, uname); - if (uid > 0) { - ArrayList mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); - if (!mids.isEmpty()) { - ArrayList msgs = MessagesQueries.getMessages(sql, mids); - responseMessages(response, uid, uname, msgs); - } else { - response.sendError(404); - } - } else { - response.sendError(404); - } - } else { - response.sendError(404); - } - } - - private void responseMessages(HttpServletResponse response, int uid, String uname, ArrayList msgs) throws IOException { - response.setContentType("application/rss+xml; charset=UTF-8"); - - PrintWriter out = response.getWriter(); - try { - out.println(""); - out.println(""); - out.println(""); - if (uid > 0) { - out.println(""); - out.println("" + uname + " - Juick"); - out.println("http://juick.com/" + uname + "/"); - out.println("The latest messages by @" + uname + " at Juick"); - out.println("http://i.juick.com/a/" + uid + ".png" + uname + " - Juickhttp://juick.com/" + uname + "/"); - } else { - out.println("Juick"); - out.println("http://juick.com/"); - out.println("The latest messages at Juick"); - } - - Iterator i = msgs.iterator(); - while (i.hasNext()) { - Message msg = i.next(); - - out.println(""); - out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); - out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); - - out.print("<![CDATA[@" + msg.User.UName + ":"); - if (!msg.Tags.isEmpty()) { - for (int n = 0; n < msg.Tags.size(); n++) { - out.print(" *" + msg.Tags.get(n)); - } - } - out.println("]]>"); - out.println(""); - - synchronized (sdfSQL) { - try { - Date date = sdfSQL.parse(msg.TimestampString); - out.println("" + sdfRSS.format(date) + ""); - } catch (Exception e) { - System.err.println("PARSE EXCEPTION: " + msg.TimestampString); - } - } - - out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); - if (!msg.Tags.isEmpty()) { - for (int n = 0; n < msg.Tags.size(); n++) { - out.println("" + msg.Tags.get(n) + ""); - } - } - if (msg.AttachmentType != null) { - if (msg.AttachmentType.equals("jpg")) { - out.println(""); - out.println(""); - } else if (msg.AttachmentType.equals("png")) { - out.println(""); - out.println(""); - } - } - out.println(""); - out.println(""); - } - - out.println(""); - } finally { - out.close(); - } - } - - private void responseReplies(HttpServletResponse response, int hours) throws IOException { - response.setContentType("application/rss+xml; charset=UTF-8"); - - PrintWriter out = response.getWriter(); - try { - - out.println(""); - out.println(""); - out.println(""); - out.println("Juick"); - out.println("http://juick.com/"); - out.println("The latest comments at Juick"); - - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT users2.nick,replies.message_id,replies.reply_id,users.nick,replies.txt,DATE_FORMAT(replies.ts,'%a, %d %b %Y %T UT'),replies.attach,replies.ts+0 FROM ((replies INNER JOIN users ON replies.user_id=users.id) INNER JOIN messages ON replies.message_id=messages.message_id) INNER JOIN users AS users2 ON messages.user_id=users2.id WHERE replies.ts>TIMESTAMPADD(HOUR,?,NOW()) AND messages.privacy>0"); - stmt.setInt(1, -hours); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - String muname = rs.getString(1); - int mid = rs.getInt(2); - int rid = rs.getInt(3); - String uname = rs.getString(4); - - out.println(""); - out.println("http://juick.com/" + muname + "/" + mid + ""); - out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); - out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); - out.println("http://juick.com/" + uname + "/"); - out.println("@" + uname + ":"); - out.println(""); - out.println("" + rs.getString(6) + ""); - String attachment = rs.getString(7); - if (attachment != null && !attachment.isEmpty()) { - if (attachment.equals("jpg")) { - out.println(""); - out.println(""); - } else if (attachment.equals("png")) { - out.println(""); - out.println(""); - } - } - out.println(""); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - - out.println(""); - } finally { - out.close(); - } - } - - private ArrayList getLastMessages(int hours) { - ArrayList mids = new ArrayList(20); - - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())"); - stmt.setInt(1, -hours); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - mids.add(rs.getInt(1)); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return mids; - } - private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?", ">"); - - // -- - // — - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2"); - - // http://juick.com/last?page=2 - // juick.com - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1$3"); - - // #12345 - // #12345 - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1#$2$3"); - - // #12345/65 - // #12345/65 - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1#$2/$3$4"); - - // *bold* - // bold - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); - - // /italic/ - // italic - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); - - // _underline_ - // underline - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); - - // /12 - // /12 - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1/$2$3"); - - // @username@jabber.org - // @username@jabber.org - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3"); - - // @username - // @username - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3"); - - // (http://juick.com/last?page=2) - // (juick.com) - Matcher m = regexLinks2.matcher(msg); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", ""); - m.appendReplacement(sb, "$1$2$4$5"); - } - m.appendTail(sb); - msg = sb.toString(); - - // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); - msg = msg.replaceAll("
", "\n"); - - msg = msg.replaceAll("\n", "
\n"); - return msg; - } -} diff --git a/src/java/com/juick/rss/Utils.java b/src/java/com/juick/rss/Utils.java deleted file mode 100644 index a6842fe1..00000000 --- a/src/java/com/juick/rss/Utils.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Juick - * Copyright (C) 2008-2011, ugnich - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.juick.rss; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; - -/** - * - * @author ugnich - */ -public class Utils { - - public static void finishSQL(ResultSet rs, Statement stmt) { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - } - } - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - } - } - } - - public static String convertArray2String(ArrayList mids) { - String q = ""; - for (int i = 0; i < mids.size(); i++) { - if (i > 0) { - q += ","; - } - q += mids.get(i); - } - return q; - } - - public static String encodeHTML(String str) { - String ret = str; - ret = ret.replaceAll("<", "<"); - ret = ret.replaceAll(">", ">"); - return str; - } - - public static int parseInt(String str, int def) { - int ret = def; - if (str != null) { - try { - ret = Integer.parseInt(str); - } catch (Exception e) { - } - } - return ret; - } -} diff --git a/src/main/java/com/juick/rss/Main.java b/src/main/java/com/juick/rss/Main.java new file mode 100644 index 00000000..9c0d803c --- /dev/null +++ b/src/main/java/com/juick/rss/Main.java @@ -0,0 +1,339 @@ +/* + * Juick + * Copyright (C) 2008-2013, ugnich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.juick.rss; + +import com.juick.Message; +import com.juick.server.MessagesQueries; +import com.juick.server.UserQueries; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author ugnich + */ +@WebServlet(name = "Main", urlPatterns = {"/"}) +public class Main extends HttpServlet { + + private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); + Connection sql; + + @Override + public void init() throws ServletException { + super.init(); + try { + Properties conf = new Properties(); + conf.load(new FileInputStream("/etc/juick/rss.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", "")); + + } catch (Exception e) { + log(null, e); + } + } + + @Override + public void destroy() { + super.destroy(); + if (sql != null) { + try { + sql.close(); + sql = null; + } catch (SQLException e) { + log(null, e); + } + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + if (request.getCharacterEncoding() == null) { + request.setCharacterEncoding("UTF-8"); + } + + String uri = request.getRequestURI(); + if (uri.equals("/")) { + int hours = Utils.parseInt(request.getParameter("hours"), 0); + if (hours > 0 && hours < 13) { + ArrayList mids = getLastMessages(hours); + ArrayList msgs = MessagesQueries.getMessages(sql, mids); + responseMessages(response, 0, null, msgs); + } else { + response.sendError(404); + } + } else if (uri.equals("/comments")) { + int hours = Utils.parseInt(request.getParameter("hours"), 0); + if (hours > 0 && hours < 13) { + responseReplies(response, hours); + } else { + response.sendError(404); + } + } else if (uri.matches("^/[a-zA-Z0-9\\-]{2,16}/blog$")) { + String uname = uri.substring(1, uri.length() - 5); + int uid = UserQueries.getUIDbyName(sql, uname); + if (uid > 0) { + ArrayList mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); + if (!mids.isEmpty()) { + ArrayList msgs = MessagesQueries.getMessages(sql, mids); + responseMessages(response, uid, uname, msgs); + } else { + response.sendError(404); + } + } else { + response.sendError(404); + } + } else { + response.sendError(404); + } + } + + private void responseMessages(HttpServletResponse response, int uid, String uname, ArrayList msgs) throws IOException { + response.setContentType("application/rss+xml; charset=UTF-8"); + + PrintWriter out = response.getWriter(); + try { + out.println(""); + out.println(""); + out.println(""); + if (uid > 0) { + out.println(""); + out.println("" + uname + " - Juick"); + out.println("http://juick.com/" + uname + "/"); + out.println("The latest messages by @" + uname + " at Juick"); + out.println("http://i.juick.com/a/" + uid + ".png" + uname + " - Juickhttp://juick.com/" + uname + "/"); + } else { + out.println("Juick"); + out.println("http://juick.com/"); + out.println("The latest messages at Juick"); + } + + Iterator i = msgs.iterator(); + while (i.hasNext()) { + Message msg = i.next(); + + out.println(""); + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + + out.print("<![CDATA[@" + msg.User.UName + ":"); + if (!msg.Tags.isEmpty()) { + for (int n = 0; n < msg.Tags.size(); n++) { + out.print(" *" + msg.Tags.get(n)); + } + } + out.println("]]>"); + out.println(""); + + synchronized (sdfSQL) { + try { + Date date = sdfSQL.parse(msg.TimestampString); + out.println("" + sdfRSS.format(date) + ""); + } catch (Exception e) { + System.err.println("PARSE EXCEPTION: " + msg.TimestampString); + } + } + + out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + if (!msg.Tags.isEmpty()) { + for (int n = 0; n < msg.Tags.size(); n++) { + out.println("" + msg.Tags.get(n) + ""); + } + } + if (msg.AttachmentType != null) { + if (msg.AttachmentType.equals("jpg")) { + out.println(""); + out.println(""); + } else if (msg.AttachmentType.equals("png")) { + out.println(""); + out.println(""); + } + } + out.println(""); + out.println(""); + } + + out.println(""); + } finally { + out.close(); + } + } + + private void responseReplies(HttpServletResponse response, int hours) throws IOException { + response.setContentType("application/rss+xml; charset=UTF-8"); + + PrintWriter out = response.getWriter(); + try { + + out.println(""); + out.println(""); + out.println(""); + out.println("Juick"); + out.println("http://juick.com/"); + out.println("The latest comments at Juick"); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users2.nick,replies.message_id,replies.reply_id,users.nick,replies.txt,DATE_FORMAT(replies.ts,'%a, %d %b %Y %T UT'),replies.attach,replies.ts+0 FROM ((replies INNER JOIN users ON replies.user_id=users.id) INNER JOIN messages ON replies.message_id=messages.message_id) INNER JOIN users AS users2 ON messages.user_id=users2.id WHERE replies.ts>TIMESTAMPADD(HOUR,?,NOW()) AND messages.privacy>0"); + stmt.setInt(1, -hours); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + String muname = rs.getString(1); + int mid = rs.getInt(2); + int rid = rs.getInt(3); + String uname = rs.getString(4); + + out.println(""); + out.println("http://juick.com/" + muname + "/" + mid + ""); + out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); + out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); + out.println("http://juick.com/" + uname + "/"); + out.println("@" + uname + ":"); + out.println(""); + out.println("" + rs.getString(6) + ""); + String attachment = rs.getString(7); + if (attachment != null && !attachment.isEmpty()) { + if (attachment.equals("jpg")) { + out.println(""); + out.println(""); + } else if (attachment.equals("png")) { + out.println(""); + out.println(""); + } + } + out.println(""); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println(""); + } finally { + out.close(); + } + } + + private ArrayList getLastMessages(int hours) { + ArrayList mids = new ArrayList(20); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())"); + stmt.setInt(1, -hours); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + mids.add(rs.getInt(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return mids; + } + private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?", ">"); + + // -- + // — + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2"); + + // http://juick.com/last?page=2 + // juick.com + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1$3"); + + // #12345 + // #12345 + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1#$2$3"); + + // #12345/65 + // #12345/65 + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1#$2/$3$4"); + + // *bold* + // bold + msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); + + // /italic/ + // italic + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); + + // _underline_ + // underline + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1$2$3"); + + // /12 + // /12 + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1/$2$3"); + + // @username@jabber.org + // @username@jabber.org + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3"); + + // @username + // @username + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3"); + + // (http://juick.com/last?page=2) + // (juick.com) + Matcher m = regexLinks2.matcher(msg); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", ""); + m.appendReplacement(sb, "$1$2$4$5"); + } + m.appendTail(sb); + msg = sb.toString(); + + // > citate + msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); + msg = msg.replaceAll("
", "\n"); + + msg = msg.replaceAll("\n", "
\n"); + return msg; + } +} diff --git a/src/main/java/com/juick/rss/Utils.java b/src/main/java/com/juick/rss/Utils.java new file mode 100644 index 00000000..a6842fe1 --- /dev/null +++ b/src/main/java/com/juick/rss/Utils.java @@ -0,0 +1,74 @@ +/* + * Juick + * Copyright (C) 2008-2011, ugnich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.juick.rss; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +/** + * + * @author ugnich + */ +public class Utils { + + public static void finishSQL(ResultSet rs, Statement stmt) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + } + } + } + + public static String convertArray2String(ArrayList mids) { + String q = ""; + for (int i = 0; i < mids.size(); i++) { + if (i > 0) { + q += ","; + } + q += mids.get(i); + } + return q; + } + + public static String encodeHTML(String str) { + String ret = str; + ret = ret.replaceAll("<", "<"); + ret = ret.replaceAll(">", ">"); + return str; + } + + public static int parseInt(String str, int def) { + int ret = def; + if (str != null) { + try { + ret = Integer.parseInt(str); + } catch (Exception e) { + } + } + return ret; + } +} diff --git a/web/META-INF/context.xml b/web/META-INF/context.xml deleted file mode 100644 index 5bee3dc3..00000000 --- a/web/META-INF/context.xml +++ /dev/null @@ -1,2 +0,0 @@ - - -- cgit v1.2.3 From 4d0d91d9cb408d0a323b18c1e5e609d74bdbba4c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 1 Dec 2015 03:26:56 +0300 Subject: escape html in tags --- src/main/java/com/juick/rss/Main.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/rss/Main.java b/src/main/java/com/juick/rss/Main.java index 9c0d803c..936c891d 100644 --- a/src/main/java/com/juick/rss/Main.java +++ b/src/main/java/com/juick/rss/Main.java @@ -171,7 +171,7 @@ public class Main extends HttpServlet { out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { - out.println("" + msg.Tags.get(n) + ""); + out.println("" + escapeHtml(msg.Tags.get(n)) + ""); } } if (msg.AttachmentType != null) { @@ -273,10 +273,12 @@ public class Main extends HttpServlet { } private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?", ">"); + } + public static String formatMessage(String msg) { - msg = msg.replaceAll("&", "&"); - msg = msg.replaceAll("<", "<"); - msg = msg.replaceAll(">", ">"); + msg = escapeHtml(msg); // -- // — -- cgit v1.2.3 From be18339f67341c02a071eddde94d230384a40a41 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 30 Jun 2016 13:50:47 +0300 Subject: update deps and apply changes --- .gitignore | 5 +- build.gradle | 14 +-- deps/com.juick | 2 +- deps/com.juick.server | 2 +- src/main/java/com/juick/rss/Main.java | 211 +++++++++++++-------------------- src/main/java/com/juick/rss/Utils.java | 38 ------ 6 files changed, 94 insertions(+), 178 deletions(-) (limited to 'src') diff --git a/.gitignore b/.gitignore index 48cc0990..e1a83f99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -/nbproject/private/ -/dist/ /build/ .gradle/* -deps/* \ No newline at end of file +deps/* +.idea/** \ No newline at end of file diff --git a/build.gradle b/build.gradle index ec4bede2..f936bc12 100644 --- a/build.gradle +++ b/build.gradle @@ -8,16 +8,15 @@ subprojects { buildscript { repositories { mavenCentral() - jcenter() } dependencies { - classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.+' + classpath 'org.akhikhl.gretty:gretty:+' } } apply plugin: 'java' apply plugin: 'war' -apply plugin: 'com.bmuschko.tomcat' +apply plugin: 'org.akhikhl.gretty' repositories { mavenCentral() @@ -36,17 +35,14 @@ dependencies { compile core compile server providedCompile 'javax.servlet:javax.servlet-api:3.1.0' - def tomcatVersion = '7.0.+' - tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", - "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", - "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}" testCompile 'junit:junit:4.12' - runtime 'mysql:mysql-connector-java:5.1.37' + runtime 'mysql:mysql-connector-java:5.1.39' } compileJava.options.encoding = 'UTF-8' -tomcat { +gretty { httpPort = 8080 contextPath = '/' + servletContainer = 'tomcat8' } diff --git a/deps/com.juick b/deps/com.juick index 5f08b8b1..39ec74ab 160000 --- a/deps/com.juick +++ b/deps/com.juick @@ -1 +1 @@ -Subproject commit 5f08b8b1cfaacf1e78c56e7752277533eb84b02e +Subproject commit 39ec74abe77cdab5aa8f50c2524e6f71c2dbbd01 diff --git a/deps/com.juick.server b/deps/com.juick.server index 23666546..79794224 160000 --- a/deps/com.juick.server +++ b/deps/com.juick.server @@ -1 +1 @@ -Subproject commit 23666546ca2c0f1ee492b1bea8c0ea83c8c04a2b +Subproject commit 797942249b0d5e38285e806bc0e73e755e6ffede diff --git a/src/main/java/com/juick/rss/Main.java b/src/main/java/com/juick/rss/Main.java index 936c891d..32e7ebae 100644 --- a/src/main/java/com/juick/rss/Main.java +++ b/src/main/java/com/juick/rss/Main.java @@ -20,66 +20,48 @@ package com.juick.rss; import com.juick.Message; import com.juick.server.MessagesQueries; import com.juick.server.UserQueries; -import java.io.FileInputStream; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DriverManagerDataSource; + +import javax.servlet.ServletException; +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.io.PrintWriter; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; +import java.util.List; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; /** - * * @author ugnich */ @WebServlet(name = "Main", urlPatterns = {"/"}) public class Main extends HttpServlet { - private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); - Connection sql; + JdbcTemplate sql; @Override public void init() throws ServletException { super.init(); try { Properties conf = new Properties(); - conf.load(new FileInputStream("/etc/juick/rss.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", "")); + conf.load(getServletContext().getResourceAsStream("/WEB-INF/juick.conf")); + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver")); + dataSource.setUrl(conf.getProperty("datasource_url")); + sql = new JdbcTemplate(dataSource); } catch (Exception e) { log(null, e); } } - @Override - public void destroy() { - super.destroy(); - if (sql != null) { - try { - sql.close(); - sql = null; - } catch (SQLException e) { - log(null, e); - } - } - } - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { @@ -90,8 +72,8 @@ public class Main extends HttpServlet { if (uri.equals("/")) { int hours = Utils.parseInt(request.getParameter("hours"), 0); if (hours > 0 && hours < 13) { - ArrayList mids = getLastMessages(hours); - ArrayList msgs = MessagesQueries.getMessages(sql, mids); + List mids = getLastMessages(hours); + List msgs = MessagesQueries.getMessages(sql, mids); responseMessages(response, 0, null, msgs); } else { response.sendError(404); @@ -107,9 +89,9 @@ public class Main extends HttpServlet { String uname = uri.substring(1, uri.length() - 5); int uid = UserQueries.getUIDbyName(sql, uname); if (uid > 0) { - ArrayList mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); + List mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); if (!mids.isEmpty()) { - ArrayList msgs = MessagesQueries.getMessages(sql, mids); + List msgs = MessagesQueries.getMessages(sql, mids); responseMessages(response, uid, uname, msgs); } else { response.sendError(404); @@ -122,11 +104,10 @@ public class Main extends HttpServlet { } } - private void responseMessages(HttpServletResponse response, int uid, String uname, ArrayList msgs) throws IOException { + private void responseMessages(HttpServletResponse response, int uid, String uname, List msgs) throws IOException { response.setContentType("application/rss+xml; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { out.println(""); out.println(""); out.println(""); @@ -142,33 +123,23 @@ public class Main extends HttpServlet { out.println("The latest messages at Juick"); } - Iterator i = msgs.iterator(); - while (i.hasNext()) { - Message msg = i.next(); - + for (Message msg : msgs) { out.println(""); - out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); - out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + ""); + out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + ""); - out.print("<![CDATA[@" + msg.User.UName + ":"); + out.print("<title><![CDATA[@" + msg.getUser().getUName() + ":"); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { out.print(" *" + msg.Tags.get(n)); } } out.println("]]>"); - out.println(""); - - synchronized (sdfSQL) { - try { - Date date = sdfSQL.parse(msg.TimestampString); - out.println("" + sdfRSS.format(date) + ""); - } catch (Exception e) { - System.err.println("PARSE EXCEPTION: " + msg.TimestampString); - } - } + out.println(""); + + out.println("" + sdfRSS.format(msg.getDate()) + ""); - out.println("http://juick.com/" + msg.User.UName + "/" + msg.MID + ""); + out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + ""); if (!msg.Tags.isEmpty()) { for (int n = 0; n < msg.Tags.size(); n++) { out.println("" + escapeHtml(msg.Tags.get(n)) + ""); @@ -176,28 +147,35 @@ public class Main extends HttpServlet { } if (msg.AttachmentType != null) { if (msg.AttachmentType.equals("jpg")) { - out.println(""); - out.println(""); + out.println(""); + out.println(""); } else if (msg.AttachmentType.equals("png")) { - out.println(""); - out.println(""); + out.println(""); + out.println(""); } } - out.println(""); + out.println(""); out.println(""); } out.println(""); - } finally { - out.close(); } } + private class ResponseReply { + String muname; + int mid; + int rid; + String uname; + String description; + Date pubDate; + String attachmentType; + } + private void responseReplies(HttpServletResponse response, int hours) throws IOException { response.setContentType("application/rss+xml; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { out.println(""); out.println(""); @@ -206,75 +184,56 @@ public class Main extends HttpServlet { out.println("http://juick.com/"); out.println("The latest comments at Juick"); - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT users2.nick,replies.message_id,replies.reply_id,users.nick,replies.txt,DATE_FORMAT(replies.ts,'%a, %d %b %Y %T UT'),replies.attach,replies.ts+0 FROM ((replies INNER JOIN users ON replies.user_id=users.id) INNER JOIN messages ON replies.message_id=messages.message_id) INNER JOIN users AS users2 ON messages.user_id=users2.id WHERE replies.ts>TIMESTAMPADD(HOUR,?,NOW()) AND messages.privacy>0"); - stmt.setInt(1, -hours); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - String muname = rs.getString(1); - int mid = rs.getInt(2); - int rid = rs.getInt(3); - String uname = rs.getString(4); - - out.println(""); - out.println("http://juick.com/" + muname + "/" + mid + ""); - out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); - out.println("http://juick.com/" + muname + "/" + mid + "#" + rid + ""); - out.println("http://juick.com/" + uname + "/"); - out.println("@" + uname + ":"); - out.println(""); - out.println("" + rs.getString(6) + ""); - String attachment = rs.getString(7); - if (attachment != null && !attachment.isEmpty()) { - if (attachment.equals("jpg")) { - out.println(""); - out.println(""); - } else if (attachment.equals("png")) { - out.println(""); - out.println(""); - } + sql.query("SELECT users2.nick,replies.message_id,replies.reply_id," + + "users.nick,replies.txt," + + "replies.ts,replies.attach,replies.ts+0 " + + "FROM ((replies INNER JOIN users ON replies.user_id=users.id) " + + "INNER JOIN messages ON replies.message_id=messages.message_id) " + + "INNER JOIN users AS users2 ON messages.user_id=users2.id " + + "WHERE replies.ts>TIMESTAMPADD(HOUR,?,NOW()) AND messages.privacy>0", (rs, rowNum) -> { + ResponseReply reply = new ResponseReply(); + reply.muname = rs.getString(1); + reply.mid = rs.getInt(2); + reply.rid = rs.getInt(3); + reply.uname = rs.getString(4); + reply.description = rs.getString(5); + reply.pubDate = rs.getTimestamp(6); + reply.attachmentType = rs.getString(7); + return reply; + }, -hours).stream().forEach(r -> { + out.println(""); + out.println("http://juick.com/" + r.muname + "/" + r.mid + ""); + out.println("http://juick.com/" + r.muname + "/" + r.mid + "#" + r.rid + ""); + out.println("http://juick.com/" + r.muname + "/" + r.mid + "#" + r.rid + ""); + out.println("http://juick.com/" + r.uname + "/"); + out.println("@" + r.uname + ":"); + out.println(""); + out.println("" + sdfRSS.format(r.pubDate) + ""); + String attachment = r.attachmentType; + if (attachment != null && !attachment.isEmpty()) { + if (attachment.equals("jpg")) { + out.println(""); + out.println(""); + } else if (attachment.equals("png")) { + out.println(""); + out.println(""); } - out.println(""); } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - + out.println(""); + }); out.println(""); - } finally { - out.close(); } } - private ArrayList getLastMessages(int hours) { - ArrayList mids = new ArrayList(20); - - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())"); - stmt.setInt(1, -hours); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - mids.add(rs.getInt(1)); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return mids; + private List getLastMessages(int hours) { + return sql.queryForList("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())", + Integer.class, -hours); } + private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?", ">"); + return input.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); } public static String formatMessage(String msg) { diff --git a/src/main/java/com/juick/rss/Utils.java b/src/main/java/com/juick/rss/Utils.java index a6842fe1..036a5a6b 100644 --- a/src/main/java/com/juick/rss/Utils.java +++ b/src/main/java/com/juick/rss/Utils.java @@ -17,50 +17,12 @@ */ package com.juick.rss; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; - /** * * @author ugnich */ public class Utils { - public static void finishSQL(ResultSet rs, Statement stmt) { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - } - } - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - } - } - } - - public static String convertArray2String(ArrayList mids) { - String q = ""; - for (int i = 0; i < mids.size(); i++) { - if (i > 0) { - q += ","; - } - q += mids.get(i); - } - return q; - } - - public static String encodeHTML(String str) { - String ret = str; - ret = ret.replaceAll("<", "<"); - ret = ret.replaceAll(">", ">"); - return str; - } - public static int parseInt(String str, int def) { int ret = def; if (str != null) { -- cgit v1.2.3 From 799523c4019fa4f6ef6d40e77b3f949fbe742c8f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 30 Jun 2016 14:00:58 +0300 Subject: add web.inf and example config --- src/main/webapp/WEB-INF/juick.conf.example | 2 ++ src/main/webapp/WEB-INF/web.xml | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/webapp/WEB-INF/juick.conf.example create mode 100644 src/main/webapp/WEB-INF/web.xml (limited to 'src') diff --git a/src/main/webapp/WEB-INF/juick.conf.example b/src/main/webapp/WEB-INF/juick.conf.example new file mode 100644 index 00000000..2cb6f4f7 --- /dev/null +++ b/src/main/webapp/WEB-INF/juick.conf.example @@ -0,0 +1,2 @@ +datasource_driver=org.h2.Driver +datasource_url=jdbc:h2:~/test diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..a4264bb0 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + + Main + com.juick.rss.Main + + + Main + / + + + + 30 + + + -- cgit v1.2.3