{"id":74,"date":"2010-04-05T21:09:57","date_gmt":"2010-04-05T19:09:57","guid":{"rendered":"http:\/\/www.pmannel.de\/wordpress\/?p=74"},"modified":"2011-01-08T17:37:48","modified_gmt":"2011-01-08T16:37:48","slug":"rss-feeds-mit-rome-spring-2-5","status":"publish","type":"post","link":"https:\/\/www.pmannel.de\/wordpress\/?p=74","title":{"rendered":"RSS-Feeds mit Rome &#038; Spring 2.5"},"content":{"rendered":"\n<p><strong>Problem: Wie  erzeuge ich einen RSS-Feed mit Rome und Spring MVC <\/strong><\/p>\n<p><strong>L\u00f6sung:<\/strong><\/p>\n<p>Man l\u00e4dt sich <a href=\"https:\/\/rome.dev.java.net\/\">Rome<\/a> und <a href=\"https:\/\/springmodules.dev.java.net\/\">Spring Modules<\/a> herunter und packt beide Jars in seinen Classpath.<\/p>\n<p>Danach erzeugt man einen RSSView:<\/p>\n<pre class=\"brush:java\">\r\npublic class RSSView extends AbstractRssView\r\n{\r\n\tprivate static final String[] FEED_TYPE = {\"rss_0.90\",\"rss_0.91\",\"rss_0.92\",\"rss_0.93\",\"rss_0.94\",\"rss_1.0\",\"rss_2.0\",\"atom_0.3\"};\t\r\n\r\n\tprivate static final DateFormat DATE_PARSER = new SimpleDateFormat(\"yyyy-MM-dd\");\r\n\r\n\tprivate String description;\r\n\r\n\t\/**\r\n\t * Generates the Feed.\r\n\t *\/\r\n\t@SuppressWarnings(\"unchecked\")\r\n\t@Override\r\n\tprotected void buildFeed(Map model, HttpServletRequest request, HttpServletResponse response, SyndFeed feed)\r\n\t{\r\n\t\tfeed.setFeedType(FEED_TYPE[6]);\r\n\r\n\t\tfeed.setTitle(\"Peters Feeds\");\r\n\t\tfeed.setLink(getBaseUrl());\r\n\t\tfeed.setDescription(description);\r\n\r\n\t\tSyndImage image \t= new SyndImageImpl();\r\n\t\timage.setLink(getBaseUrl());\r\n\t\timage.setUrl(\"URLTOIMAGE\");\r\n\t\timage.setDescription(description);\r\n\t\timage.setTitle(\"Peter\");\r\n\t\tfeed.setImage(image);\r\n\r\n\t\tList<SyndEntry> entries = new ArrayList<SyndEntry>();\r\n\t\tSyndEntry entry;\r\n\r\n\t\tentry = new SyndEntryImpl();\r\n\t\tentry.setTitle(\"Rome v1.0\");\r\n\t\tentry.setLink(\"http:\/\/wiki.java.net\/bin\/view\/Javawsxml\/Rome01\");\r\n\t\tentry.setPublishedDate(DATE_PARSER.parse(\"2004-06-08\"));\r\n\t\tdescription = new SyndContentImpl();\r\n\t\tdescription.setType(\"text\/plain\");\r\n\t\tdescription.setValue(\"Initial release of Rome\");\r\n\t\tentry.setDescription(description);\r\n\t\tentries.add(entry);\r\n\r\n\t\tentry = new SyndEntryImpl();\r\n\t\tentry.setTitle(\"Rome v2.0\");\r\n\t\tentry.setLink(\"http:\/\/wiki.java.net\/bin\/view\/Javawsxml\/Rome02\");\r\n\t\tentry.setPublishedDate(DATE_PARSER.parse(\"2004-06-16\"));\r\n\t\tdescription = new SyndContentImpl();\r\n\t\tdescription.setType(\"text\/plain\");\r\n\t\tdescription.setValue(\"Bug fixes, minor API changes and some new features\");\r\n\t\tentry.setDescription(description);\r\n\t\tentries.add(entry);\r\n\r\n\t\tfeed.setEntries(entries);\r\n\r\n\t}\r\n\r\n\tpublic void setDescription(String description)\r\n\t{\r\n\t\tthis.description = description;\r\n\t}\r\n\r\n}\r\n\r\n<\/pre>\n<p>Anschlie\u00dfend erzeugt man den dazugeh\u00f6rigen Controller:<\/p>\n<pre class=\"brush:java\">\r\npublic class RssFeedController implements Controller\r\n{\r\n\r\n\t@Override\r\n\tpublic ModelAndView handleRequest(HttpServletRequest arg0,\r\n\t\t\tHttpServletResponse arg1) throws Exception\r\n\t{\r\n\r\n\t\treturn  new ModelAndView(\"rSSView\");\r\n\t}\r\n}\r\n\r\n<\/pre>\n<p>Als Letztes verdrahtet man alles in seiner dispatcher.xml:<\/p>\n<pre class=\"brush:xml\">\r\n...\r\n<prop key=\"\/feed.rss\">RssFeedController<\/prop>\r\n\r\n\t<bean id=\"rSSView\" class=\"de.test.mvc.views.RSSView\">\r\n<property name=\"description\" value=\"Ein Beispielfeed mit Spring &#038; Rome\">\r\n\t<\/property>\r\n\r\n\t<bean id=\"RssFeedController\" class=\"de.test.mvc.controller.RssFeedController\">\r\n\t<\/bean>\r\n...\r\n<\/bean>\r\n<\/pre>\n<p>\u2026 ab Version 3.0 des Springframework kann man das ganz einfach <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.0.x\/spring-framework-reference\/html\/view.html#view-feeds\">so <\/a>machen.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: Wie erzeuge ich einen RSS-Feed mit Rome und Spring MVC L\u00f6sung: Man l\u00e4dt sich Rome und Spring Modules herunter und packt beide Jars in seinen Classpath. Danach erzeugt man einen RSSView: public class RSSView extends AbstractRssView { private static final String[] FEED_TYPE = {&#8222;rss_0.90&#8243;,&#8220;rss_0.91&#8243;,&#8220;rss_0.92&#8243;,&#8220;rss_0.93&#8243;,&#8220;rss_0.94&#8243;,&#8220;rss_1.0&#8243;,&#8220;rss_2.0&#8243;,&#8220;atom_0.3&#8220;}; private static final DateFormat DATE_PARSER = new SimpleDateFormat(&#8222;yyyy-MM-dd&#8220;); private String&#8230; <\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.pmannel.de\/wordpress\/?p=74\">Weiterlesen<\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,10],"tags":[30,29,28],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-java","category-spring-mvc","tag-feeds","tag-rome","tag-rss"],"_links":{"self":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":3,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}