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));
}
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;
}
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();
}
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);
}
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");
}
}
Aggregations