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.ContentTypes;
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.theme.ThemeDisplay;
023 import com.liferay.portal.util.PortalUtil;
024 import com.liferay.portal.util.WebKeys;
025 import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
026 import com.liferay.util.RSSUtil;
027 import com.liferay.util.servlet.ServletResponseUtil;
028
029 import javax.servlet.http.HttpServletRequest;
030 import javax.servlet.http.HttpServletResponse;
031
032 import org.apache.struts.action.Action;
033 import org.apache.struts.action.ActionForm;
034 import org.apache.struts.action.ActionForward;
035 import org.apache.struts.action.ActionMapping;
036
037
040 public class RSSAction extends Action {
041
042 public ActionForward execute(
043 ActionMapping mapping, ActionForm form, HttpServletRequest request,
044 HttpServletResponse response)
045 throws Exception {
046
047 try {
048 ServletResponseUtil.sendFile(
049 request, response, null, getRSS(request),
050 ContentTypes.TEXT_XML_UTF8);
051
052 return null;
053 }
054 catch (Exception e) {
055 PortalUtil.sendError(e, request, response);
056
057 return null;
058 }
059 }
060
061 protected byte[] getRSS(HttpServletRequest request) throws Exception {
062 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
063 WebKeys.THEME_DISPLAY);
064
065 String plid = ParamUtil.getString(request, "p_l_id");
066 long companyId = ParamUtil.getLong(request, "companyId");
067 long groupId = ParamUtil.getLong(request, "groupId");
068 long userId = ParamUtil.getLong(request, "userId");
069 long categoryId = ParamUtil.getLong(request, "mbCategoryId");
070 long threadId = ParamUtil.getLong(request, "threadId");
071 int max = ParamUtil.getInteger(
072 request, "max", SearchContainer.DEFAULT_DELTA);
073 String type = ParamUtil.getString(
074 request, "type", RSSUtil.DEFAULT_TYPE);
075 double version = ParamUtil.getDouble(
076 request, "version", RSSUtil.DEFAULT_VERSION);
077 String displayStyle = ParamUtil.getString(
078 request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
079
080 String entryURL =
081 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
082 "/message_boards/find_message?p_l_id=" + plid;
083
084 String rss = StringPool.BLANK;
085
086 if (companyId > 0) {
087 String feedURL = StringPool.BLANK;
088
089 rss = MBMessageServiceUtil.getCompanyMessagesRSS(
090 companyId, WorkflowConstants.STATUS_APPROVED, max, type,
091 version, displayStyle, feedURL, entryURL, themeDisplay);
092 }
093 else if (groupId > 0) {
094 String feedURL =
095 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
096 "/message_boards/find_recent_posts?p_l_id=" + plid;
097
098 if (userId > 0) {
099 rss = MBMessageServiceUtil.getGroupMessagesRSS(
100 groupId, userId, WorkflowConstants.STATUS_APPROVED, max,
101 type, version, displayStyle, feedURL, entryURL,
102 themeDisplay);
103 }
104 else {
105 rss = MBMessageServiceUtil.getGroupMessagesRSS(
106 groupId, WorkflowConstants.STATUS_APPROVED, max, type,
107 version, displayStyle, feedURL, entryURL, themeDisplay);
108 }
109 }
110 else if (categoryId > 0) {
111 String feedURL =
112 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
113 "/message_boards/find_category?p_l_id=" + plid +
114 "&mbCategoryId=" + categoryId;
115
116 rss = MBMessageServiceUtil.getCategoryMessagesRSS(
117 groupId, categoryId, WorkflowConstants.STATUS_APPROVED, max,
118 type, version, displayStyle, feedURL, entryURL, themeDisplay);
119 }
120 else if (threadId > 0) {
121 String feedURL =
122 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
123 "/message_boards/find_thread?p_l_id=" + plid +
124 "&threadId=" + threadId;
125
126 rss = MBMessageServiceUtil.getThreadMessagesRSS(
127 threadId, WorkflowConstants.STATUS_APPROVED, max, type, version,
128 displayStyle, feedURL, entryURL, themeDisplay);
129 }
130
131 return rss.getBytes(StringPool.UTF8);
132 }
133
134 }