Search in sources :

Example 1 with SyndLink

use of com.sun.syndication.feed.synd.SyndLink 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)

Aggregations

KBArticle (com.liferay.knowledgebase.model.KBArticle)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 SyndContent (com.sun.syndication.feed.synd.SyndContent)1 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)1 SyndLink (com.sun.syndication.feed.synd.SyndLink)1 SyndLinkImpl (com.sun.syndication.feed.synd.SyndLinkImpl)1 FeedException (com.sun.syndication.io.FeedException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1