001
014
015 package com.liferay.portlet.messageboards.action;
016
017 import com.liferay.portal.kernel.dao.search.SearchContainer;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.RSSUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.workflow.WorkflowConstants;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portal.util.WebKeys;
024 import com.liferay.portlet.messageboards.MBGroupServiceSettings;
025 import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
026
027 import javax.portlet.PortletRequest;
028
029 import javax.servlet.http.HttpServletRequest;
030
031
034 public class RSSAction extends com.liferay.portal.struts.RSSAction {
035
036 @Override
037 protected byte[] getRSS(HttpServletRequest request) throws Exception {
038 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
039 WebKeys.THEME_DISPLAY);
040
041 String plid = ParamUtil.getString(request, "p_l_id");
042 long companyId = ParamUtil.getLong(request, "companyId");
043 long groupId = ParamUtil.getLong(request, "groupId");
044 long userId = ParamUtil.getLong(request, "userId");
045 long categoryId = ParamUtil.getLong(request, "mbCategoryId");
046 long threadId = ParamUtil.getLong(request, "threadId");
047 int max = ParamUtil.getInteger(
048 request, "max", SearchContainer.DEFAULT_DELTA);
049 String type = ParamUtil.getString(
050 request, "type", RSSUtil.FORMAT_DEFAULT);
051 double version = ParamUtil.getDouble(
052 request, "version", RSSUtil.VERSION_DEFAULT);
053 String displayStyle = ParamUtil.getString(
054 request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);
055
056 String entryURL =
057 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
058 "/message_boards/find_message?p_l_id=" + plid;
059
060 String rss = StringPool.BLANK;
061
062 if (companyId > 0) {
063 String feedURL = StringPool.BLANK;
064
065 rss = MBMessageServiceUtil.getCompanyMessagesRSS(
066 companyId, WorkflowConstants.STATUS_APPROVED, max, type,
067 version, displayStyle, feedURL, entryURL, themeDisplay);
068 }
069 else if (groupId > 0) {
070 String topLink = ParamUtil.getString(request, "topLink");
071
072 String feedURL = null;
073
074 if (topLink.equals("recent-posts")) {
075 feedURL =
076 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
077 "/message_boards/find_recent_posts?p_l_id=" + plid;
078 }
079 else {
080 feedURL =
081 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
082 "/message_boards/find_category?p_l_id=" + plid +
083 "&mbCategoryId=" + categoryId;
084 }
085
086 if (userId > 0) {
087 rss = MBMessageServiceUtil.getGroupMessagesRSS(
088 groupId, userId, WorkflowConstants.STATUS_APPROVED, max,
089 type, version, displayStyle, feedURL, entryURL,
090 themeDisplay);
091 }
092 else {
093 rss = MBMessageServiceUtil.getGroupMessagesRSS(
094 groupId, WorkflowConstants.STATUS_APPROVED, max, type,
095 version, displayStyle, feedURL, entryURL, themeDisplay);
096 }
097 }
098 else if (categoryId > 0) {
099 String feedURL =
100 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
101 "/message_boards/find_category?p_l_id=" + plid +
102 "&mbCategoryId=" + categoryId;
103
104 rss = MBMessageServiceUtil.getCategoryMessagesRSS(
105 groupId, categoryId, WorkflowConstants.STATUS_APPROVED, max,
106 type, version, displayStyle, feedURL, entryURL, themeDisplay);
107 }
108 else if (threadId > 0) {
109 String feedURL =
110 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
111 "/message_boards/find_thread?p_l_id=" + plid +
112 "&threadId=" + threadId;
113
114 rss = MBMessageServiceUtil.getThreadMessagesRSS(
115 threadId, WorkflowConstants.STATUS_APPROVED, max, type, version,
116 displayStyle, feedURL, entryURL, themeDisplay);
117 }
118
119 return rss.getBytes(StringPool.UTF8);
120 }
121
122 @Override
123 protected boolean isRSSFeedsEnabled(PortletRequest portletRequest)
124 throws Exception {
125
126 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
127 WebKeys.THEME_DISPLAY);
128
129 MBGroupServiceSettings mbGroupServiceSettings =
130 MBGroupServiceSettings.getInstance(themeDisplay.getSiteGroupId());
131
132 return mbGroupServiceSettings.isEnableRSS();
133 }
134
135 }