001
014
015 package com.liferay.portlet.blogs.action;
016
017 import com.liferay.portal.kernel.dao.search.SearchContainer;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.workflow.WorkflowConstants;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.Portal;
025 import com.liferay.portal.util.PortalUtil;
026 import com.liferay.portal.util.WebKeys;
027 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
028 import com.liferay.util.RSSUtil;
029
030 import java.util.Date;
031
032 import javax.portlet.PortletPreferences;
033 import javax.portlet.PortletRequest;
034
035 import javax.servlet.http.HttpServletRequest;
036
037
040 public class RSSAction extends com.liferay.portal.struts.RSSAction {
041
042 @Override
043 protected byte[] getRSS(HttpServletRequest request) throws Exception {
044 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
045 WebKeys.THEME_DISPLAY);
046
047 Layout layout = themeDisplay.getLayout();
048
049 long plid = ParamUtil.getLong(request, "p_l_id");
050 long companyId = ParamUtil.getLong(request, "companyId");
051 long groupId = ParamUtil.getLong(request, "groupId");
052 long organizationId = ParamUtil.getLong(request, "organizationId");
053 int status = WorkflowConstants.STATUS_APPROVED;
054 int max = ParamUtil.getInteger(
055 request, "max", SearchContainer.DEFAULT_DELTA);
056 String type = ParamUtil.getString(
057 request, "type", RSSUtil.FORMAT_DEFAULT);
058 double version = ParamUtil.getDouble(
059 request, "version", RSSUtil.VERSION_DEFAULT);
060 String displayStyle = ParamUtil.getString(
061 request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);
062
063 String feedURL =
064 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
065 "/blogs/find_entry?";
066
067 String entryURL = feedURL;
068
069 String rss = StringPool.BLANK;
070
071 if (companyId > 0) {
072 feedURL = StringPool.BLANK;
073
074 rss = BlogsEntryServiceUtil.getCompanyEntriesRSS(
075 companyId, new Date(), status, max, type, version, displayStyle,
076 feedURL, entryURL, themeDisplay);
077 }
078 else if (groupId > 0) {
079 feedURL += "p_l_id=" + plid;
080
081 entryURL = feedURL;
082
083 rss = BlogsEntryServiceUtil.getGroupEntriesRSS(
084 groupId, new Date(), status, max, type, version, displayStyle,
085 feedURL, entryURL, themeDisplay);
086 }
087 else if (organizationId > 0) {
088 feedURL = StringPool.BLANK;
089
090 rss = BlogsEntryServiceUtil.getOrganizationEntriesRSS(
091 organizationId, new Date(), status, max, type, version,
092 displayStyle, feedURL, entryURL, themeDisplay);
093 }
094 else if (layout != null) {
095 groupId = themeDisplay.getScopeGroupId();
096
097 feedURL =
098 PortalUtil.getLayoutFullURL(themeDisplay) +
099 Portal.FRIENDLY_URL_SEPARATOR + "blogs/rss";
100
101 entryURL = feedURL;
102
103 rss = BlogsEntryServiceUtil.getGroupEntriesRSS(
104 groupId, new Date(), status, max, type, version, displayStyle,
105 feedURL, entryURL, themeDisplay);
106 }
107
108 return rss.getBytes(StringPool.UTF8);
109 }
110
111 @Override
112 protected boolean isRSSFeedsEnabled(PortletRequest portletRequest)
113 throws Exception {
114
115 if (!super.isRSSFeedsEnabled(portletRequest)) {
116 return false;
117 }
118
119 PortletPreferences portletPreferences = portletRequest.getPreferences();
120
121 return GetterUtil.getBoolean(
122 portletPreferences.getValue("enableRss", null), true);
123 }
124
125 }