gpt4 book ai didi

validation - Grails供稿-插件, && ,验证错误

转载 作者:行者123 更新时间:2023-12-02 15:11:26 26 4
gpt4 key购买 nike

我刚刚尝试了 grails feeds-plugin http://grails.org/Feeds+Plugin

它非常容易且运行良好,但我不了解一件事。

一旦添加publishedDate,就像这样:

     reviews.each() {
review -> entry('fooTitle'){
publishedDate = review.dtCreated
review.rating + ' ' + review.comment
}
}

它生成两个标签:
      <pubDate>Tue, 04 Sep 2012 12:10:02 GMT</pubDate>
<dc:date>2012-09-04T12:10:02Z</dc:date>

数据库中的条目是:
"dtCreated": ISODate("2013-01-15T00:52:47.0Z"),

但我只希望生成 <pubDate>,因为供稿验证器会引发以下错误:
An item should not include both pubDate and dc:date 

我该如何解决?我很想使用这个插件,但是我需要一个有效的RSS。

最佳答案

如果您不介意快速而又肮脏的解决方案,则可以尝试以下方法(它来自插件的集成测试并经过修改):

import groovy.xml.XmlUtil
import groovy.xml.StreamingMarkupBuilder
import feedsplugin.FeedBuilder
import com.sun.syndication.io.SyndFeedOutput

class TestController {
private renderToString(feedType, feedVersion, Closure closure) {
def builder = new FeedBuilder()
builder.feed(closure)

def type = feedType
def version = feedVersion

SyndFeedOutput output = new SyndFeedOutput()
def sw = new StringWriter()
output.output(builder.makeFeed(type, version),sw)
sw.toString()

}

private removeDcDate(String rssFeed) {

def dom = new XmlSlurper().parseText(rssFeed)
dom.channel[0].item.eachWithIndex { item, i ->
dom.channel[0].item[i].date = {}
}

def newResp = XmlUtil.serialize(new StreamingMarkupBuilder().bind {
mkp.declareNamespace (rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#")
mkp.declareNamespace (dc:"http://purl.org/dc/elements/1.1/")
mkp.declareNamespace (content:"http://purl.org/rss/1.0/modules/content/")
mkp.declareNamespace (itunes:"http://www.itunes.com/dtds/podcast-1.0.dtd")
mkp.declareNamespace (taxo:"http://purl.org/rss/1.0/modules/taxonomy/")

mkp.yield dom
})

newResp

}

def test = {
def articles = ['A', 'B', 'C']

def outStr= renderToString("rss", "2.0") {
title = 'Test feed'
link = 'http://somewhere.com/'
description = "This is a test feed"

articles.each() { article ->
entry("Title for \$article") {
content(type:'text/html') {
return "Content for \$article"
}

link = 'http://somewhere.com/x'

publishedDate = new Date()

}
}
}
def cleanedFeed = removeDcDate(outStr)

render text: cleanedFeed, contentType: "application/rss+xml", encoding: "UTF-8"

}
}

基本上,它的工作是直接调用feedbuilder以获取提要的字符串表示形式,然后对其进行解析,并删除“dc:date”标记。结果照常渲染。

我已经在Grails 1.3.7的插件测试套件中测试了此解决方法

关于validation - Grails供稿-插件,<pubDate> && <dc:date>,验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15003747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com