Created
April 1, 2012 23:44
-
-
Save akr4/2279505 to your computer and use it in GitHub Desktop.
Scala + Rome で RSS 出力
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fourseasonszoo.niboshi | |
import com.sun.syndication.io._ | |
import com.sun.syndication.feed.synd._ | |
import scala.collection.JavaConverters._ | |
import org.scala_tools.time.Imports._ | |
import scalax.io._ | |
import java.io.StringWriter | |
object Main extends App { | |
import Factories._ | |
val feed = createFeed("rss_2.0", "sample feed", "http://fourseasonszoo.com", "Hello Rock'n Roll City", | |
List( | |
createEntry("Tokyo", "http://fourseasonszoo.com/tokyo", "Hello, Tokyo city!"), | |
createEntry("Yokohama", "http://fourseasonszoo.com/yokohama", "Hello, Yokohama city!") | |
) | |
) | |
val output = new SyndFeedOutput | |
val writer = new StringWriter | |
output.output(feed, writer) | |
println(writer.toString) | |
} | |
object Factories { | |
def createFeed(feedType: String, title: String, link: String, description: String, entries: List[SyndEntry]) = { | |
val f = new SyndFeedImpl | |
f.setFeedType(feedType) | |
f.setTitle(title) | |
f.setLink(link) | |
f.setDescription(description) | |
f.setEntries(entries.asJava) | |
f | |
} | |
def createEntry(title: String, link: String, description: String) = { | |
val e = new SyndEntryImpl | |
e.setTitle(title) | |
e.setLink(link) | |
e.setPublishedDate(DateTime.now.toDate) | |
e.setDescription(createDescription(description)) | |
e | |
} | |
def createDescription(value: String) = { | |
val d = new SyndContentImpl | |
d.setType("text/plain") | |
d.setValue(value) | |
d | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment