diff options
author | 2016-01-14 12:16:49 +0300 | |
---|---|---|
committer | 2016-01-14 12:16:49 +0300 | |
commit | c492429b25c1ef711620a4f509975c7edc3ffa4a (patch) | |
tree | 5bc6b5746381d970760cd6ae5c5561e66a1f95e7 /src/main/java/com/juick/http/www/NewMessage.java | |
parent | 7e93e142b6dd75c22c057962447eec014c4e15b4 (diff) |
Update libraries and refactoring
Diffstat (limited to 'src/main/java/com/juick/http/www/NewMessage.java')
-rw-r--r-- | src/main/java/com/juick/http/www/NewMessage.java | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java index 3cf73882..86725db7 100644 --- a/src/main/java/com/juick/http/www/NewMessage.java +++ b/src/main/java/com/juick/http/www/NewMessage.java @@ -37,6 +37,7 @@ import java.net.URL; import java.net.URLEncoder; import java.sql.Connection; import java.util.ArrayList; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -88,7 +89,7 @@ public class NewMessage { } void printUserTags(Connection sql, PrintWriter out, com.juick.User visitor) { - ArrayList<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.UID); + List<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.getUID()); if (tags.isEmpty()) { return; @@ -114,7 +115,7 @@ public class NewMessage { } String taglink = ""; try { - taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/" + visitor.UName + "/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>"; + taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/" + visitor.getUName() + "/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>"; } catch (UnsupportedEncodingException e) { } int usagecnt = tags.get(i).UsageCnt; @@ -142,7 +143,7 @@ public class NewMessage { body = body.replace("\r", ""); String tagsStr = request.getParameter("tags"); - ArrayList<com.juick.Tag> tags = new ArrayList<Tag>(); + List<com.juick.Tag> tags = new ArrayList<Tag>(); String tagsArr[] = new String[1]; if (tagsStr != null && !tagsStr.isEmpty()) { tagsArr = tagsStr.split("[ \\,]"); @@ -182,8 +183,8 @@ public class NewMessage { } String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null; - int mid = MessagesQueries.createMessage(sql, visitor.UID, body, attachmentType, tags); - SubscriptionsQueries.subscribeMessage(sql, mid, visitor.UID); + int mid = MessagesQueries.createMessage(sql, visitor.getUID(), body, attachmentType, tags); + SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUID()); Message xmsg = new Message(); xmsg.from = new JID("juick", "juick.com", null); @@ -194,7 +195,7 @@ public class NewMessage { xmsg.addChild(jmsg); Nickname nick = new Nickname(); - nick.Nickname = "@" + jmsg.User.UName; + nick.Nickname = "@" + jmsg.getUser().getUName(); xmsg.addChild(nick); if (attachmentFName != null) { @@ -210,10 +211,10 @@ public class NewMessage { } String tagsStr2 = ""; - for (int i = 0; i < tagsArr.length; i++) { - tagsStr2 += " *" + tagsArr[i]; + for (String tag : tagsArr) { + tagsStr2 += " *" + tag; } - xmsg.body = "@" + jmsg.User.UName + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid; + xmsg.body = "@" + jmsg.getUser().getUName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid; xmsg.to = new JID("juick", "s2s.juick.com", null); xmpp.send(xmsg); @@ -237,8 +238,7 @@ public class NewMessage { // response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { PageTemplates.pageHead(out, "Сообщение опубликовано", null); PageTemplates.pageNavigation(out, visitor, null); PageTemplates.pageHomeColumn(out, sql, visitor); @@ -265,12 +265,12 @@ public class NewMessage { out.println("<section id=\"content\">"); out.println("<h1>Сообщение опубликовано</h1>"); out.println("<p>Поделитесь своим новым постом в социальных сетях:</p>"); - if (CrosspostQueries.getTwitterTokens(sql, visitor.UID) == null) { + if (CrosspostQueries.getTwitterTokens(sql, visitor.getUID()) == null) { out.println("<p><a href=\"https://twitter.com/intent/tweet?text=" + URLEncoder.encode(sharetwi, "utf-8") + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-twi sharenew\">Отправить в Twitter</a></p>"); } out.println("<p><a href=\"http://www.livejournal.com/update.bml?subject=" + URLEncoder.encode(hashtags, "utf-8") + "&event=" + sharelj + "&prop_taglist=" + URLEncoder.encode(tagscomma, "utf-8") + "\" target=\"_blank\" class=\"ico32-lj sharenew\">Отправить в LiveJournal</a></p>"); out.println("<p><a href=\"https://vk.com/share.php?url=" + url + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-vk sharenew\">Отправить в ВКонтакте</a></p>"); - if (CrosspostQueries.getFacebookToken(sql, visitor.UID) == null) { + if (CrosspostQueries.getFacebookToken(sql, visitor.getUID()) == null) { out.println("<p><a href=\"https://www.facebook.com/sharer/sharer.php?u=" + url + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-fb sharenew\">Отправить в Facebook</a></p>"); } out.println("<p><a href=\"https://plus.google.com/share?url=" + url + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-gp sharenew\">Отправить в Google+</a></p>"); @@ -279,8 +279,6 @@ public class NewMessage { PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); - } finally { - out.close(); } } @@ -313,7 +311,7 @@ public class NewMessage { } body = body.replace("\r", ""); - if ((msg.ReadOnly && msg.User.UID != visitor.UID) || UserQueries.isInBLAny(sql, msg.User.UID, visitor.UID) || (reply != null && UserQueries.isInBLAny(sql, reply.User.UID, visitor.UID))) { + if ((msg.ReadOnly && msg.getUser().getUID() != visitor.getUID()) || UserQueries.isInBLAny(sql, msg.getUser().getUID(), visitor.getUID()) || (reply != null && UserQueries.isInBLAny(sql, reply.getUser().getUID(), visitor.getUID()))) { response.sendError(403); return; } @@ -339,8 +337,8 @@ public class NewMessage { } String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null; - int ridnew = MessagesQueries.createReply(sql, mid, rid, visitor.UID, body, attachmentType); - SubscriptionsQueries.subscribeMessage(sql, mid, visitor.UID); + int ridnew = MessagesQueries.createReply(sql, mid, rid, visitor.getUID(), body, attachmentType); + SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUID()); Message xmsg = new Message(); xmsg.from = new JID("juick", "juick.com", null); @@ -350,13 +348,13 @@ public class NewMessage { JuickMessage jmsg = new JuickMessage(MessagesQueries.getReply(sql, mid, ridnew)); xmsg.addChild(jmsg); - String quote = reply != null ? reply.Text : msg.Text; + String quote = reply != null ? reply.getText() : msg.getText(); if (quote.length() >= 50) { quote = quote.substring(0, 47) + "..."; } Nickname nick = new Nickname(); - nick.Nickname = "@" + jmsg.User.UName; + nick.Nickname = "@" + jmsg.getUser().getUName(); xmsg.addChild(nick); if (attachmentFName != null) { @@ -371,7 +369,7 @@ public class NewMessage { xmsg.addChild(xoob); } - xmsg.body = "Reply by @" + jmsg.User.UName + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew; + xmsg.body = "Reply by @" + jmsg.getUser().getUName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew; xmsg.to = new JID("juick", "s2s.juick.com", null); xmpp.send(xmsg); @@ -382,7 +380,7 @@ public class NewMessage { xmsg.to.Host = "push.juick.com"; xmpp.send(xmsg); - Utils.sendTemporaryRedirect(response, "/" + msg.User.UName + "/" + mid + "#" + ridnew); + Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getUName() + "/" + mid + "#" + ridnew); } public void doPostRecomm(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException { @@ -396,20 +394,20 @@ public class NewMessage { response.sendError(404); return; } - if (msg.User.UID == visitor.UID) { + if (msg.getUser().getUID() == visitor.getUID()) { response.sendError(403); return; } - boolean res = MessagesQueries.recommendMessage(sql, mid, visitor.UID); + boolean res = MessagesQueries.recommendMessage(sql, mid, visitor.getUID()); if (res) { Message xmsg = new Message(); xmsg.from = new JID("juick", "juick.com", null); xmsg.to = new JID("recomm", "s2s.juick.com", null); JuickMessage jmsg = new JuickMessage(); - jmsg.MID = mid; - jmsg.User = new JuickUser(visitor); + jmsg.setMID(mid); + jmsg.setUser(new JuickUser(visitor)); xmsg.addChild(jmsg); xmpp.send(xmsg); |