package com.kudrevatykh.integration.bash;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;

import com.sun.syndication.feed.atom.Content;
import com.sun.syndication.feed.atom.Entry;

@Component
public class AtomFeedView extends AbstractAtomFeedView {

	@Override
	protected List<Entry> buildFeedEntries(Map<String, Object> model,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		@SuppressWarnings("unchecked")
		List<Map<String, Object>> rss = (List<Map<String, Object>>) model
				.get("rss");
		List<Entry> list = new ArrayList<Entry>(rss.size());
		for (Map<String, Object> m : rss) {
			Entry e = new Entry();
			e.setPublished((Date) m.get("date"));
			e.setId((String) m.get("id"));
			Content c = new Content();
			c.setType(Content.HTML);
			c.setValue((String) m.get("text"));
			e.setContents(Collections.singletonList(c));
			list.add(e);
		}
		return list;
	}

}

@@ -467,16 +467,59 @@
 m.Entry;
+%0Aimport com.sun.syndication.feed.atom.Feed;
 %0A%0A@Compo
@@ -581,16 +581,79 @@
 View %7B%0A%0A
+%09private static String FEED_URL = %22http://bash.im/abyssbest%22;%0A%0A
 %09@Overri
@@ -805,16 +805,58 @@
 ption %7B%0A
+%09%09response.setCharacterEncoding(%22UTF-8%22);%0A
 %09%09@Suppr
@@ -1137,10 +1137,13 @@
 .set
-Id
+Title
 ((St
@@ -1327,16 +1327,16 @@
 e);%0A%09%09%7D%0A
-
 %09%09return
@@ -1346,10 +1346,382 @@
 st;%0A%09%7D%0A%0A
+%09@Override%0A%09protected void buildFeedMetadata(Map%3CString, Object%3E model, Feed feed,%0A%09%09%09HttpServletRequest request) %7B%0A%09%09feed.setTitle(%22bash abyss%22);%0A%09%09feed.setId(FEED_URL);%0A%09%09@SuppressWarnings(%22unchecked%22)%0A%09%09List%3CMap%3CString, Object%3E%3E rss = (List%3CMap%3CString, Object%3E%3E) model%0A%09%09%09%09.get(%22rss%22);%0A%09%09if (!rss.isEmpty()) %7B%0A%09%09%09feed.setUpdated((Date) rss.get(0).get(%22date%22));%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

fix atom feed