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