From d9379351e992704c7b93ed0b74d2e1c60e166538 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 15 Sep 2016 01:51:30 +0300 Subject: juick-www: signup/rss -> pebble --- juick-www/src/main/java/com/juick/www/RSS.java | 63 ++++++-------------------- 1 file changed, 13 insertions(+), 50 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/RSS.java') 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 mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); if (mids.isEmpty()) { response.sendError(404); @@ -47,55 +49,16 @@ public class RSS { List 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(""); - out.println(""); - out.println(""); - 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 + "/"); - - for (Message msg : msgs) { - out.println(""); - out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + ""); - out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + ""); - - out.print("<![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(""); - - Date date = msg.getDate(); - out.println("" + sdfRSS.format(date) + ""); - - - 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("" + 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(""); + PebbleTemplate template = Utils.getEngine().getTemplate("layouts/rss.xml"); + Map context = new HashMap<>(); + context.put("user", msgs.stream().findFirst().get().getUser()); + context.put("msgs", msgs); + context.put("sdfRSS", sdfRSS); + template.evaluate(out, context); } } } -- cgit v1.2.3