Package es.java.otro.util

Source Code of es.java.otro.util.RssUtil

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;
  }
}
TOP

Related Classes of es.java.otro.util.RssUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.