diff options
author | Vitaly Takmazov | 2016-07-07 15:13:47 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-07-07 15:13:47 +0300 |
commit | e5c8298beee5dde90ca98cc4707faac4bf0e2f0c (patch) | |
tree | 10178a0103ae8ac17849e56914b87b0ee681d0ba /juick-www/src/main/java/com/juick/www/RSS.java | |
parent | d85424021a63c1519e18bd6518ad3424de61fb9f (diff) |
reorganize project
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 | 101 |
1 files changed, 101 insertions, 0 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 new file mode 100644 index 00000000..48510ce3 --- /dev/null +++ b/juick-www/src/main/java/com/juick/www/RSS.java @@ -0,0 +1,101 @@ +/* + * Juick + * Copyright (C) 2008-2013, ugnich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.juick.www; + +import com.juick.Message; +import com.juick.server.MessagesQueries; +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.List; + +/** + * + * @author ugnich + */ +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 { + List<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0); + if (mids.isEmpty()) { + response.sendError(404); + return; + } + + List<Message> msgs = MessagesQueries.getMessages(sql, mids); + + 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[" + PageTemplates.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>"); + } + } +} |