Conversion of source elements between wirefeed and syndfeed in RSS
converters (fixes #161)
This commit is contained in:
parent
6cc4636ffc
commit
812ec23952
2 changed files with 60 additions and 0 deletions
|
@ -24,10 +24,12 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
|
|||
import com.sun.syndication.feed.rss.Channel;
|
||||
import com.sun.syndication.feed.rss.Image;
|
||||
import com.sun.syndication.feed.rss.Item;
|
||||
import com.sun.syndication.feed.rss.Source;
|
||||
import com.sun.syndication.feed.synd.Converter;
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.feed.synd.SyndEntryImpl;
|
||||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
import com.sun.syndication.feed.synd.SyndFeedImpl;
|
||||
import com.sun.syndication.feed.synd.SyndImage;
|
||||
import com.sun.syndication.feed.synd.SyndImageImpl;
|
||||
|
||||
|
@ -104,9 +106,21 @@ public class ConverterForRSS090 implements Converter {
|
|||
syndEntry.setLink(item.getLink());
|
||||
syndEntry.setTitle(item.getTitle());
|
||||
syndEntry.setLink(item.getLink());
|
||||
syndEntry.setSource(createSource(item.getSource()));
|
||||
return syndEntry;
|
||||
}
|
||||
|
||||
protected SyndFeed createSource(final Source source) {
|
||||
SyndFeed feed = null;
|
||||
if (source != null) {
|
||||
feed = new SyndFeedImpl();
|
||||
feed.setLink(source.getUrl());
|
||||
feed.setUri(source.getUrl());
|
||||
feed.setTitle(source.getValue());
|
||||
}
|
||||
return feed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WireFeed createRealFeed(final SyndFeed syndFeed) {
|
||||
return this.createRealFeed(getType(), syndFeed);
|
||||
|
@ -166,6 +180,7 @@ public class ConverterForRSS090 implements Converter {
|
|||
item.setForeignMarkup(sEntry.getForeignMarkup());
|
||||
}
|
||||
|
||||
item.setSource(createSource(sEntry.getSource()));
|
||||
final String uri = sEntry.getUri();
|
||||
if (uri != null) {
|
||||
item.setUri(uri);
|
||||
|
@ -174,4 +189,14 @@ public class ConverterForRSS090 implements Converter {
|
|||
return item;
|
||||
}
|
||||
|
||||
protected Source createSource(final SyndFeed feed) {
|
||||
Source source = null;
|
||||
if (feed != null) {
|
||||
source = new Source();
|
||||
source.setUrl(feed.getUri());
|
||||
source.setValue(feed.getTitle());
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.sun.syndication.unittest.issues;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.unittest.TestSyndFeedRSS20;
|
||||
|
||||
/**
|
||||
* Test for #161: No source element in RSS 2.0 items.
|
||||
* @author Martin Kurz
|
||||
*
|
||||
*/
|
||||
public class Isseue161Test extends TestSyndFeedRSS20 {
|
||||
|
||||
public Isseue161Test() {
|
||||
super("rss_2.0");
|
||||
}
|
||||
|
||||
public void testItems() throws Exception {
|
||||
final int count = this.getCachedSyndFeed().getEntries().size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
testItem(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testItem(final int i) throws Exception {
|
||||
super.testItem(i);
|
||||
final List<SyndEntry> items = this.getCachedSyndFeed().getEntries();
|
||||
final SyndEntry entry = items.get(i);
|
||||
assertProperty(entry.getSource().getLink(), "channel.item[" + i + "].source^url");
|
||||
assertProperty(entry.getSource().getTitle(), "channel.item[" + i + "].source");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue