{"id":1001,"date":"2007-09-13T13:06:08","date_gmt":"2007-09-13T21:06:08","guid":{"rendered":"http:\/\/cephas.net\/blog\/2007\/09\/13\/using-rome-to-get-the-body-summary-of-an-item\/"},"modified":"2007-09-13T13:06:08","modified_gmt":"2007-09-13T21:06:08","slug":"using-rome-to-get-the-body-summary-of-an-item","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2007\/09\/13\/using-rome-to-get-the-body-summary-of-an-item\/","title":{"rendered":"Using ROME to get the body \/ summary of an item"},"content":{"rendered":"<p>I&#8217;ve been using <a href=\"https:\/\/rome.dev.java.net\/\">ROME<\/a> for a couple years now and I&#8217;m still learning new things. Today I was working on an issue in <a href=\"http:\/\/www.jivesoftware.com\/products\/clearspace\/\">Clearspace<\/a> where we give users the ability to show RSS \/ Atom feeds in a widget, optionally giving them the choice to show the full content of each item in the feed or just a summary of each item in the feed. The existing logic \/ pseudo-code looked something like this:<\/p>\n<pre>for (SyndEntry entry : feed.getEntries()) {\r\n  if (showFullContent) {\r\n    write(entry.getContents()[0].value);\r\n  } else {\r\n    write(entry.getDescription().value);\r\n  }\r\n}<\/pre>\n<p>The assumption was that description would return a summary and contents would return the full content. The problem is that Atom and RSS are spec&#8217;ed umm.. differently.  <a href=\"http:\/\/cyber.law.harvard.edu\/rss\/rss.html#hrelementsOfLtitemgt\">RSS 2.0<\/a> says that &#8216;description&#8217; is a synopsis of the item but then goes on <a href=\"http:\/\/cyber.law.harvard.edu\/rss\/encodingDescriptions.html\">in an example<\/a> to show how the description can be much more than just a short plain text description. So then you&#8217;re left with descriptions that aren&#8217;t really a synopsis, it&#8217;s the full content&#8230; or <a href=\"http:\/\/www.cincomsmalltalk.com\/blog\/blogView?showComments=true&#038;entry=3322638507\">it is sometimes and sometimes not<\/a>.  Then Atom came along with <a href=\"http:\/\/www.ietf.org\/rfc\/rfc4287.txt\">well defined atom:summary and atom:content elements<\/a> which means ROME had to figure out a way to map description and <a href=\"http:\/\/web.resource.org\/rss\/1.0\/modules\/content\/\">content-encoded<\/a> elements in RSS to atom:summary and atom:content.  Dave Johnson summarized the mappings nicely in <a href=\"http:\/\/rollerweblogger.org\/roller\/entry\/rome_0_9_beta_is\">a blog post discussing the release of ROME 0.9<\/a>, in short the mapping looks like this:<\/p>\n<pre>\r\nRSS &lt;description&gt; <--> SyndEntry.description <--> Atom &lt;summary&gt;\r\nRSS &lt;content:encoded&gt; <--> SyndEntry.contents[0] <--> Atom &lt;content&gt;\r\n<\/pre>\n<p>Anyway, all this is to say that if you&#8217;re doing any work with SyndEntry, you&#8217;ll need to check both description and contents. Generally, if you&#8217;re looking for the full content, check the value of contents first. If that&#8217;s null, check the value of description.  If you&#8217;re looking for a summary, check the value of description first BUT don&#8217;t assume that you&#8217;ll actually get a short summary.  Use something like <a href=\"http:\/\/commons.apache.org\/lang\/apidocs\/org\/apache\/commons\/lang\/StringUtils.html#abbreviate(java.lang.String,%20int)\">StringUtils.abbreviate(&#8230;)<\/a> to make certain that you&#8217;ll get a short summary back and not the entire content. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been using ROME for a couple years now and I&#8217;m still learning new things. Today I was working on an issue in Clearspace where we give users the ability to show RSS \/ Atom feeds in a widget, optionally giving them the choice to show the full content of each item in the feed &hellip; <a href=\"https:\/\/cephas.net\/blog\/2007\/09\/13\/using-rome-to-get-the-body-summary-of-an-item\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using ROME to get the body \/ summary of an item<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,32,33],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/1001"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=1001"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/1001\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=1001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=1001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=1001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}