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