精通 Grails: 文件上传和 Atom 联合
2009-10-26 00:00:00 来源:WEB开发网清单 18. 添加 atomDate 标记
import java.text.SimpleDateFormat
class DateTagLib {
public static final String INCOMING_DATE_FORMAT = "yyyy-MM-dd hh:mm:ss"
public static final String ATOM_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'-07:00'"
def atomDate = {attrs, body ->
def b = attrs.body ?: body()
def d = new SimpleDateFormat(INCOMING_DATE_FORMAT).parse(b)
out << new SimpleDateFormat(ATOM_DATE_FORMAT).format(d)
}
//SNIP
}
为了完成 Atom feed,创建 grails-app/views/entry/_atomEntry.gsp,并添加清单 19 中的代码:
清单 19. _atomEntry.gsp 局部模板
<entry xmlns='http://www.w3.org/2005/Atom'>
<author>
<name>${entryInstance.author.name}</name>
</author>
<published><g:atomDate>${entryInstance.dateCreated}</g:atomDate></published>
<updated><g:atomDate>${entryInstance.lastUpdated}</g:atomDate></updated>
<link href="http://blogito.org/blog/${entryInstance.author.login}/
${entryInstance.title.encodeAsUnderscore()}" rel="alternate"
title="${entryInstance.title}" type="text/html" />
<id>tag:blogito.org,2009:/blog/${entryInstance.author.login}/
${entryInstance.title.encodeAsUnderscore()}</id>
<title type="text">${entryInstance.title}</title>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
${entryInstance.summary}
</div>
</content>
</entry>
更多精彩
赞助商链接