3

I've been toying around with Rome 1.0 today with scala and while i've been able to get the title, description, etc tabs it says that getContent() doesn't exist.

   val url = "http://www.codecommit.com/blog/ruby/monads-are-not-metaphors/feed"
   val feed: SyndFeed = new SyndFeedInput().build(new XmlReader(new URL(url)))

   var rss_title = feed.getTitle()
   var rss_ex = feed.getTitleEx.getValue()
   var rss_desc = feed.getDescription()
   var rss_content = feed.getContent()  

<---- this one doesn't seem to exist though looking at the API it should work.

iAmDecim
  • 403
  • 4
  • 11

1 Answers1

2

A feed represents multiple entries and the entries themselves have a getContents() method. Here's a complete working example (assumes you have rome 1.0 on the classpath):

import com.sun.syndication.feed.synd.{SyndContent, SyndEntry, SyndFeed}
import com.sun.syndication.io.{SyndFeedInput, XmlReader}
import java.net.URL
import java.util.{List => JList}
import scala.collection.JavaConverters._

object RomeApp extends App {
  val url = "http://www.codecommit.com/blog/ruby/monads-are-not-metaphors/feed"
  val feed: SyndFeed = new SyndFeedInput().build(new XmlReader(new URL(url)))
  val rss_title = feed.getTitle
  val rss_ex = feed.getTitleEx.getValue
  val rss_desc = feed.getDescription
  val rss_entries = feed.getEntries.asInstanceOf[JList[SyndEntry]].asScala
  for (entry <- rss_entries;
       content <- entry.getContents.asInstanceOf[JList[SyndContent]].asScala) {
    println("------------------------------")
    println(content.getValue)
  }   
}

Notice that the lack of generics in the Java API makes it a bit cumbersome to use, the library could use some pimping.

Bart Schuller
  • 2,725
  • 19
  • 18
  • Nice!!! Thanks, this is my first big project actually using libraries so figuring this stuff out is still a needle in a hay stack! – iAmDecim Oct 15 '11 at 17:58