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