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.struts.ActionConstants;
30 import com.liferay.portal.theme.ThemeDisplay;
31 import com.liferay.portal.util.WebKeys;
32 import com.liferay.portlet.messageboards.NoSuchCategoryException;
33 import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
34 import com.liferay.util.RSSUtil;
35 import com.liferay.util.servlet.ServletResponseUtil;
36
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpServletResponse;
39 import javax.servlet.jsp.PageContext;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43 import org.apache.struts.action.Action;
44 import org.apache.struts.action.ActionForm;
45 import org.apache.struts.action.ActionForward;
46 import org.apache.struts.action.ActionMapping;
47
48
54 public class RSSAction extends Action {
55
56 public ActionForward execute(
57 ActionMapping mapping, ActionForm form, HttpServletRequest req,
58 HttpServletResponse res)
59 throws Exception {
60
61 try {
62 ServletResponseUtil.sendFile(
63 res, null, getRSS(req), ContentTypes.TEXT_XML_UTF8);
64
65 return null;
66 }
67 catch (Exception e) {
68 req.setAttribute(PageContext.EXCEPTION, e);
69
70 return mapping.findForward(ActionConstants.COMMON_ERROR);
71 }
72 }
73
74 protected byte[] getRSS(HttpServletRequest req) throws Exception {
75 ThemeDisplay themeDisplay =
76 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
77
78 String plid = ParamUtil.getString(req, "p_l_id");
79 long companyId = ParamUtil.getLong(req, "companyId");
80 long groupId = ParamUtil.getLong(req, "groupId");
81 long userId = ParamUtil.getLong(req, "userId");
82 long categoryId = ParamUtil.getLong(req, "categoryId");
83 long threadId = ParamUtil.getLong(req, "threadId");
84 int max = ParamUtil.getInteger(
85 req, "max", SearchContainer.DEFAULT_DELTA);
86 String type = ParamUtil.getString(req, "type", RSSUtil.DEFAULT_TYPE);
87 double version = ParamUtil.getDouble(
88 req, "version", RSSUtil.DEFAULT_VERSION);
89 String displayStyle = ParamUtil.getString(
90 req, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
91
92 String entryURL =
93 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
94 "/message_boards/find_message?p_l_id=" + plid;
95
96 String rss = StringPool.BLANK;
97
98 if (companyId > 0) {
99 String feedURL = StringPool.BLANK;
100
101 rss = MBMessageServiceUtil.getCompanyMessagesRSS(
102 companyId, max, type, version, displayStyle, feedURL, entryURL);
103 }
104 else if (groupId > 0) {
105 String feedURL =
106 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
107 "/message_boards/find_recent_posts?p_l_id=" + plid;
108
109 if (userId > 0) {
110 rss = MBMessageServiceUtil.getGroupMessagesRSS(
111 groupId, userId, max, type, version, displayStyle, feedURL,
112 entryURL);
113 }
114 else {
115 rss = MBMessageServiceUtil.getGroupMessagesRSS(
116 groupId, max, type, version, displayStyle, feedURL,
117 entryURL);
118 }
119 }
120 else if (categoryId > 0) {
121 String feedURL =
122 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
123 "/message_boards/find_category?p_l_id=" + plid +
124 "&categoryId=" + categoryId;
125
126 try {
127 rss = MBMessageServiceUtil.getCategoryMessagesRSS(
128 categoryId, max, type, version, displayStyle, feedURL,
129 entryURL);
130 }
131 catch (NoSuchCategoryException nsce) {
132 if (_log.isWarnEnabled()) {
133 _log.warn(nsce);
134 }
135 }
136 }
137 else if (threadId > 0) {
138 String feedURL =
139 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
140 "/message_boards/find_thread?p_l_id=" + plid +
141 "&threadId=" + threadId;
142
143 rss = MBMessageServiceUtil.getThreadMessagesRSS(
144 threadId, max, type, version, displayStyle, feedURL, entryURL);
145 }
146
147 return rss.getBytes(StringPool.UTF8);
148 }
149
150 private static Log _log = LogFactory.getLog(RSSAction.class);
151
152 }