{"id":13923,"date":"2014-05-28T17:04:47","date_gmt":"2014-05-28T11:34:47","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=13923"},"modified":"2014-05-28T17:04:47","modified_gmt":"2014-05-28T11:34:47","slug":"rome-tools-all-feeds-lead-to-rome","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/rome-tools-all-feeds-lead-to-rome\/","title":{"rendered":"ROME Tools  &#8211;\u201cAll Feeds Lead To Rome&#8221;"},"content":{"rendered":"<p>In our grails application, we recently met with a requirement where we had to facilitate the application user to post his blog post url in our application. The application then had to fetch the blog post&#8217;s content and the fetched content had to be displayed in our application. The other part of this requirement was that we had to use the blog&#8217;s feed url to fetch the content.<\/p>\n<p>Aware of the fact that the feed&#8217;s structure would vary with the varying feed formats, and that we were a little too short of time, the manual processing of all formats was out of question. A little research on the requirement, our good &#8216;ol friend Google helped us reach the doorstep of Rome Tools.<\/p>\n<p>The sign on the board read \u201cAll Feeds Lead To Rome\u201d.<\/p>\n<p>Stepping inside we found that we had hit the jackpot. Upon further research on how Rome works this is what we found.<\/p>\n<p><strong>Configuration Requirements:-<\/strong><\/p>\n<p>Add the following jar dependency in your BuilConfig.groovy<\/p>\n<p>[groovy]runtime &#8216;rome:rome:1.0&#8242;[\/groovy]<\/p>\n<p><strong>Here&#8217;s how:<\/strong><\/p>\n<p>[groovy]dependencies{<br \/>\nruntime &#8216;rome:rome:1.0&#8217;<br \/>\n}[\/groovy]<\/p>\n<p>ROME, includes a set of parsers and generators for the various syndication feeds formats and the converters to convert from one format to another. The parsers can then give you back Java objects that are of a generic normalized SyndFeed class.<\/p>\n<p>This lets you work on with the data without bothering about the incoming or outgoing feed type. All you need is a feed url and the following three lines of code.<\/p>\n<p>[groovy]URL feedUrl = new URL(&lt;rss feed url to parse&gt;;);<br \/>\nSyndFeedInput input = new SyndFeedInput();<br \/>\nSyndFeed feed = input.build(new XmlReader(feedUrl));[\/groovy]<\/p>\n<p>Pretty neat isn&#8217;t it.!!<\/p>\n<p>Well, now here is a brief about what the above code does that makes your life easier.<\/p>\n<p><strong>I. Creating a SyndFeedInput instance<\/strong><\/p>\n<p>[groovy]SyndFeedInput input = new SyndFeedInput();[\/groovy]<\/p>\n<p>The above line of code calls SyndFeedInput to parse the feed. It creates a SyndFeedInput instance that will work with any syndication feed type (RSS and Atom versions)<\/p>\n<p><strong>II. Reading the syndication feed and extracting the parsed feed<\/strong><\/p>\n<p>[groovy]SyndFeed feed = input.build(new XmlReader(feedUrl));[\/groovy]<\/p>\n<p>The above line of code instructs the SyndFeedInput to read the syndication feed from the character based input stream of the URL pointing to the feed.<\/p>\n<p><strong>Following is a brief about how ROME makes this happen:<\/strong><\/p>\n<p>1. The <strong>SyndFeedInput.build()<\/strong> method returns a <strong>SyndFeed<\/strong> instance that can be easily processed.<\/p>\n<p>2. <strong>SyndFeedInput<\/strong> delegates to <strong>WireFeedInput<\/strong> to do the actual parsing. The <strong>WireFeedInput<\/strong> uses a <strong>PluginManager<\/strong> of class <strong>FeedParsers<\/strong> to pick the right parser that then parses the feed. The developer does not need to worry about selecting the right parser for a syndication feed, the <strong>SyndFeedInput<\/strong> will take care of it by peeking at the syndication feed structure.<\/p>\n<p>3. The parser then, using <strong>JDom<\/strong>, parses the feed into a <strong>WireFeed<\/strong>. The returned <strong>WireFeed<\/strong> is an instance of class:<\/p>\n<p>  i)  <strong>Channel<\/strong>, if the feed is in an RSS format.<br \/>\n  ii) <strong>Feed<\/strong>, if the feed is in Atom format.<\/p>\n<p>4. <strong>SyndFeedInput<\/strong> then uses the returned <strong>WireFeedInput<\/strong> to create a <strong>SyndFeedImpl<\/strong> that implements <strong>SyndFeed<\/strong> (an interface that represents a format independent feed).<\/p>\n<p>5. <strong>SyndFeedImpl<\/strong> then with the <strong>SyndFeedInput.build()<\/strong> command converts the format specific <strong>WireFeed<\/strong> to a format-independent <strong>SyndFeed<\/strong> instance.<\/p>\n<p>6. The <strong>SyndFeedInput<\/strong> then returns to you the <strong>SyndFeed<\/strong> containing the parsed feed.<\/p>\n<p><strong>Supported Formats:-<\/strong><br \/>\nRSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0<\/p>\n<p>For furthur understanding of ROME, refer to the following link for documentation:<br \/>\n<a href=\"http:\/\/rometools.github.io\/rome\/index.html\" title=\"http:\/\/rometools.github.io\/rome\/index.html\">http:\/\/rometools.github.io\/rome\/index.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our grails application, we recently met with a requirement where we had to facilitate the application user to post his blog post url in our application. The application then had to fetch the blog post&#8217;s content and the fetched content had to be displayed in our application. The other part of this requirement was [&hellip;]<\/p>\n","protected":false},"author":80,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/13923"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/80"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=13923"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/13923\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=13923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=13923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=13923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}