2016-08-08 34 views
2

Ich versuche, die RSS-Feeds mit Java ROM API zu erstellen. Meine Forderung ist, dass jeder Eintrag ein Bild enthalten soll, wie unten angegeben:Wie erstellt man Einträge mit Bildelement im RSS Feed mit der Java ROM API?

<?xml version="1.0" encoding="UTF-8"?> 
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> 
    <channel> 
    <title>Sample RSS Build Results</title> 
    <link>http://time.is</link> 
    <description>sample RSS build</description> 
     <item> 
      <title>Ist Feed</title> 
      <link>http://mysampleurl1.com</link> 
      <description>The build was successful!</description> 
      <pubDate>Mon, 08 Aug 2016 10:28:32 GMT</pubDate> 
      <image>http://myimageurl1.com</image> 
      <dc:date>2016-08-08T10:28:32Z</dc:date> 
     </item> 
     <item> 
      <title>IInd Feed</title> 
      <link>http://mysampleurl2.com</link> 
      <description>The build was successful!</description> 
      <pubDate>Mon, 08 Aug 2016 10:28:44 GMT</pubDate> 
      <dc:date>2016-08-08T10:28:44Z</dc:date> 
     </item> 
</channel> 

Ich bin ROM api Java. Es bietet das Paket :: com.rometools.rome.feed.synd.SyndImageImpl, um Bildelemente im vollständigen Feed, aber nicht in einzelnen Einträgen zu setzen/abzurufen. Für einen Eintrag im RSS-Feed hat es Paket: com.rometools.rome.feed.synd.SyndEntryImpl, aber es bietet keine Funktion zum Einstellen oder Abrufen von Bildern.

Bitte helfen Sie mir, dieses Problem zu lösen. Vielen Dank im Voraus.

Antwort

1

The RSS spec gibt keine Bildelemente für Einträge an, aber Sie können sie um Image namespace erweitern.

Short Lösung könnte so aussehen:

SyndEntry entry = new SyndEntryImpl(); 
.. 
Element image = new Element("image", Namespace.getNamespace("image", "http://web.resource.org/rss/1.0/modules/image/")); 
image.addContent("http://localhost/feed/item1_image"); 
entry.getForeignMarkup().add(image); 

Dies gilt xml führen:

<?xml version="1.0" encoding="UTF-8"?> 
<rss version="2.0"> 
    <channel> 
    <title>title</title> 
    <link>http://localhost/feed</link> 
    <description>description</description> 
    <item> 
     <title>entry title 1</title> 
     <link>http://localhost/feed/item1</link> 
     <image:image xmlns:image="http://web.resource.org/rss/1.0/modules/image/">http://localhost/feed/item1_image</image:image> 
     <guid isPermaLink="false">http://localhost/feed/item1</guid> 
    </item> 
    </channel> 
</rss> 

robuste Weise zu create a custom module ist wie sie here und here getan haben.