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