protected byte[] getRSS(PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { PortletPreferences preferences = portletRequest.getPreferences(); String selectionStyle = preferences.getValue("selectionStyle", "dynamic"); if (!selectionStyle.equals("dynamic")) { return new byte[0]; } String rssName = preferences.getValue("rssName", null); String rssFormat = preferences.getValue("rssFormat", "atom10"); String rssDisplayStyle = preferences.getValue("rssDisplayStyle", RSSUtil.DISPLAY_STYLE_ABSTRACT); String assetLinkBehavior = preferences.getValue("assetLinkBehavior", "showFullContent"); String rss = exportToRSS( portletRequest, portletResponse, rssName, null, RSSUtil.getFormatType(rssFormat), RSSUtil.getFormatVersion(rssFormat), rssDisplayStyle, assetLinkBehavior, getAssetEntries(portletRequest, preferences)); return rss.getBytes(StringPool.UTF8); }
public static byte[] getRSS(ResourceRequest portletRequest, ResourceResponse portletResponse) throws Exception { PortletPreferences portletPreferences = portletRequest.getPreferences(); String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic"); if (!selectionStyle.equals("dynamic")) { return new byte[0]; } String assetLinkBehavior = portletPreferences.getValue("assetLinkBehavior", "showFullContent"); String rssDisplayStyle = portletPreferences.getValue("rssDisplayStyle", RSSUtil.DISPLAY_STYLE_ABSTRACT); String rssFeedType = portletPreferences.getValue("rssFeedType", RSSUtil.FEED_TYPE_DEFAULT); String rssName = portletPreferences.getValue("rssName", null); String format = RSSUtil.getFeedTypeFormat(rssFeedType); double version = RSSUtil.getFeedTypeVersion(rssFeedType); String rss = exportToRSS( portletRequest, portletResponse, rssName, null, format, version, rssDisplayStyle, assetLinkBehavior, getAssetEntries(portletRequest, portletPreferences)); return rss.getBytes(StringPool.UTF8); }
protected String exportToRSS( PortletRequest portletRequest, PortletResponse portletResponse, String name, String description, String type, double version, String displayStyle, String linkBehavior, List<AssetEntry> assetEntries) throws Exception { SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setFeedType(RSSUtil.getFeedType(type, version)); syndFeed.setTitle(name); syndFeed.setLink(getFeedURL(portletRequest)); syndFeed.setDescription(GetterUtil.getString(description, name)); List<SyndEntry> syndEntries = new ArrayList<SyndEntry>(); syndFeed.setEntries(syndEntries); for (AssetEntry assetEntry : assetEntries) { String link = getEntryURL(portletRequest, portletResponse, linkBehavior, assetEntry); String author = PortalUtil.getUserName(assetEntry); String value = null; String languageId = LanguageUtil.getLanguageId(portletRequest); if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) { value = StringPool.BLANK; } else { value = assetEntry.getSummary(languageId, true); } SyndEntry syndEntry = new SyndEntryImpl(); syndEntry.setAuthor(author); syndEntry.setTitle(assetEntry.getTitle(languageId, true)); syndEntry.setLink(link); syndEntry.setUri(syndEntry.getLink()); syndEntry.setPublishedDate(assetEntry.getCreateDate()); syndEntry.setUpdatedDate(assetEntry.getModifiedDate()); SyndContent syndContent = new SyndContentImpl(); syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT); syndContent.setValue(value); syndEntry.setDescription(syndContent); syndEntries.add(syndEntry); } return RSSUtil.export(syndFeed); }
protected String exportToRSS( ResourceRequest resourceRequest, ResourceResponse resourceResponse, String title, String description, String format, double version, String displayStyle, List<SocialActivity> socialActivities, ServiceContext serviceContext) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setDescription(GetterUtil.getString(description, title)); List<SyndEntry> syndEntries = new ArrayList<>(); syndFeed.setEntries(syndEntries); for (SocialActivity socialActivity : socialActivities) { SocialActivityFeedEntry socialActivityFeedEntry = _socialActivityInterpreterLocalService.interpret( StringPool.BLANK, socialActivity, serviceContext); if (socialActivityFeedEntry == null) { continue; } SyndEntry syndEntry = new SyndEntryImpl(); SyndContent syndContent = new SyndContentImpl(); syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT); String value = null; if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) { value = StringPool.BLANK; } else { value = socialActivityFeedEntry.getBody(); } syndContent.setValue(value); syndEntry.setDescription(syndContent); if (Validator.isNotNull(socialActivityFeedEntry.getLink())) { syndEntry.setLink(socialActivityFeedEntry.getLink()); } syndEntry.setPublishedDate(new Date(socialActivity.getCreateDate())); syndEntry.setTitle(HtmlUtil.extractText(socialActivityFeedEntry.getTitle())); syndEntry.setUri(syndEntry.getLink()); syndEntries.add(syndEntry); } syndFeed.setFeedType(RSSUtil.getFeedType(format, version)); List<SyndLink> syndLinks = new ArrayList<>(); syndFeed.setLinks(syndLinks); SyndLink selfSyndLink = new SyndLinkImpl(); syndLinks.add(selfSyndLink); LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) resourceResponse; ResourceURL rssURL = liferayPortletResponse.createResourceURL(); rssURL.setParameter("feedTitle", title); rssURL.setResourceID("rss"); selfSyndLink.setHref(rssURL.toString()); selfSyndLink.setRel("self"); SyndLink alternateSyndLink = new SyndLinkImpl(); syndLinks.add(alternateSyndLink); alternateSyndLink.setHref(PortalUtil.getLayoutFullURL(themeDisplay)); alternateSyndLink.setRel("alternate"); syndFeed.setPublishedDate(new Date()); syndFeed.setTitle(title); syndFeed.setUri(rssURL.toString()); return RSSUtil.export(syndFeed); }
protected String exportToRSS( String name, String description, String type, double version, String displayStyle, String feedURL, String entryURL, List blogsEntries) throws SystemException { SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setFeedType(type + "_" + version); syndFeed.setTitle(name); syndFeed.setLink(feedURL); syndFeed.setDescription(GetterUtil.getString(description, name)); List entries = new ArrayList(); syndFeed.setEntries(entries); Iterator itr = blogsEntries.iterator(); while (itr.hasNext()) { BlogsEntry entry = (BlogsEntry) itr.next(); String author = PortalUtil.getUserName(entry.getUserId(), entry.getUserName()); String link = entryURL; if (link.endsWith("/blogs/rss")) { link = link.substring(0, link.length() - 3) + entry.getUrlTitle(); } else { if (!link.endsWith("?")) { link += "&"; } link += "entryId=" + entry.getEntryId(); } String value = null; if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) { value = StringUtil.shorten( Html.stripHtml(entry.getContent()), _RSS_ABSTRACT_LENGTH, StringPool.BLANK); } else { value = entry.getContent(); } SyndEntry syndEntry = new SyndEntryImpl(); syndEntry.setAuthor(author); syndEntry.setTitle(entry.getTitle()); syndEntry.setLink(link); syndEntry.setPublishedDate(entry.getCreateDate()); SyndContent syndContent = new SyndContentImpl(); syndContent.setType("html"); syndContent.setValue(value); syndEntry.setDescription(syndContent); entries.add(syndEntry); } try { return RSSUtil.export(syndFeed); } catch (FeedException fe) { throw new SystemException(fe); } catch (IOException ioe) { throw new SystemException(ioe); } }
protected String exportToRSS( String name, String description, String type, double version, String displayStyle, String feedURL, String entryURL, List<MBMessage> messages, ThemeDisplay themeDisplay) throws SystemException { SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setDescription(description); List<SyndEntry> syndEntries = new ArrayList<SyndEntry>(); syndFeed.setEntries(syndEntries); for (MBMessage message : messages) { SyndEntry syndEntry = new SyndEntryImpl(); if (!message.isAnonymous()) { String author = PortalUtil.getUserName(message); syndEntry.setAuthor(author); } SyndContent syndContent = new SyndContentImpl(); syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT); String value = null; if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) { value = StringUtil.shorten( HtmlUtil.extractText(message.getBody()), PropsValues.MESSAGE_BOARDS_RSS_ABSTRACT_LENGTH, StringPool.BLANK); } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) { value = StringPool.BLANK; } else if (message.isFormatBBCode()) { value = BBCodeTranslatorUtil.getHTML(message.getBody()); value = MBUtil.replaceMessageBodyPaths(themeDisplay, value); } else { value = message.getBody(); } syndContent.setValue(value); syndEntry.setDescription(syndContent); syndEntry.setLink(entryURL + "&messageId=" + message.getMessageId()); syndEntry.setPublishedDate(message.getCreateDate()); syndEntry.setTitle(message.getSubject()); syndEntry.setUpdatedDate(message.getModifiedDate()); syndEntry.setUri(syndEntry.getLink()); syndEntries.add(syndEntry); } syndFeed.setFeedType(RSSUtil.getFeedType(type, version)); 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); } }
protected static String exportToRSS( PortletRequest portletRequest, PortletResponse portletResponse, String name, String description, String format, double version, String displayStyle, String linkBehavior, List<AssetEntry> assetEntries) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setDescription(GetterUtil.getString(description, name)); List<SyndEntry> syndEntries = new ArrayList<>(); syndFeed.setEntries(syndEntries); for (AssetEntry assetEntry : assetEntries) { SyndEntry syndEntry = new SyndEntryImpl(); String author = PortalUtil.getUserName(assetEntry); syndEntry.setAuthor(author); SyndContent syndContent = new SyndContentImpl(); syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT); String value = null; String languageId = LanguageUtil.getLanguageId(portletRequest); if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) { value = StringPool.BLANK; } else { value = assetEntry.getSummary(languageId, true); } syndContent.setValue(value); syndEntry.setDescription(syndContent); String link = getEntryURL(portletRequest, portletResponse, linkBehavior, assetEntry); syndEntry.setLink(link); syndEntry.setPublishedDate(assetEntry.getPublishDate()); syndEntry.setTitle(assetEntry.getTitle(languageId, true)); syndEntry.setUpdatedDate(assetEntry.getModifiedDate()); syndEntry.setUri(syndEntry.getLink()); syndEntries.add(syndEntry); } syndFeed.setFeedType(RSSUtil.getFeedType(format, version)); List<SyndLink> syndLinks = new ArrayList<>(); syndFeed.setLinks(syndLinks); SyndLink selfSyndLink = new SyndLinkImpl(); syndLinks.add(selfSyndLink); String feedURL = getFeedURL(portletRequest); selfSyndLink.setHref(feedURL); selfSyndLink.setRel("self"); SyndLink alternateSyndLink = new SyndLinkImpl(); syndLinks.add(alternateSyndLink); alternateSyndLink.setHref(PortalUtil.getLayoutFullURL(themeDisplay)); alternateSyndLink.setRel("alternate"); syndFeed.setPublishedDate(new Date()); syndFeed.setTitle(name); syndFeed.setUri(feedURL); return RSSUtil.export(syndFeed); }
protected String exportToRSS( long companyId, String name, String description, String type, double version, String displayStyle, String feedURL, String entryURL, List<WikiPage> pages, boolean diff, Locale locale) throws SystemException { SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setFeedType(RSSUtil.getFeedType(type, version)); syndFeed.setTitle(name); syndFeed.setLink(feedURL); syndFeed.setDescription(description); List<SyndEntry> syndEntries = new ArrayList<SyndEntry>(); syndFeed.setEntries(syndEntries); WikiPage latestPage = null; StringBundler link = new StringBundler(7); for (WikiPage page : pages) { String author = HtmlUtil.escape(PortalUtil.getUserName(page.getUserId(), page.getUserName())); String title = page.getTitle() + StringPool.SPACE + page.getVersion(); if (page.isMinorEdit()) { title += StringPool.SPACE + StringPool.OPEN_PARENTHESIS + LanguageUtil.get(locale, "minor-edit") + StringPool.CLOSE_PARENTHESIS; } link.setIndex(0); link.append(entryURL); link.append(StringPool.AMPERSAND); link.append(HttpUtil.encodeURL(page.getTitle())); SyndEntry syndEntry = new SyndEntryImpl(); syndEntry.setAuthor(author); syndEntry.setTitle(title); syndEntry.setPublishedDate(page.getCreateDate()); syndEntry.setUpdatedDate(page.getModifiedDate()); SyndContent syndContent = new SyndContentImpl(); syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT); if (diff) { if (latestPage != null) { link.append(StringPool.QUESTION); link.append(PortalUtil.getPortletNamespace(PortletKeys.WIKI)); link.append("version="); link.append(page.getVersion()); String value = getPageDiff(companyId, latestPage, page, locale); syndContent.setValue(value); syndEntry.setDescription(syndContent); syndEntries.add(syndEntry); } } else { String value = null; if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) { value = StringUtil.shorten( HtmlUtil.extractText(page.getContent()), PropsValues.WIKI_RSS_ABSTRACT_LENGTH, StringPool.BLANK); } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) { value = StringPool.BLANK; } else { value = page.getContent(); } syndContent.setValue(value); syndEntry.setDescription(syndContent); syndEntries.add(syndEntry); } syndEntry.setLink(link.toString()); syndEntry.setUri(syndEntry.getLink()); latestPage = page; } try { return RSSUtil.export(syndFeed); } catch (FeedException fe) { throw new SystemException(fe); } }
protected String exportToRSS( ResourceRequest resourceRequest, ResourceResponse resourceResponse, JournalFeed feed, String languageId, Layout layout, ThemeDisplay themeDisplay) throws Exception { SyndFeed syndFeed = new SyndFeedImpl(); syndFeed.setDescription(feed.getDescription()); List<SyndEntry> syndEntries = new ArrayList<SyndEntry>(); syndFeed.setEntries(syndEntries); List<JournalArticle> articles = JournalRSSUtil.getArticles(feed); if (_log.isDebugEnabled()) { _log.debug("Syndicating " + articles.size() + " articles"); } for (JournalArticle article : articles) { SyndEntry syndEntry = new SyndEntryImpl(); String author = PortalUtil.getUserName(article); syndEntry.setAuthor(author); SyndContent syndContent = new SyndContentImpl(); syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT); String value = article.getDescription(languageId); try { value = processContent(feed, article, languageId, themeDisplay, syndEntry, syndContent); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } } syndContent.setValue(value); syndEntry.setDescription(syndContent); String link = getEntryURL(resourceRequest, feed, article, layout, themeDisplay); syndEntry.setLink(link); syndEntry.setPublishedDate(article.getDisplayDate()); syndEntry.setTitle(article.getTitle(languageId)); syndEntry.setUpdatedDate(article.getModifiedDate()); syndEntry.setUri(link); syndEntries.add(syndEntry); } syndFeed.setFeedType(feed.getFeedType() + "_" + feed.getFeedVersion()); List<SyndLink> syndLinks = new ArrayList<SyndLink>(); syndFeed.setLinks(syndLinks); SyndLink selfSyndLink = new SyndLinkImpl(); syndLinks.add(selfSyndLink); ResourceURL feedURL = resourceResponse.createResourceURL(); feedURL.setCacheability(ResourceURL.FULL); feedURL.setParameter("struts_action", "/journal/rss"); feedURL.setParameter("groupId", String.valueOf(feed.getGroupId())); feedURL.setParameter("feedId", String.valueOf(feed.getFeedId())); String link = feedURL.toString(); selfSyndLink.setHref(link); selfSyndLink.setRel("self"); syndFeed.setTitle(feed.getName()); syndFeed.setPublishedDate(new Date()); syndFeed.setUri(feedURL.toString()); try { return RSSUtil.export(syndFeed); } catch (FeedException fe) { throw new SystemException(fe); } }