Search in sources :

Example 16 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project jaggery by wso2.

the class FeedHostObject method jsFunction_getFeed.

public static synchronized void jsFunction_getFeed(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    if (arguments.length != 1) {
        throw new ScriptException("Invalid parameter");
    }
    if (arguments[0] instanceof String) {
        feed = null;
        URL url = null;
        try {
            url = new URL((String) arguments[0]);
            feed = (Feed) Abdera.getNewParser().parse(url.openStream()).getRoot();
            isRssFeed = false;
        } catch (ClassCastException e) {
            XmlReader reader = null;
            try {
                reader = new XmlReader(url);
                rssFeed = new SyndFeedInput().build(reader);
                isRssFeed = true;
                for (Iterator i = rssFeed.getEntries().iterator(); i.hasNext(); ) {
                    SyndEntry entry = (SyndEntry) i.next();
                }
            } catch (IOException e1) {
                throw new ScriptException(e1);
            } catch (Exception e1) {
                throw new ScriptException(e1);
            } finally {
                if (reader != null)
                    try {
                        reader.close();
                    } catch (IOException e1) {
                        throw new ScriptException(e1);
                    }
            }
        } catch (IRISyntaxException e) {
            throw new ScriptException(e);
        } catch (MalformedURLException e) {
            throw new ScriptException(e);
        } catch (IOException e) {
            throw new ScriptException(e);
        }
    } else {
        throw new ScriptException("Invalid parameter, It is must to be a String");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) MalformedURLException(java.net.MalformedURLException) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Iterator(java.util.Iterator) IRISyntaxException(org.apache.abdera.i18n.iri.IRISyntaxException) XmlReader(com.sun.syndication.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IRISyntaxException(org.apache.abdera.i18n.iri.IRISyntaxException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Example 17 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project jbpm-work-items by kiegroup.

the class RSSWorkItemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    try {
        List<String> urls = new ArrayList<String>();
        String urlsList = (String) workItem.getParameter("URL");
        for (String s : urlsList.split(";")) {
            if (s != null && !"".equals(s)) {
                urls.add(s);
            }
        }
        for (String url : urls) {
            URL feedSource = new URL(url);
            if (input == null) {
                input = new SyndFeedInput();
            }
            SyndFeed feed = input.build(new XmlReader(feedSource));
            feeds.add(feed);
        }
        manager.completeWorkItem(workItem.getId(), null);
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) ArrayList(java.util.ArrayList) XmlReader(com.sun.syndication.io.XmlReader) URL(java.net.URL)

Example 18 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project gitblit by gitblit.

the class SyndicationUtils method readFeed.

/**
 * Reads a Gitblit RSS feed.
 *
 * @param url
 *            the url of the Gitblit server
 * @param parameters
 *            the list of RSS parameters
 * @param repository
 *            the repository name
 * @param username
 * @param password
 * @return a list of SyndicationModel entries
 * @throws {@link IOException}
 */
private static List<FeedEntryModel> readFeed(String url, List<String> parameters, String repository, String branch, String username, char[] password) throws IOException {
    // build url
    StringBuilder sb = new StringBuilder();
    sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));
    if (parameters.size() > 0) {
        boolean first = true;
        for (String parameter : parameters) {
            if (first) {
                sb.append('?');
                first = false;
            } else {
                sb.append('&');
            }
            sb.append(parameter);
        }
    }
    String feedUrl = sb.toString();
    URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);
    InputStream is = conn.getInputStream();
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = null;
    try {
        feed = input.build(new XmlReader(is));
    } catch (FeedException f) {
        throw new GitBlitException(f);
    }
    is.close();
    List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
    for (Object o : feed.getEntries()) {
        SyndEntryImpl entry = (SyndEntryImpl) o;
        FeedEntryModel model = new FeedEntryModel();
        model.repository = repository;
        model.branch = branch;
        model.title = entry.getTitle();
        model.author = entry.getAuthor();
        model.published = entry.getPublishedDate();
        model.link = entry.getLink();
        model.content = entry.getDescription().getValue();
        model.contentType = entry.getDescription().getType();
        if (entry.getCategories() != null && entry.getCategories().size() > 0) {
            List<String> tags = new ArrayList<String>();
            for (Object p : entry.getCategories()) {
                SyndCategory cat = (SyndCategory) p;
                tags.add(cat.getName());
            }
            model.tags = tags;
        }
        entries.add(model);
    }
    return entries;
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) FeedEntryModel(com.gitblit.models.FeedEntryModel) InputStream(java.io.InputStream) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) XmlReader(com.sun.syndication.io.XmlReader) URLConnection(java.net.URLConnection) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Aggregations

SyndFeedInput (com.sun.syndication.io.SyndFeedInput)18 XmlReader (com.sun.syndication.io.XmlReader)13 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)9 URL (java.net.URL)7 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)6 ArrayList (java.util.ArrayList)5 InputStream (java.io.InputStream)4 URLConnection (java.net.URLConnection)4 FeedException (com.sun.syndication.io.FeedException)3 IOException (java.io.IOException)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 InputSource (org.xml.sax.InputSource)2 GitBlitException (com.gitblit.GitBlitException)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 SyndEnclosure (com.sun.syndication.feed.synd.SyndEnclosure)1