aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/RSS.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-14 12:16:49 +0300
committerGravatar Vitaly Takmazov2016-01-14 12:16:49 +0300
commitc492429b25c1ef711620a4f509975c7edc3ffa4a (patch)
tree5bc6b5746381d970760cd6ae5c5561e66a1f95e7 /src/main/java/com/juick/http/www/RSS.java
parent7e93e142b6dd75c22c057962447eec014c4e15b4 (diff)
Update libraries and refactoring
Diffstat (limited to 'src/main/java/com/juick/http/www/RSS.java')
-rw-r--r--src/main/java/com/juick/http/www/RSS.java36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/main/java/com/juick/http/www/RSS.java b/src/main/java/com/juick/http/www/RSS.java
index ab96221e..72893915 100644
--- a/src/main/java/com/juick/http/www/RSS.java
+++ b/src/main/java/com/juick/http/www/RSS.java
@@ -23,9 +23,9 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -40,17 +40,16 @@ public class RSS {
private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException {
- ArrayList<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
+ List<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
if (mids.isEmpty()) {
response.sendError(404);
return;
}
- ArrayList<Message> msgs = MessagesQueries.getMessages(sql, mids);
+ List<Message> msgs = MessagesQueries.getMessages(sql, mids);
response.setContentType("application/rss+xml; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
out.println("<?xml version='1.0' encoding='utf-8'?>");
out.println("<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:slash='http://purl.org/rss/1.0/modules/slash/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:media='http://search.yahoo.com/mrss/' xmlns:juick='http://juick.com/'>");
out.println("<channel>");
@@ -60,22 +59,19 @@ public class RSS {
out.println("<description>The latest messages by @" + uname + " at Juick</description>");
out.println("<image><url>http://i.juick.com/a/" + uid + ".png</url><title>" + uname + " - Juick</title><link>http://juick.com/" + uname + "/</link></image>");
- Iterator<Message> i = msgs.iterator();
- while (i.hasNext()) {
- Message msg = i.next();
-
+ for (Message msg : msgs) {
out.println("<item>");
- out.println("<link>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</link>");
- out.println("<guid>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</guid>");
+ out.println("<link>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</link>");
+ out.println("<guid>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</guid>");
- out.print("<title><![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("]]></title>");
- out.println("<description><![CDATA[" + PageTemplates.formatMessage(msg.Text) + "]]></description>");
+ out.println("<description><![CDATA[" + PageTemplates.formatMessage(msg.getText()) + "]]></description>");
synchronized (sdfSQL) {
try {
@@ -86,7 +82,7 @@ public class RSS {
}
}
- out.println("<comments>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</comments>");
+ out.println("<comments>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</comments>");
if (!msg.Tags.isEmpty()) {
for (int n = 0; n < msg.Tags.size(); n++) {
out.println("<category>" + msg.Tags.get(n) + "</category>");
@@ -94,20 +90,18 @@ public class RSS {
}
if (msg.AttachmentType != null) {
if (msg.AttachmentType.equals("jpg")) {
- out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.MID + ".jpg' type='image/jpeg'/>");
- out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.MID + ".jpg'/>");
+ out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.getMID() + ".jpg' type='image/jpeg'/>");
+ out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".jpg'/>");
} else if (msg.AttachmentType.equals("png")) {
- out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.MID + ".png' type='image/png'/>");
- out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.MID + ".png'/>");
+ out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.getMID() + ".png' type='image/png'/>");
+ out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".png'/>");
}
}
- out.println("<juick:user uid='" + msg.User.UID + "'/>");
+ out.println("<juick:user uid='" + msg.getUser().getUID() + "'/>");
out.println("</item>");
}
out.println("</channel></rss>");
- } finally {
- out.close();
}
}
}