diff options
author | 2016-09-15 01:51:30 +0300 | |
---|---|---|
committer | 2016-09-15 02:42:29 +0300 | |
commit | d9379351e992704c7b93ed0b74d2e1c60e166538 (patch) | |
tree | 80632d4d7d13a38f999b9cf5414c2c4f2bb52539 /juick-www/src/main/java/com/juick/www/RSS.java | |
parent | f48b4f81a48745895e3e76c173ad8e63b71c55a1 (diff) |
juick-www: signup/rss -> pebble
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/RSS.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/RSS.java | 63 |
1 files changed, 13 insertions, 50 deletions
diff --git a/juick-www/src/main/java/com/juick/www/RSS.java b/juick-www/src/main/java/com/juick/www/RSS.java index 23120140..f27ea539 100644 --- a/juick-www/src/main/java/com/juick/www/RSS.java +++ b/juick-www/src/main/java/com/juick/www/RSS.java @@ -19,16 +19,18 @@ package com.juick.www; import com.juick.Message; import com.juick.server.MessagesQueries; +import com.mitchellbosecke.pebble.error.PebbleException; +import com.mitchellbosecke.pebble.template.PebbleTemplate; 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.text.SimpleDateFormat; -import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @@ -38,7 +40,7 @@ public class RSS { private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); - protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException { + protected void doGet(JdbcTemplate sql, HttpServletResponse response, int uid) throws ServletException, IOException, PebbleException { List<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); if (mids.isEmpty()) { response.sendError(404); @@ -47,55 +49,16 @@ public class RSS { List<Message> msgs = MessagesQueries.getMessages(sql, mids); + msgs.forEach(m -> Utils.formatMessage(m.getText())); + response.setContentType("application/rss+xml; charset=UTF-8"); 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>"); - out.println("<atom:link href='http://rss.juick.com/" + uname + "/blog' rel='self' type='application/rss+xml'/>"); - out.println("<title>" + uname + " - Juick</title>"); - out.println("<link>http://juick.com/" + uname + "/</link>"); - 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>"); - - for (Message msg : msgs) { - out.println("<item>"); - 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.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[" + Utils.formatMessage(msg.getText()) + "]]></description>"); - - Date date = msg.getDate(); - out.println("<pubDate>" + sdfRSS.format(date) + "</pubDate>"); - - - 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>"); - } - } - if (msg.AttachmentType != null) { - if (msg.AttachmentType.equals("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.getMID() + ".png' type='image/png'/>"); - out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".png'/>"); - } - } - out.println("<juick:user uid='" + msg.getUser().getUID() + "'/>"); - out.println("</item>"); - } - - out.println("</channel></rss>"); + PebbleTemplate template = Utils.getEngine().getTemplate("layouts/rss.xml"); + Map<String, Object> context = new HashMap<>(); + context.put("user", msgs.stream().findFirst().get().getUser()); + context.put("msgs", msgs); + context.put("sdfRSS", sdfRSS); + template.evaluate(out, context); } } } |