Skip to content

Instantly share code, notes, and snippets.

@javajosh
Created June 18, 2010 23:22
Show Gist options
  • Save javajosh/444353 to your computer and use it in GitHub Desktop.
Save javajosh/444353 to your computer and use it in GitHub Desktop.
<%@ page language="java" contentType="text/xml" pageEncoding="ISO-8859-1" import="java.util.*"%><%
class FeedItem{
String title,link,description;Date updated;
FeedItem(String title, String link, String description)
{this.title=title;this.link=link;this.description=description;this.updated=new Date();};
}
List<FeedItem> items = new ArrayList<FeedItem>(){{
add(new FeedItem("wow, isn't that neat 1?","http://javajosh.com/1","whatever you <b>want</b>, dude"));
add(new FeedItem("wow, isn't that neat 2?","http://javajosh.com/2","whatever you want, dude"));
add(new FeedItem("wow, isn't that neat 3?","http://javajosh.com/3","whatever you want, dude"));
}};
String title, link, description;
title = "An example feed title";
link="http://javajosh.com";
description ="An example description of my cool feed";
String updated = new Date().toGMTString(); //atom
boolean rss = false;
response.setContentType(rss ? "application/rss+xml" : "application/atom+xml");
%>
<% if (rss){ %>
<rss version="2.0">
<channel>
<title><%=title%></title>
<link><%=link%></link>
<description><%=description%></description>
<% for (FeedItem item:items){ %>
<item>
<title><%=item.title%></title>
<link><%=item.link %></link>
<description><%=item.description%></description>
</item>
<% } %>
</channel>
</rss>
<%}else{ //atom %>
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><%=title%></title>
<updated><%=updated%></updated>
<id><%=link%></id>
<% for (FeedItem item:items){ %>
<entry>
<id><%=item.link %></id>
<title><%=item.title %></title>
<updated><%=item.updated %></updated>
<content><%=item.description %></content>
</entry>
<% } %>
</feed>
<%}%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment