放置内容:使用ROME在RSS feed中编码 [英] Putting content:encoded in RSS feed using ROME

查看:142
本文介绍了放置内容:使用ROME在RSS feed中编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ROME及其< content:encoded> 标记内。 com / wiki / display / MODULES / Homerel =nofollow>模块。到目前为止,我已成功将mediaRSS和geoRSS放入Feed中,但我的内容未显示。

I'm trying to put some HTML content inside <content:encoded> tags using ROME and its modules. So far I've succesfully put mediaRSS and geoRSS in the feed, but my content is not showing up.

这是我的代码:

ContentModule contentModule = new ContentModuleImpl();
List<ContentItem> contents = new ArrayList<ContentItem>();
List<String> contentValueDOM = new ArrayList<String>();
ContentItem content = new ContentItem();

content.setContentValue("<p>Some text here</p>");
content.setContentEncoding("text/html");
content.setContentAbout("Paragraph");
content.setContentValueDOM(contentValueDOM);
contents.add(content);

contentModule.setContents(contents);
contentModule.setContentItems(contents);
entry.getModules().add(contentModule);

这是我的输出

<item>
  <title>Example page</title>

  <link>http://www.example.com/news/2012/march/example-page.html</link>
  <description>Introduction</description>
  <category>news</category>
  <pubDate>Tue, 27 Mar 2012 08:18:52 GMT</pubDate>
  <guid>http://www.example.com/news/2012/march/example-page.html</guid>
  <dc:date>2012-03-27T08:18:52Z</dc:date>

  <content:items>
    <rdf:Bag>
      <rdf:li>
        <content:item rdf:about="Paragraph">
          <content:encoding rdf:resource="text/html" />
          <rdf:value />
        </content:item>
      </rdf:li>
    </rdf:Bag>

  </content:items>
  <geo:lat>52.09161879618039</geo:lat>
  <geo:long>5.1141280958007655</geo:long>
  <media:content medium="image" fileSize="16029" height="500" type="image/jpeg" width="399" url="http://www.example.com/binaries/content/gallery/image.jpg">
    <media:description type="plain/text" />
    <media:thumbnail url="http://www.example.com/binaries/content/gallery/thumbnail/image.jpg" />
  </media:content>
  <media:content medium="video" expression="full" type="application/x-shockwave-flash" isDefault="true" url="http://www.youtube.com/v/jQq4ju-vupY?rel=0">

    <media:player url="http://www.youtube.com/v/jQq4ju-vupY?rel=0&amp;feature=youtube_gdata_player" width="520" height="390" />
  </media:content>
</item>


推荐答案

这似乎有效:

List<String> contents = new ArrayList<String>();
contents.add("<p>Some text here</p>");
ContentModule module = new ContentModuleImpl();
module.setEncodeds(contents);        
entry.getModules().add(module); 

然而,上面使用 更新语法 而不是 原始语法 。使用更新语法,您会看到类似的内容(包含< content:encoded> 标记):

However the above outputs the feed using the Updated Syntax rather than the Original Syntax. With the Updated Syntax you get something that looks like (this contains the <content:encoded> tag):

<item>
  <content:encoded><![CDATA[<p>Some text here</p>]]></content:encoded>
</item>

当我尝试使用支持原始语法的 ContentItem 时(使用modules-0.3.2)就像你一样,我发现 ContentModuleGenerator 要求 setContentValueDOM 包含要输出的内容的值。此内容似乎也必须可投射 org.jdom.Content (例如,您需要调用 setContentValueDOM(List< org.jdom.Content>) )。由于 org.jdom.CDATA org.jdom.Content 的子类,您可以执行以下操作:

When I tried to use the ContentItem which does support Original Syntax (using modules-0.3.2) like you did I found that the ContentModuleGenerator required that setContentValueDOM contains the value of the content to output. It also appears that this content needs to be castable to org.jdom.Content (e.g. you need to call setContentValueDOM(List<org.jdom.Content>)). As org.jdom.CDATA is a subclass of org.jdom.Content you can do something like this:

ContentModule contentModule = new ContentModuleImpl();                
List<ContentItem> contents = new ArrayList<ContentItem>();
List<Content> contentValueDOM = new ArrayList<Content>();        
String value = "<p>Some text here</p>";
ContentItem content = new ContentItem();
content.setContentValue(value);
content.setContentAbout("Paragraph"); 
content.setContentFormat("http://www.w3.org/TR/html4/");
CDATA valueElement = new CDATA(value);
contentValueDOM.add(valueElement);
content.setContentValueDOM(contentValueDOM);      
contents.add(content);
contentModule.setContents(contents);
contentModule.setContentItems(contents);
entry.getModules().add(contentModule);

产生:

<item>
  <title>Example page</title>
  <content:items>
    <rdf:Bag>
      <rdf:li>
        <content:item rdf:about="Paragraph">
          <content:format rdf:resource="http://www.w3.org/TR/html4/" />
          <rdf:value><![CDATA[<p>Some text here</p>]]></rdf:value>
        </content:item>
      </rdf:li>
    </rdf:Bag>
  </content:items>
</item>

如果更改上面的代码示例,用Element替换CDATA部分并添加适当的格式和编码信息因此:

If you alter the above code sample replacing the CDATA section with an Element and adding appropriate format and encoding information thus:

//content.setContentFormat("http://www.w3.org/TR/html4/");
//CDATA valueElement = new CDATA(value);
content.setContentFormat("http://www.w3.org/1999/xhtml");
content.setContentEncoding("http://www.w3.org/TR/REC-xml#dt-wellformed");
Element valueElement = new Element("p");
valueElement.setText("Some text here");

您最终会看到显示< content:encoding> 的XML tag:

you will end up with XML showing the <content:encoding> tag:

<item>
  <title>Example page</title>
  <content:items>
    <rdf:Bag>
      <rdf:li>
        <content:item rdf:about="Paragraph">
          <content:format rdf:resource="http://www.w3.org/1999/xhtml" />
          <content:encoding rdf:resource="http://www.w3.org/TR/REC-xml#dt-wellformed" />
          <rdf:value>
            <p>Some text here</p>
          </rdf:value>
        </content:item>
      </rdf:li>
    </rdf:Bag>
  </content:items>
</item>

这篇关于放置内容:使用ROME在RSS feed中编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