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);
}
}
Aggregations