Search in sources :

Example 41 with SyndFeed

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();
}
Also used : NewWizardAction(org.eclipse.ui.actions.NewWizardAction) Action(org.eclipse.jface.action.Action) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) ControlAdapter(org.eclipse.swt.events.ControlAdapter) HashMap(java.util.HashMap) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) GridLayout(org.eclipse.swt.layout.GridLayout) TextSearchControl(org.eclipse.mylyn.commons.workbench.search.TextSearchControl) Control(org.eclipse.swt.widgets.Control) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) RowLayout(org.eclipse.swt.layout.RowLayout) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) PaintListener(org.eclipse.swt.events.PaintListener) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) FeedException(com.sun.syndication.io.FeedException) Section(org.eclipse.ui.forms.widgets.Section) PageBook(org.eclipse.ui.part.PageBook) TableWrapLayout(org.eclipse.ui.forms.widgets.TableWrapLayout) GridData(org.eclipse.swt.layout.GridData) ControlEvent(org.eclipse.swt.events.ControlEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Example 42 with SyndFeed

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 43 with SyndFeed

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Date(java.util.Date)

Example 44 with SyndFeed

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);
            }
        }
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry)

Example 45 with SyndFeed

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();
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndImageImpl(com.sun.syndication.feed.synd.SyndImageImpl) FeedEntryModel(com.gitblit.models.FeedEntryModel) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndCategoryImpl(com.sun.syndication.feed.synd.SyndCategoryImpl) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)90 ArrayList (java.util.ArrayList)28 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)25 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)16 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)16 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)16 Test (org.testng.annotations.Test)16 Test (org.junit.Test)11 SkipException (org.testng.SkipException)11 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 FeedException (com.sun.syndication.io.FeedException)10 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)10 IOException (java.io.IOException)10 URL (java.net.URL)10 Date (java.util.Date)9 XmlReader (com.sun.syndication.io.XmlReader)8 HashMap (java.util.HashMap)8 ConsumerCert (rhsm.data.ConsumerCert)8 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)6