001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.action;
016    
017    import com.liferay.portal.kernel.dao.search.SearchContainer;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.workflow.WorkflowConstants;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.WebKeys;
023    import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
024    import com.liferay.util.RSSUtil;
025    
026    import javax.servlet.http.HttpServletRequest;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class RSSAction extends com.liferay.portal.struts.RSSAction {
032    
033            @Override
034            protected byte[] getRSS(HttpServletRequest request) throws Exception {
035                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
036                            WebKeys.THEME_DISPLAY);
037    
038                    String plid = ParamUtil.getString(request, "p_l_id");
039                    long companyId = ParamUtil.getLong(request, "companyId");
040                    long groupId = ParamUtil.getLong(request, "groupId");
041                    long userId = ParamUtil.getLong(request, "userId");
042                    long categoryId = ParamUtil.getLong(request, "mbCategoryId");
043                    long threadId = ParamUtil.getLong(request, "threadId");
044                    int max = ParamUtil.getInteger(
045                            request, "max", SearchContainer.DEFAULT_DELTA);
046                    String type = ParamUtil.getString(
047                            request, "type", RSSUtil.FORMAT_DEFAULT);
048                    double version = ParamUtil.getDouble(
049                            request, "version", RSSUtil.VERSION_DEFAULT);
050                    String displayStyle = ParamUtil.getString(
051                            request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);
052    
053                    String entryURL =
054                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
055                                    "/message_boards/find_message?p_l_id=" + plid;
056    
057                    String rss = StringPool.BLANK;
058    
059                    if (companyId > 0) {
060                            String feedURL = StringPool.BLANK;
061    
062                            rss = MBMessageServiceUtil.getCompanyMessagesRSS(
063                                    companyId, WorkflowConstants.STATUS_APPROVED, max, type,
064                                    version, displayStyle, feedURL, entryURL, themeDisplay);
065                    }
066                    else if (groupId > 0) {
067                            String topLink = ParamUtil.getString(request, "topLink");
068    
069                            String feedURL = null;
070    
071                            if (topLink.equals("recent-posts")) {
072                                    feedURL =
073                                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
074                                                    "/message_boards/find_recent_posts?p_l_id=" + plid;
075                            }
076                            else {
077                                    feedURL =
078                                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
079                                                    "/message_boards/find_category?p_l_id=" + plid +
080                                                            "&mbCategoryId=" + categoryId;
081                            }
082    
083                            if (userId > 0) {
084                                    rss = MBMessageServiceUtil.getGroupMessagesRSS(
085                                            groupId, userId, WorkflowConstants.STATUS_APPROVED, max,
086                                            type, version, displayStyle, feedURL, entryURL,
087                                            themeDisplay);
088                            }
089                            else {
090                                    rss = MBMessageServiceUtil.getGroupMessagesRSS(
091                                            groupId, WorkflowConstants.STATUS_APPROVED, max, type,
092                                            version, displayStyle, feedURL, entryURL, themeDisplay);
093                            }
094                    }
095                    else if (categoryId > 0) {
096                            String feedURL =
097                                    themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
098                                            "/message_boards/find_category?p_l_id=" + plid +
099                                                    "&mbCategoryId=" + categoryId;
100    
101                            rss = MBMessageServiceUtil.getCategoryMessagesRSS(
102                                    groupId, categoryId, WorkflowConstants.STATUS_APPROVED, max,
103                                    type, version, displayStyle, feedURL, entryURL, themeDisplay);
104                    }
105                    else if (threadId > 0) {
106                            String feedURL =
107                                    themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
108                                            "/message_boards/find_thread?p_l_id=" + plid +
109                                                    "&threadId=" + threadId;
110    
111                            rss = MBMessageServiceUtil.getThreadMessagesRSS(
112                                    threadId, WorkflowConstants.STATUS_APPROVED, max, type, version,
113                                    displayStyle, feedURL, entryURL, themeDisplay);
114                    }
115    
116                    return rss.getBytes(StringPool.UTF8);
117            }
118    
119    }