package es.java.otro.util;
import java.net.URL;
import java.util.Iterator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.PlatformUI;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import es.java.otro.common.OtroException;
import es.java.otro.model.Entry;
import es.java.otro.model.Feed;
public class RssUtil {
public static Feed createFeed(String feedUrl) throws OtroException {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
try {
feed = input.build(new XmlReader(new URL(feedUrl)));
} catch (Exception e) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Load Error", "Unable to load "
+feedUrl+" ("+e.getMessage()+")");
}
Feed f = null;
if (feed != null) {
feed.getEntries();
f = new Feed();
f.setName(feed.getTitle());
f.setUrl(feed.getLink());
for (Iterator it = feed.getEntries().iterator(); it.hasNext();) {
SyndEntry entry = (SyndEntry) it.next();
Entry modelEntry = new Entry();
modelEntry.setTitle(entry.getTitle());
modelEntry.setUrl(entry.getLink());
modelEntry.setPublishDate(entry.getPublishedDate());
modelEntry.setAuthor(entry.getAuthor());
modelEntry.setHtml(entry.getDescription().getValue());
f.addEntry(modelEntry);
}
}
return f;
}
}