Search in sources :

Example 11 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project eclipse-integration-commons by spring-projects.

the class BlogsProvider method buildDescription.

private String buildDescription(SyndEntry entry) {
    SyndContent content = entry.getDescription();
    if (content == null) {
        List<?> nestedContent = entry.getContents();
        if (!nestedContent.isEmpty()) {
            Object obj = nestedContent.get(0);
            if (obj instanceof SyndContent) {
                content = (SyndContent) obj;
            }
        }
    }
    if (content == null) {
        return "";
    }
    String value = content.getValue();
    if (value == null) {
        return "";
    }
    if (value.startsWith("<form>")) {
        return value;
    }
    return removeHtmlEntities(value);
}
Also used : SyndContent(com.sun.syndication.feed.synd.SyndContent)

Example 12 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project xwiki-platform by xwiki.

the class FeedPlugin method saveEntry.

private void saveEntry(String feedname, String feedurl, SyndEntry entry, XWikiDocument doc, BaseObject obj, boolean fullContent, XWikiContext context) throws XWikiException {
    obj.setStringValue("feedname", feedname);
    obj.setStringValue("title", entry.getTitle());
    // set document title to the feed title
    String title;
    try {
        // Strips HTML tags that the feed can output, since they are not supported in document titles.
        // (For example Google Blog search adds a <b> tag around matched keyword in title)
        // If some day wiki syntax is supported in document titles, we might want to convert to wiki syntax instead.
        title = this.stripHtmlTags(entry.getTitle());
    } catch (ConversionException e) {
        LOGGER.warn("Failed to strip HTML tags from entry title : " + e.getMessage());
        // Nevermind, we will use the original title
        title = entry.getTitle();
    }
    doc.setTitle(title);
    obj.setIntValue("flag", 0);
    @SuppressWarnings("unchecked") List<SyndCategory> categList = entry.getCategories();
    StringBuffer categs = new StringBuffer("");
    if (categList != null) {
        for (SyndCategory categ : categList) {
            if (categs.length() != 0) {
                categs.append(", ");
            }
            categs.append(categ.getName());
        }
    }
    obj.setStringValue("category", categs.toString());
    StringBuffer contents = new StringBuffer("");
    String description = (entry.getDescription() == null) ? null : entry.getDescription().getValue();
    @SuppressWarnings("unchecked") List<SyndContent> contentList = entry.getContents();
    if (contentList != null && contentList.size() > 0) {
        for (SyndContent content : contentList) {
            if (contents.length() != 0) {
                contents.append("\n");
            }
            contents.append(content.getValue());
        }
    }
    // If we find more data in the description we will use that one instead of the content field
    if ((description != null) && (description.length() > contents.length())) {
        obj.setLargeStringValue("content", description);
    } else {
        obj.setLargeStringValue("content", contents.toString());
    }
    Date edate = entry.getPublishedDate();
    if (edate == null) {
        edate = new Date();
    }
    obj.setDateValue("date", edate);
    obj.setStringValue("url", entry.getLink());
    obj.setStringValue("author", entry.getAuthor());
    obj.setStringValue("feedurl", feedurl);
    // TODO: need to get entry xml or serialization
    // obj.setLargeStringValue("xml", entry.toString());
    obj.setLargeStringValue("xml", "");
    if (fullContent) {
        String url = entry.getLink();
        if ((url != null) && (!url.trim().equals(""))) {
            try {
                String sfullContent = context.getWiki().getURLContent(url, context);
                obj.setLargeStringValue("fullContent", (sfullContent.length() > 65000) ? sfullContent.substring(0, 65000) : sfullContent);
            } catch (Exception e) {
                obj.setLargeStringValue("fullContent", "Exception while reading fullContent: " + e.getMessage());
            }
        } else {
            obj.setLargeStringValue("fullContent", "No url");
        }
    }
}
Also used : ConversionException(org.xwiki.rendering.converter.ConversionException) SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndContent(com.sun.syndication.feed.synd.SyndContent) Date(java.util.Date) XWikiException(com.xpn.xwiki.XWikiException) ConversionException(org.xwiki.rendering.converter.ConversionException) IOException(java.io.IOException) CacheException(org.xwiki.cache.CacheException)

Example 13 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project liferay-ide by liferay.

the class KBArticleServiceImpl method exportToRSS.

