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