use of com.sun.syndication.feed.synd.SyndFeed in project eclipse-integration-commons by spring-projects.
the class DashboardMainPage method createFeedsSection.
private void createFeedsSection(Composite parent, final String title, FeedType feedType, String feedName) {
final Section section = new Section(parent, ExpandableComposite.TITLE_BAR) {
@Override
public void redraw() {
GridData compositeData = (GridData) feedsScrolled.getLayoutData();
compositeData.widthHint = getSize().x - 35;
compositeData.heightHint = getSize().y - 40;
compositeData.grabExcessHorizontalSpace = false;
compositeData.grabExcessVerticalSpace = false;
super.redraw();
}
};
form.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
GridData data = (GridData) section.getLayoutData();
data.heightHint = form.getSize().y - FEEDS_TEXT_WRAP_INDENT;
}
});
toolkit.adapt(section);
section.setTitleBarForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
section.setTitleBarBackground(toolkit.getColors().getColor(IFormColors.TB_BG));
section.setTitleBarBorderColor(toolkit.getColors().getColor(IFormColors.TB_BORDER));
section.setFont(FormFonts.getInstance().getBoldFont(getSite().getShell().getDisplay(), section.getFont()));
section.setText(title);
section.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).hint(300, 300).applyTo(section);
final Composite headerComposite = toolkit.createComposite(section, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.marginTop = 0;
rowLayout.marginBottom = 0;
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.createControl(headerComposite);
final PageBook pagebook = new PageBook(section, SWT.NONE);
toolkit.adapt(pagebook);
pagebook.setLayoutData(new GridLayout());
final Composite disclaimer = createDisclaimer(pagebook);
feedsScrolled = new ScrolledComposite(pagebook, SWT.V_SCROLL);
feedsScrolled.setExpandVertical(false);
feedsScrolled.setLayout(new GridLayout());
feedsScrolled.setAlwaysShowScrollBars(false);
GridDataFactory.fillDefaults().grab(true, false).applyTo(feedsScrolled);
toolkit.adapt(feedsScrolled);
feedsComposite = toolkit.createComposite(feedsScrolled);
feedsComposite.setLayout(new TableWrapLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(feedsComposite);
feedsScrolled.setContent(feedsComposite);
feedsComposite.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GridData data = (GridData) feedsComposite.getLayoutData();
data.widthHint = section.getSize().x - FEEDS_TEXT_WRAP_INDENT;
data.heightHint = form.getSize().y - 50;
}
});
section.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
GridData data = (GridData) feedsScrolled.getLayoutData();
data.heightHint = form.getSize().y - 50;
data.grabExcessVerticalSpace = false;
feedsScrolled.setSize(section.getSize().x - 40, form.getSize().y - 50);
for (Control feedControl : feedControls) {
if (!feedControl.isDisposed()) {
((TableWrapData) feedControl.getLayoutData()).maxWidth = section.getSize().x - FEEDS_TEXT_WRAP_INDENT;
// Point size = feedControl.computeSize(data.widthHint,
// 400);
// feedControl.setSize(size);
// feedControl.pack(true);
}
}
feedsComposite.pack();
}
});
feedControls = new HashSet<Control>();
final Map<String, String> springMap = new HashMap<String, String>();
String[] urls = ResourceProvider.getUrls(RESOURCE_DASHBOARD_FEEDS_BLOGS);
for (String url : urls) {
springMap.put(url, null);
}
getEditorSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
FeedsReader reader = new FeedsReader();
CachedFeedsManager manager = new CachedFeedsManager(title, springMap, reader);
try {
manager.readCachedFeeds(null);
Set<SyndEntry> entries = new HashSet<SyndEntry>();
for (SyndFeed entry : reader.getFeeds()) {
entries.addAll(entry.getEntries());
}
if (!getManagedForm().getForm().isDisposed()) {
displayFeeds(entries, feedsComposite, feedsScrolled, pagebook, disclaimer, section);
}
} catch (IllegalArgumentException e) {
StatusHandler.log(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "An unexpected error occurred while retrieving feed content from cache.", e));
} catch (FeedException e) {
StatusHandler.log(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "An unexpected error occurred while retrieving feed content from cache.", e));
}
}
});
refreshFeedsAction = new Action("Refresh Feeds", CommonImages.REFRESH) {
@Override
public void run() {
Map<String, String> springMap = getFeedsMap();
displayFeeds(feedsComposite, feedsScrolled, pagebook, disclaimer, springMap, title, section);
}
};
Action configureURLsAction = new Action("Configure URLs", StsUiImages.RSS_CONFIGURE) {
@Override
public void run() {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), URL_CONFIGURATION_ID, new String[] { URL_CONFIGURATION_ID }, null);
dialog.open();
}
};
section.setClient(pagebook);
section.setTextClient(headerComposite);
toolBarManager.add(configureURLsAction);
toolBarManager.add(refreshFeedsAction);
toolBarManager.update(true);
refreshFeedsAction.run();
}
use of com.sun.syndication.feed.synd.SyndFeed in project eclipse-integration-commons by spring-projects.
the class FeedsLabelProvider method getColumnImage.
public Image getColumnImage(Object element, int index) {
// public Image getColumnImage(Object element, int columnIndex) {
if (element instanceof SyndEntry) {
SyndEntry entry = (SyndEntry) element;
SyndFeed feed = feedsMap.get(entry);
if (feed == null) {
return CommonImages.getImage(IdeUiPlugin.getImageDescriptor(ICON_BLOG_BLANK));
}
//
// ImageDescriptor incoming = null;
ImageDescriptor feedImageDesc = feedReader.getImageDescriptorForFeed(feed);
if (feedType.equals(DashboardMainPage.FeedType.BLOG)) {
if (!prefStore.getBoolean(IIdeUiConstants.PREF_FEED_ENTRY_READ_STATE + ":" + entry.getLink())) {
return IdeUiPlugin.getImage(ICON_BLOG_INCOMING);
// incoming =
// IdeUiPlugin.getImageDescriptor(ICON_BLOG_INCOMING);
}
}
if (feedImageDesc == null) {
return IdeUiPlugin.getImage(ICON_BLOG_BLANK);
}
return CommonImages.getImage(feedImageDesc);
// if (incoming != null) {
// return CommonImages.getImageWithOverlay(feedImageDesc, incoming,
// true, true);
// }
// return CommonImages.getImage(feedImageDesc);
}
return null;
}
use of com.sun.syndication.feed.synd.SyndFeed in project eclipse-integration-commons by spring-projects.
the class FeedsLabelProvider method getColumnText.
public String getColumnText(Object element, int index) {
// public String getColumnText(Object element, int columnIndex) {
if (element instanceof StubSyndEntryImpl) {
return removeHtmlEntities(((StubSyndEntryImpl) element).getText());
}
if (element instanceof SyndEntry) {
SyndEntry entry = (SyndEntry) element;
SyndFeed feed = feedsMap.get(entry);
if (feed == null) {
return null;
}
String title = entry.getTitle();
Date entryDate = new Date(0);
if (entry.getUpdatedDate() != null) {
entryDate = entry.getUpdatedDate();
} else {
entryDate = entry.getPublishedDate();
}
String dateString = "";
if (entryDate != null) {
dateString = DateFormat.getDateInstance(DateFormat.SHORT).format(entryDate);
}
String entryAuthor = "";
if (entry.getAuthor() != null && entry.getAuthor().trim() != "") {
entryAuthor = " by " + entry.getAuthor();
}
if (feedType.equals(DashboardMainPage.FeedType.BLOG) && dateString.length() > 0 && entryAuthor.length() > 0) {
return removeHtmlEntities(title + " (" + dateString + entryAuthor + ")");
}
return removeHtmlEntities(title);
}
return null;
}
use of com.sun.syndication.feed.synd.SyndFeed in project eclipse-integration-commons by spring-projects.
the class FeedsReader method readFeeds.
@SuppressWarnings("unchecked")
public void readFeeds(Reader reader, SyndFeedInput input, String iconPath) throws IllegalArgumentException, FeedException {
SyndFeed feed = input.build(reader);
if (feed != null) {
feeds.add(feed);
feedsWithIcons.put(feed, iconPath);
List<SyndEntry> articlesList = feed.getEntries();
if (!articlesList.isEmpty()) {
for (SyndEntry article : articlesList) {
feedsWithEntries.put(article, feed);
}
}
}
}
use of com.sun.syndication.feed.synd.SyndFeed in project gitblit by gitblit.
the class SyndicationUtils method toRSS.
/**
* Outputs an RSS feed of the list of entries to the outputstream.
*
* @param hostUrl
* @param feedLink
* @param title
* @param description
* @param entryModels
* @param os
* @throws IOException
* @throws FeedException
*/
public static void toRSS(String hostUrl, String feedLink, String title, String description, List<FeedEntryModel> entryModels, OutputStream os) throws IOException, FeedException {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setEncoding("UTF-8");
feed.setTitle(title);
feed.setLink(feedLink);
if (StringUtils.isEmpty(description)) {
feed.setDescription(title);
} else {
feed.setDescription(description);
}
SyndImageImpl image = new SyndImageImpl();
image.setTitle(Constants.NAME);
image.setUrl(hostUrl + "/gitblt_25.png");
image.setLink(hostUrl);
feed.setImage(image);
List<SyndEntry> entries = new ArrayList<SyndEntry>();
for (FeedEntryModel entryModel : entryModels) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(entryModel.title);
entry.setAuthor(entryModel.author);
entry.setLink(entryModel.link);
entry.setPublishedDate(entryModel.published);
if (entryModel.tags != null && entryModel.tags.size() > 0) {
List<SyndCategory> tags = new ArrayList<SyndCategory>();
for (String tag : entryModel.tags) {
SyndCategoryImpl cat = new SyndCategoryImpl();
cat.setName(tag);
tags.add(cat);
}
entry.setCategories(tags);
}
SyndContent content = new SyndContentImpl();
if (StringUtils.isEmpty(entryModel.contentType) || entryModel.contentType.equalsIgnoreCase("text/plain")) {
content.setType("text/html");
content.setValue(StringUtils.breakLinesForHtml(entryModel.content));
} else {
content.setType(entryModel.contentType);
content.setValue(entryModel.content);
}
entry.setDescription(content);
entries.add(entry);
}
feed.setEntries(entries);
OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, writer);
writer.close();
}
Aggregations