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