Revision: 2135
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 3, 2007 09:59 by scottdavis99
Initial Code
def atom = {
params.max = 10
params.sort = 'datePosted'
params.order = 'desc'
def tmpList = Item.list( params )
def feedHeader = """<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">aboutGroovy.com</title>
<link rel="alternate" type="text/html" href="http://aboutGroovy.com"/>
<link rel="self" type="application/atom+xml" href="http://aboutGroovy.com/item/atom"/>
<updated>2006-12-17T18:30:02Z</updated>
<author><name>Scott Davis</name></author>
<id>tag:aboutgroovy.com,2006-12-18:thisIsUnique</id>
<generator uri="http://aboutGroovy.com" version="0.0.1">Hand-rolled Grails code</generator>
"""
def feedFooter = "</feed>"
StringBuffer feed = new StringBuffer()
def df = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'-07:00'")
tmpList.each{item ->
Writer sw = new StringWriter()
def x = new groovy.xml.MarkupBuilder(sw)
x.entry(xmlns:"http://www.w3.org/2005/Atom"){
author{name("Scott Davis")}
published(df.format(item.datePosted))
updated(df.format(item.datePosted))
link(href:"http://aboutGroovy.com/item/show/${item.id}",
rel:"alternate", title:item.title, type:"text/html")
id("tag:aboutgroovy.com,2006:/item/show/${item.id}")
title(type:"text", item.title)
content(type:"xhtml"){
div(xmlns:"http://www.w3.org/1999/xhtml"){
p("Category: ${item.type}")
p{a(href:item.url, "Original Source")}
p(item.shortDescription)
p(item.description)
}
}
}
feed.append(sw.toString() + "\n")
}
response.setContentType("application/atom+xml")
render "${feedHeader}${feed}${feedFooter}"
}
Initial URL
http://aboutgroovy.com/item/atom
Initial Description
Here's a quick block of code that adds a valid Atom feed to you Grails application. Validate here: http://feedvalidator.org/check?url=http://aboutgroovy.com/item/atom
Initial Title
Atom feed from Grails
Initial Tags
groovy
Initial Language
Groovy