1
14
15 package com.liferay.portlet.messageboards.action;
16
17 import com.liferay.portal.kernel.dao.search.SearchContainer;
18 import com.liferay.portal.kernel.util.ContentTypes;
19 import com.liferay.portal.kernel.util.ParamUtil;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.workflow.StatusConstants;
22 import com.liferay.portal.theme.ThemeDisplay;
23 import com.liferay.portal.util.PortalUtil;
24 import com.liferay.portal.util.WebKeys;
25 import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
26 import com.liferay.util.RSSUtil;
27 import com.liferay.util.servlet.ServletResponseUtil;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.apache.struts.action.Action;
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36
37
42 public class RSSAction extends Action {
43
44 public ActionForward execute(
45 ActionMapping mapping, ActionForm form, HttpServletRequest request,
46 HttpServletResponse response)
47 throws Exception {
48
49 try {
50 ServletResponseUtil.sendFile(
51 request, response, null, getRSS(request),
52 ContentTypes.TEXT_XML_UTF8);
53
54 return null;
55 }
56 catch (Exception e) {
57 PortalUtil.sendError(e, request, response);
58
59 return null;
60 }
61 }
62
63 protected byte[] getRSS(HttpServletRequest request) throws Exception {
64 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
65 WebKeys.THEME_DISPLAY);
66
67 String plid = ParamUtil.getString(request, "p_l_id");
68 long companyId = ParamUtil.getLong(request, "companyId");
69 long groupId = ParamUtil.getLong(request, "groupId");
70 long userId = ParamUtil.getLong(request, "userId");
71 long categoryId = ParamUtil.getLong(request, "mbCategoryId");
72 long threadId = ParamUtil.getLong(request, "threadId");
73 int max = ParamUtil.getInteger(
74 request, "max", SearchContainer.DEFAULT_DELTA);
75 String type = ParamUtil.getString(
76 request, "type", RSSUtil.DEFAULT_TYPE);
77 double version = ParamUtil.getDouble(
78 request, "version", RSSUtil.DEFAULT_VERSION);
79 String displayStyle = ParamUtil.getString(
80 request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
81
82 String entryURL =
83 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
84 "/message_boards/find_message?p_l_id=" + plid;
85
86 String rss = StringPool.BLANK;
87
88 if (companyId > 0) {
89 String feedURL = StringPool.BLANK;
90
91 rss = MBMessageServiceUtil.getCompanyMessagesRSS(
92 companyId, StatusConstants.APPROVED, max, type, version,
93 displayStyle, feedURL, entryURL, themeDisplay);
94 }
95 else if (groupId > 0) {
96 String feedURL =
97 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
98 "/message_boards/find_recent_posts?p_l_id=" + plid;
99
100 if (userId > 0) {
101 rss = MBMessageServiceUtil.getGroupMessagesRSS(
102 groupId, userId, StatusConstants.APPROVED, max, type,
103 version, displayStyle, feedURL, entryURL, themeDisplay);
104 }
105 else {
106 rss = MBMessageServiceUtil.getGroupMessagesRSS(
107 groupId, StatusConstants.APPROVED, max, type, version,
108 displayStyle, feedURL, entryURL, themeDisplay);
109 }
110 }
111 else if (categoryId > 0) {
112 String feedURL =
113 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
114 "/message_boards/find_category?p_l_id=" + plid +
115 "&mbCategoryId=" + categoryId;
116
117 rss = MBMessageServiceUtil.getCategoryMessagesRSS(
118 groupId, categoryId, StatusConstants.APPROVED, max, type,
119 version, displayStyle, feedURL, entryURL, themeDisplay);
120 }
121 else if (threadId > 0) {
122 String feedURL =
123 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
124 "/message_boards/find_thread?p_l_id=" + plid +
125 "&threadId=" + threadId;
126
127 rss = MBMessageServiceUtil.getThreadMessagesRSS(
128 threadId, StatusConstants.APPROVED, max, type, version,
129 displayStyle, feedURL, entryURL, themeDisplay);
130 }
131
132 return rss.getBytes(StringPool.UTF8);
133 }
134
135 }