Reputation: 1068
I am creating an rss feed in Java using ROME, but for the life of me, i can find how a GUID on it.
public boolean addRss(String msg,String msgLink,Date date){
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry;
entry = new SyndEntryImpl();
entry.setTitle(msg);
if(msgLink!=null){
entry.setLink(msgLink);
}
entry.setPublishedDate(date);
entries.add(entry);
feed.setEntries(entries);
return true;
}
This code works for creating a rss item. the problem is that i need to add a timestamp as a GUID. So i tried to use a Guid object as so
Guid g=new Guid();
g.setValue(date.toString());
g.setPermaLink(false);
But I cant find a way to add this to my item, for example there is no entry.setGuid(Guid)
Edit
It turns out that Guid()
can be added to an Item()
not a SyndFeedImpl()
as i have in my case, and i cant find a way to add an Item to my SyndFeedImpl. I would rather have some way of adding a guid to a SyndFeedImpl() than re writing the whole thing
Upvotes: 5
Views: 1262
Reputation: 2234
The SyndFeed.setURI sets the unique identifier. Depending on the type of feed you are creating (atom/rss) the resulting xml will be different, but anyway the identifier will be there:
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("entry title 1");
entry.setUri("http://localhost/feed/item1GUID");
entry.setLink("http://localhost/feed/item1");
result as rss 2.0:
<item>
<title>entry title 1</title>
<link>http://localhost/feed/item1</link>
<guid isPermaLink="false">http://localhost/feed/item1GUID</guid>
</item>
same entry as atom 1.0:
<entry>
<title>entry title 1</title>
<link rel="alternate" href="http://localhost/feed/item1" />
<author>
<name />
</author>
<id>http://localhost/feed/item1GUID</id>
</entry>
Upvotes: 6