Search in sources :

Example 1 with XmlReader

use of com.sun.syndication.io.XmlReader in project cubrid-manager by CUBRID.

the class NoticeDashboardEntity method readFeedFromLocalCache.

@SuppressWarnings("unused")
private void readFeedFromLocalCache() throws IllegalArgumentException, FeedException, IOException {
    // TODO
    String file = "";
    SyndFeedInput input = new SyndFeedInput();
    File feedUrl = new File(file);
    rssData = input.build(new XmlReader(feedUrl));
}
Also used : SyndFeedInput(com.sun.syndication.io.SyndFeedInput) XmlReader(com.sun.syndication.io.XmlReader) File(java.io.File)

Example 2 with XmlReader

use of com.sun.syndication.io.XmlReader 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)

Example 3 with XmlReader

use of com.sun.syndication.io.XmlReader in project jersey by jersey.

the class FeedDownloader method apply.

@Override
@SuppressWarnings("unchecked")
public List<SyndEntry> apply(URL url) {
    try (XmlReader xmlReader = new XmlReader(url)) {
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(xmlReader);
        return feed.getEntries();
    } catch (Exception e) {
        LOG.warn("An error during downloading and parsing a given feed: " + url, e);
    }
    return Collections.emptyList();
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) XmlReader(com.sun.syndication.io.XmlReader)

Example 4 with XmlReader

use of com.sun.syndication.io.XmlReader in project cubrid-manager by CUBRID.

the class NoticeDashboardEntity method readFeedFromRemote.

/**
	 * get syndFeed from rss
	 *
	 * @param source
	 * @return
	 * @throws IllegalArgumentException
	 * @throws FeedException
	 * @throws IOException
	 */
private void readFeedFromRemote() throws IllegalArgumentException, FeedException, IOException {
    SyndFeedInput input = new SyndFeedInput();
    // Locale.setDefault(Locale.ENGLISH);
    URLConnection feedUrl = new URL(rssurl).openConnection();
    // java.io.IOException: Server returned HTTP response code: 403
    feedUrl.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
    feedUrl.setConnectTimeout(5000);
    XmlReader xmlReader = new XmlReader(feedUrl);
    rssData = input.build(xmlReader);
}
Also used : SyndFeedInput(com.sun.syndication.io.SyndFeedInput) XmlReader(com.sun.syndication.io.XmlReader) URLConnection(java.net.URLConnection) URL(java.net.URL)

Example 5 with XmlReader

use of com.sun.syndication.io.XmlReader 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)

Aggregations

SyndFeedInput (com.sun.syndication.io.SyndFeedInput)6 XmlReader (com.sun.syndication.io.XmlReader)6 URL (java.net.URL)3 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)2 InputStream (java.io.InputStream)2 URLConnection (java.net.URLConnection)2 GitBlitException (com.gitblit.GitBlitException)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 FeedException (com.sun.syndication.io.FeedException)1 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 IRISyntaxException (org.apache.abdera.i18n.iri.IRISyntaxException)1 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)1