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 actionMapping, ActionForm actionForm,
046 HttpServletRequest request, 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 actionMapping.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 topLink = ParamUtil.getString(request, "topLink");
097
098 String feedURL = null;
099
100 if (topLink.equals("recent-posts")) {
101 feedURL =
102 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
103 "/message_boards/find_recent_posts?p_l_id=" + plid;
104 }
105 else {
106 feedURL =
107 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
108 "/message_boards/find_category?p_l_id=" + plid +
109 "&mbCategoryId=" + categoryId;
110 }
111
112 if (userId > 0) {
113 rss = MBMessageServiceUtil.getGroupMessagesRSS(
114 groupId, userId, WorkflowConstants.STATUS_APPROVED, max,
115 type, version, displayStyle, feedURL, entryURL,
116 themeDisplay);
117 }
118 else {
119 rss = MBMessageServiceUtil.getGroupMessagesRSS(
120 groupId, WorkflowConstants.STATUS_APPROVED, max, type,
121 version, displayStyle, feedURL, entryURL, themeDisplay);
122 }
123 }
124 else if (categoryId > 0) {
125 String feedURL =
126 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
127 "/message_boards/find_category?p_l_id=" + plid +
128 "&mbCategoryId=" + categoryId;
129
130 rss = MBMessageServiceUtil.getCategoryMessagesRSS(
131 groupId, categoryId, WorkflowConstants.STATUS_APPROVED, max,
132 type, version, displayStyle, feedURL, entryURL, themeDisplay);
133 }
134 else if (threadId > 0) {
135 String feedURL =
136 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
137 "/message_boards/find_thread?p_l_id=" + plid +
138 "&threadId=" + threadId;
139
140 rss = MBMessageServiceUtil.getThreadMessagesRSS(
141 threadId, WorkflowConstants.STATUS_APPROVED, max, type, version,
142 displayStyle, feedURL, entryURL, themeDisplay);
143 }
144
145 return rss.getBytes(StringPool.UTF8);
146 }
147
148 }