protected String exportToRSS(String rssDisplayStyle, String rssFormat, String name, String description, String feedURL, List<KBArticle> kbArticles, ThemeDisplay themeDisplay) throws SystemException {
    SyndFeed syndFeed = new SyndFeedImpl();
    syndFeed.setDescription(description);
    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
    syndFeed.setEntries(syndEntries);
    for (KBArticle kbArticle : kbArticles) {
        SyndEntry syndEntry = new SyndEntryImpl();
        String author = PortalUtil.getUserName(kbArticle);
        syndEntry.setAuthor(author);
        SyndContent syndContent = new SyndContentImpl();
        syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
        String value = null;
        if (rssDisplayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
            value = HtmlUtil.extractText(kbArticle.getDescription());
            if (Validator.isNull(value)) {
                value = StringUtil.shorten(HtmlUtil.extractText(kbArticle.getContent()), 200);
            }
        } else if (rssDisplayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
            value = StringPool.BLANK;
        } else {
            value = StringUtil.replace(kbArticle.getContent(), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + themeDisplay.getURLPortal() + "/", "src=\"" + themeDisplay.getURLPortal() + "/" });
        }
        syndContent.setValue(value);
        syndEntry.setDescription(syndContent);
        String link = KnowledgeBaseUtil.getKBArticleURL(themeDisplay.getPlid(), kbArticle.getResourcePrimKey(), kbArticle.getStatus(), themeDisplay.getPortalURL(), false);
        syndEntry.setLink(link);
        syndEntry.setPublishedDate(kbArticle.getCreateDate());
        syndEntry.setTitle(kbArticle.getTitle());
        syndEntry.setUpdatedDate(kbArticle.getModifiedDate());
        syndEntry.setUri(syndEntry.getLink());
        syndEntries.add(syndEntry);
    }
    String feedType = RSSUtil.getFeedType(RSSUtil.getFormatType(rssFormat), RSSUtil.getFormatVersion(rssFormat));
    syndFeed.setFeedType(feedType);
    List<SyndLink> syndLinks = new ArrayList<SyndLink>();
    syndFeed.setLinks(syndLinks);
    SyndLink selfSyndLink = new SyndLinkImpl();
    syndLinks.add(selfSyndLink);
    selfSyndLink.setHref(feedURL);
    selfSyndLink.setRel("self");
    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);
    try {
        return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
        throw new SystemException(fe);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndLinkImpl(com.sun.syndication.feed.synd.SyndLinkImpl) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) KBArticle(com.liferay.knowledgebase.model.KBArticle) SyndContent(com.sun.syndication.feed.synd.SyndContent) SystemException(com.liferay.portal.kernel.exception.SystemException) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndLink(com.sun.syndication.feed.synd.SyndLink)

Example 14 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project archiva by apache.

the class RssFeedGenerator method getEntries.

private List<SyndEntry> getEntries(List<RssFeedEntry> dataEntries) {
    List<SyndEntry> entries = new ArrayList<>();
    SyndEntry entry;
    SyndContent description;
    for (RssFeedEntry dataEntry : dataEntries) {
        entry = new SyndEntryImpl();
        entry.setTitle(dataEntry.getTitle());
        entry.setPublishedDate(dataEntry.getPublishedDate());
        description = new SyndContentImpl();
        description.setType("text/plain");
        description.setValue(dataEntry.getDescription());
        entry.setDescription(description);
        entries.add(entry);
    }
    return entries;
}
Also used : SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList)

Example 15 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project maven-plugins by apache.

the class FeedGenerator method getSyndContent.

private static SyndContent getSyndContent(final Release release) {
    final SyndContent syndContent = new SyndContentImpl();
    syndContent.setType("text/html");
    final StringBuilder sb = new StringBuilder(512);
    final String description = release.getDescription();
    if (description != null && description.trim().length() > 0) {
        sb.append("<p>").append(description).append("</p>");
    }
    // TODO: localize?
    sb.append("<p>Version ").append(release.getVersion()).append(" is available with ");
    sb.append(release.getActions().size()).append(" fixed issues.</p>");
    syndContent.setValue(sb.toString());
    return syndContent;
}
Also used : SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl)

Aggregations

SyndContent (com.sun.syndication.feed.synd.SyndContent)17 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)12 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)12 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)10 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)5 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)5 IOException (java.io.IOException)4 FeedException (com.sun.syndication.io.FeedException)3 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 OutputStreamWriter (java.io.OutputStreamWriter)2 List (java.util.List)2 Post (com.erudika.scoold.core.Post)1 Question (com.erudika.scoold.core.Question)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 GeoRSSModule (com.sun.syndication.feed.module.georss.GeoRSSModule)1