use of com.sun.syndication.feed.synd.SyndFeed in project rhsm-qe by RedHatQE.
the class CandlepinTasks method getSyndFeedFor.
protected static SyndFeed getSyndFeedFor(String candlepinUsername, String candlepinPassword, String url, String path) throws IOException, IllegalArgumentException, FeedException {
/* References:
* http://www.exampledepot.com/egs/javax.net.ssl/TrustAll.html
* http://www.avajava.com/tutorials/lessons/how-do-i-connect-to-a-url-using-basic-authentication.html
* http://wiki.java.net/bin/view/Javawsxml/Rome
*/
// Notes: Alternative curl approach to getting the atom feed:
// [ajay@garuda-rh proxy{pool_refresh}]$ curl -k -u admin:admin --request GET "https://localhost:8443/candlepin/owners/admin/atom" > /tmp/atom.xml; xmllint --format /tmp/atom.xml > /tmp/atom1.xml
// from https://bugzilla.redhat.com/show_bug.cgi?id=645597
SSLCertificateTruster.trustAllCerts();
// set the atom feed url for an owner, consumer, or null
// String url = String.format("https://%s:%s%s%s/atom", candlepinHostname, candlepinPort, candlepinPrefix, path);
url = url + path + "/atom";
// if (ownerORconsumer!=null && key!=null) {
// url = String.format("https://%s:%s%s/%s/%s/atom", candlepinHostname, candlepinPort, candlepinPrefix, ownerORconsumer, key);
// }
log.fine("SyndFeedUrl: " + url);
String authString = candlepinUsername + ":" + candlepinPassword;
log.finer("SyndFeedAuthenticationString: " + authString);
byte[] authEncBytes = Base64.encodeBytesToBytes(authString.getBytes());
String authStringEnc = new String(authEncBytes);
log.finer("SyndFeed Base64 encoded SyndFeedAuthenticationString: " + authStringEnc);
SyndFeed feed = null;
URL feedUrl = null;
URLConnection urlConnection = null;
feedUrl = new URL(url);
urlConnection = feedUrl.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
SyndFeedInput input = new SyndFeedInput();
XmlReader xmlReader = new XmlReader(urlConnection);
feed = input.build(xmlReader);
// debug logging
log.finest("SyndFeed from " + feedUrl + ":\n" + feed);
// log.fine("SyndFeed from "+feedUrl+":\n"+feed);
if (feed.getEntries().size() == 0) {
log.fine(String.format("%s entries[] is empty", feed.getTitle()));
} else
for (int i = 0; i < feed.getEntries().size(); i++) {
log.fine(String.format("%s entries[%d].title=%s description=%s", feed.getTitle(), i, ((SyndEntryImpl) feed.getEntries().get(i)).getTitle(), ((SyndEntryImpl) feed.getEntries().get(i)).getDescription() == null ? "null" : ((SyndEntryImpl) feed.getEntries().get(i)).getDescription().getValue()));
// log.fine(String.format("%s entries[%d].title=%s description=%s updatedDate=%s", feed.getTitle(), i, ((SyndEntryImpl) feed.getEntries().get(i)).getTitle(), ((SyndEntryImpl) feed.getEntries().get(i)).getDescription()==null?"null":((SyndEntryImpl) feed.getEntries().get(i)).getDescription().getValue(), ((SyndEntryImpl) feed.getEntries().get(i)).getUpdatedDate()));
// log.fine(String.format("%s entries[%d].title=%s description=%s updatedDate=%s", feed.getTitle(), i, ((SyndEntryImpl) feed.getEntries().get(i)).getTitle(), ((SyndEntryImpl) feed.getEntries().get(i)).getDescription()==null?"null":((SyndEntryImpl) feed.getEntries().get(i)).getDescription().getValue(), formatDateString( ((SyndEntryImpl) feed.getEntries().get(i)).getUpdatedDate()) ));
}
return feed;
}
use of com.sun.syndication.feed.synd.SyndFeed in project eclipse-integration-commons by spring-projects.
the class AggregateFeedJob method updateNotifications.
private void updateNotifications(IProgressMonitor monitor) {
Map<SyndEntry, SyndFeed> entryToFeed = getFeedReader().getFeedsWithEntries();
Set<SyndEntry> entries = entryToFeed.keySet();
Set<String> installedFeatures = null;
try {
installedFeatures = DiscoveryUi.createInstallJob().getInstalledFeatures(monitor);
} catch (NullPointerException e) {
// profile is not available
}
Dictionary<Object, Object> environment = new Hashtable<Object, Object>(System.getProperties());
// make sure the entries are sorted correctly
List<SyndEntry> sortedEntries = new ArrayList<SyndEntry>(entries);
Collections.sort(sortedEntries, new Comparator<SyndEntry>() {
public int compare(SyndEntry o1, SyndEntry o2) {
Date o1Date = o1.getPublishedDate() != null ? o1.getPublishedDate() : o1.getUpdatedDate();
Date o2Date = o2.getPublishedDate() != null ? o2.getPublishedDate() : o2.getUpdatedDate();
if (o1Date == null && o2Date == null) {
return 0;
} else if (o1Date == null) {
return -1;
} else if (o2Date == null) {
return 1;
} else {
return o2Date.compareTo(o1Date);
}
}
});
Version ideVersion = IdeUiUtils.getVersion();
Set<UpdateNotification> notificationsSet = new HashSet<UpdateNotification>(notifications);
for (SyndEntry entry : sortedEntries) {
UpdateNotification notification = new UpdateNotification(entry);
if (notification.matches(ideVersion, installedFeatures, environment)) {
notificationsSet.add(notification);
}
}
notifications = new ArrayList<UpdateNotification>(notificationsSet);
}
use of com.sun.syndication.feed.synd.SyndFeed in project eclipse-integration-commons by spring-projects.
the class DashboardMainPage method displayFeeds.
private void displayFeeds(final Composite composite, final ScrolledComposite scrolled, final PageBook pagebook, final Control disclaimer, Map<String, String> map, String feedName, final Section section) {
final AggregateFeedJob job = new AggregateFeedJob(map, feedName);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
unfinishedJobs.remove(job);
IWorkbenchPartSite site = getSite();
if (site != null && site.getShell() != null && !site.getShell().isDisposed() && site.getShell().getDisplay() != null && !site.getShell().getDisplay().isDisposed()) {
site.getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
Map<SyndEntry, SyndFeed> entryToFeed = job.getFeedReader().getFeedsWithEntries();
Set<SyndEntry> entries = entryToFeed.keySet();
if (!getManagedForm().getForm().isDisposed()) {
displayFeeds(entries, composite, scrolled, pagebook, disclaimer, section);
}
}
});
}
}
});
unfinishedJobs.add(job);
job.schedule();
}
use of com.sun.syndication.feed.synd.SyndFeed in project Gemma by PavlidisLab.
the class FeedReader method getLatestNews.
/**
* @return List of news items in HTML format.
*/
public List<NewsItem> getLatestNews() {
/*
* reformat the feed.
*/
Pattern authorP = Pattern.compile("<p>.*?News Item.*?<b>(edited|added)</b>.*?by.*?<a.*?</p>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
Pattern footerP = Pattern.compile("<div style=.?padding: 10px 0;.*?View Online</a>.*?</div>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
Pattern borderP = Pattern.compile("border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;");
List<NewsItem> result = new ArrayList<NewsItem>();
try {
SyndFeed feed = feedFetcher.retrieveFeed(new URL(feedUrl));
for (SyndEntry k : (Collection<SyndEntry>) feed.getEntries()) {
NewsItem n = new NewsItem();
/*
* This code is specific for confluence feeds.
*/
String title = k.getTitle();
String body = k.getDescription().getValue();
Matcher m = authorP.matcher(body);
body = m.replaceAll("");
Matcher b = borderP.matcher(body);
body = b.replaceAll("");
/*
* Confluence-specific
*/
Matcher footerMatch = footerP.matcher(body);
body = footerMatch.replaceAll("");
n.setBody(body);
n.setTitle(title);
n.setDate(k.getPublishedDate());
result.add(n);
}
} catch (Exception e) {
NewsItem n = new NewsItem();
n.setTitle("No news");
n.setBody("");
}
return result;
}
use of com.sun.syndication.feed.synd.SyndFeed in project UniversalMediaServer by UniversalMediaServer.
the class Feed method parse.
@SuppressWarnings("unchecked")
public void parse() throws Exception {
SyndFeedInput input = new SyndFeedInput();
byte[] b = downloadAndSendBinary(url);
if (b != null) {
SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(b)));
name = feed.getTitle();
if (feed.getCategories() != null && feed.getCategories().size() > 0) {
SyndCategory category = (SyndCategory) feed.getCategories().get(0);
tempCategory = category.getName();
}
List<SyndEntry> entries = feed.getEntries();
for (SyndEntry entry : entries) {
tempItemTitle = entry.getTitle();
tempItemLink = entry.getLink();
tempFeedLink = entry.getUri();
tempItemThumbURL = null;
ArrayList<Element> elements = (ArrayList<Element>) entry.getForeignMarkup();
for (Element elt : elements) {
if ("group".equals(elt.getName()) && "media".equals(elt.getNamespacePrefix())) {
List<Content> subElts = elt.getContent();
for (Content subelt : subElts) {
if (subelt instanceof Element) {
parseElement((Element) subelt, false);
}
}
}
parseElement(elt, true);
}
List<SyndEnclosure> enclosures = entry.getEnclosures();
for (SyndEnclosure enc : enclosures) {
if (StringUtils.isNotBlank(enc.getUrl())) {
tempItemLink = enc.getUrl();
}
}
manageItem();
}
}
setLastModified(System.currentTimeMillis());
}
Aggregations