We Recommend

Microsoft Windows Registry Guide Microsoft Windows Registry Guide
Get the in-depth information you need to modifyand seamlessly managethe Windows registry. Written for IT professionals and power users, this vital resource reveals little-known registry techniques, tricks, tips, and secrets to make your job easier.


Posted By

scottdavis99 on 01/03/07


Tagged

atom groovy grails


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

gwmccort
dima767
mykelalvis
bootz15


Atom feed from Grails


Published in: Groovy 


URL: http://aboutgroovy.com/item/atom

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


  1. def atom = {
  2. params.max = 10
  3. params.sort = 'datePosted'
  4. params.order = 'desc'
  5. def tmpList = Item.list( params )
  6.  
  7. def feedHeader = """<feed xmlns="http://www.w3.org/2005/Atom">
  8. <title type="text">aboutGroovy.com</title>
  9. <link rel="alternate" type="text/html" href="http://aboutGroovy.com"/>
  10. <link rel="self" type="application/atom+xml" href="http://aboutGroovy.com/item/atom"/>
  11. <updated>2006-12-17T18:30:02Z</updated>
  12. <author><name>Scott Davis</name></author>
  13. <id>tag:aboutgroovy.com,2006-12-18:thisIsUnique</id>
  14. <generator uri="http://aboutGroovy.com" version="0.0.1">Hand-rolled Grails code</generator>
  15. """
  16.  
  17. def feedFooter = "</feed>"
  18.  
  19. StringBuffer feed = new StringBuffer()
  20. def df = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'-07:00'")
  21. tmpList.each{item ->
  22. Writer sw = new StringWriter()
  23. def x = new groovy.xml.MarkupBuilder(sw)
  24. x.entry(xmlns:"http://www.w3.org/2005/Atom"){
  25. author{name("Scott Davis")}
  26. published(df.format(item.datePosted))
  27. updated(df.format(item.datePosted))
  28. link(href:"http://aboutGroovy.com/item/show/${item.id}",
  29. rel:"alternate", title:item.title, type:"text/html")
  30. id("tag:aboutgroovy.com,2006:/item/show/${item.id}")
  31. title(type:"text", item.title)
  32. content(type:"xhtml"){
  33. div(xmlns:"http://www.w3.org/1999/xhtml"){
  34. p("Category: ${item.type}")
  35. p{a(href:item.url, "Original Source")}
  36. p(item.shortDescription)
  37. p(item.description)
  38. }
  39. }
  40. }
  41. feed.append(sw.toString() + "\n")
  42. }
  43.  
  44. response.setContentType("application/atom+xml")
  45. render "${feedHeader}${feed}${feedFooter}"
  46. }

Report this snippet 

You need to login to post a comment.