aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/UserThread.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-02-02 14:36:04 +0300
committerGravatar Vitaly Takmazov2016-02-02 14:36:04 +0300
commitbd3892546b51f0d31e959d45c138b009d35b2692 (patch)
tree3c3945f114472344cc3a8866391fa08f02975143 /src/main/java/com/juick/http/www/UserThread.java
parentf2a2660e753fa11478fd3edadfdff9c000b22cc9 (diff)
spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/http/www/UserThread.java')
-rw-r--r--src/main/java/com/juick/http/www/UserThread.java39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/main/java/com/juick/http/www/UserThread.java b/src/main/java/com/juick/http/www/UserThread.java
index fe5ca32f..f54aa925 100644
--- a/src/main/java/com/juick/http/www/UserThread.java
+++ b/src/main/java/com/juick/http/www/UserThread.java
@@ -21,14 +21,16 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
-import java.sql.Connection;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
*
@@ -36,7 +38,10 @@ import javax.servlet.http.HttpServletResponse;
*/
public class UserThread {
- protected void doGetThread(Connection sql, HttpServletRequest request, HttpServletResponse response, int MID) throws ServletException, IOException {
+ private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ protected void doGetThread(JdbcTemplate sql, HttpServletRequest request,
+ HttpServletResponse response, int MID) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (!MessagesQueries.canViewThread(sql, MID, visitor != null ? visitor.getUID() : 0)) {
@@ -68,8 +73,7 @@ public class UserThread {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getUName() + "\" href=\"//rss.juick.com/" + msg.getUser().getUName() + "/blog\"/>";
if (paramView != null) {
headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "\"/>";
@@ -93,12 +97,11 @@ public class UserThread {
out.println("</script>");
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- public static com.juick.Message printMessage(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor) {
+ public static com.juick.Message printMessage(PrintWriter out, JdbcTemplate sql,
+ com.juick.Message msg, com.juick.User visitor) {
msg.VisitorCanComment = visitor != null;
List<Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMID());
@@ -128,7 +131,7 @@ public class UserThread {
out.println(" <div class=\"msg-cont\">");
out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.getMID() + "); return false\"></a></div>");
out.println(" <div class=\"msg-header\"><a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:" + tagsStr + "</div>");
- out.println(" <div class=\"msg-ts\">" + PageTemplates.formatJSLocalTime(msg.TimestampString) + "</div>");
+ out.println(" <div class=\"msg-ts\">" + PageTemplates.formatJSLocalTime(msg.getDate()) + "</div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");
if (msg.AttachmentType != null) {
@@ -189,10 +192,10 @@ public class UserThread {
return msg;
}
- public static void printReplies(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor, boolean listview) {
+ public static void printReplies(PrintWriter out, JdbcTemplate sql, com.juick.Message msg, com.juick.User visitor, boolean listview) {
List<com.juick.Message> replies = MessagesQueries.getReplies(sql, msg.getMID());
- List<Integer> blUIDs = new ArrayList<Integer>();
+ List<Integer> blUIDs = new ArrayList<>();
for (int i = 0; i < replies.size(); i++) {
com.juick.Message reply = replies.get(i);
if (reply.getUser().getUID() != msg.getUser().getUID() && !blUIDs.contains(reply.getUser().getUID())) {
@@ -200,9 +203,9 @@ public class UserThread {
}
if (reply.ReplyTo > 0) {
boolean added = false;
- for (int n = 0; n < replies.size(); n++) {
- if (replies.get(n).getRID() == reply.ReplyTo) {
- replies.get(n).childs.add(reply);
+ for (Message reply1 : replies) {
+ if (reply1.getRID() == reply.ReplyTo) {
+ reply1.childs.add(reply);
added = true;
break;
}
@@ -301,7 +304,7 @@ public class UserThread {
} else {
out.println(" <div class=\"msg-header\">[удалено]:</div>");
}
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMID() + "#" + msg.getRID() + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMID() + "#" + msg.getRID() + "\" title=\"" + sdfSQL.format(msg.getDate()) + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.getDate()) + "</a></div>");
out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.getText()) + "</div>");
if (msg.AttachmentType != null) {
out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.getMID() + "-" + msg.getRID() + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.getMID() + "-" + msg.getRID() + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
@@ -345,7 +348,7 @@ public class UserThread {
} else {
out.println(" <div class=\"msg-header\">[удалено]:</div>");
}
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMID() + "#" + msg.getRID() + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMID() + "#" + msg.getRID() + "\" title=\"" + sdfSQL.format(msg.getDate()) + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.getDate()) + "</a></div>");
out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.getText()) + "</div>");
if (msg.AttachmentType != null) {
out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.getMID() + "-" + msg.getRID() + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.getMID() + "-" + msg.getRID() + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");