1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
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  /**
37   * <a href="RSSAction.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
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                  request, response, null, getRSS(request),
51                  ContentTypes.TEXT_XML_UTF8);
52  
53              return null;
54          }
55          catch (Exception e) {
56              PortalUtil.sendError(e, request, response);
57  
58              return null;
59          }
60      }
61  
62      protected byte[] getRSS(HttpServletRequest request) throws Exception {
63          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
64              WebKeys.THEME_DISPLAY);
65  
66          String plid = ParamUtil.getString(request, "p_l_id");
67          long companyId = ParamUtil.getLong(request, "companyId");
68          long groupId = ParamUtil.getLong(request, "groupId");
69          long userId = ParamUtil.getLong(request, "userId");
70          long categoryId = ParamUtil.getLong(request, "categoryId");
71          long threadId = ParamUtil.getLong(request, "threadId");
72          int max = ParamUtil.getInteger(
73              request, "max", SearchContainer.DEFAULT_DELTA);
74          String type = ParamUtil.getString(
75              request, "type", RSSUtil.DEFAULT_TYPE);
76          double version = ParamUtil.getDouble(
77              request, "version", RSSUtil.DEFAULT_VERSION);
78          String displayStyle = ParamUtil.getString(
79              request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
80  
81          String entryURL =
82              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
83                  "/message_boards/find_message?p_l_id=" + plid;
84  
85          String rss = StringPool.BLANK;
86  
87          if (companyId > 0) {
88              String feedURL = StringPool.BLANK;
89  
90              rss = MBMessageServiceUtil.getCompanyMessagesRSS(
91                  companyId, max, type, version, displayStyle, feedURL, entryURL,
92                  themeDisplay);
93          }
94          else if (groupId > 0) {
95              String feedURL =
96                  themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
97                      "/message_boards/find_recent_posts?p_l_id=" + plid;
98  
99              if (userId > 0) {
100                 rss = MBMessageServiceUtil.getGroupMessagesRSS(
101                     groupId, userId, max, type, version, displayStyle, feedURL,
102                     entryURL, themeDisplay);
103             }
104             else {
105                 rss = MBMessageServiceUtil.getGroupMessagesRSS(
106                     groupId, max, type, version, displayStyle, feedURL,
107                     entryURL, themeDisplay);
108             }
109         }
110         else if (categoryId > 0) {
111             String feedURL =
112                 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
113                     "/message_boards/find_category?p_l_id=" + plid +
114                         "&categoryId=" + categoryId;
115 
116             rss = MBMessageServiceUtil.getCategoryMessagesRSS(
117                 categoryId, max, type, version, displayStyle, feedURL, entryURL,
118                 themeDisplay);
119         }
120         else if (threadId > 0) {
121             String feedURL =
122                 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
123                     "/message_boards/find_thread?p_l_id=" + plid +
124                         "&threadId=" + threadId;
125 
126             rss = MBMessageServiceUtil.getThreadMessagesRSS(
127                 threadId, max, type, version, displayStyle, feedURL, entryURL,
128                 themeDisplay);
129         }
130 
131         return rss.getBytes(StringPool.UTF8);
132     }
133 
134 }