001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.messageboards.action;
022:
023: import com.liferay.portal.kernel.dao.search.SearchContainer;
024: import com.liferay.portal.kernel.util.ContentTypes;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.struts.ActionConstants;
028: import com.liferay.portal.theme.ThemeDisplay;
029: import com.liferay.portal.util.WebKeys;
030: import com.liferay.portlet.messageboards.NoSuchCategoryException;
031: import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
032: import com.liferay.util.RSSUtil;
033: import com.liferay.util.servlet.ServletResponseUtil;
034:
035: import javax.servlet.http.HttpServletRequest;
036: import javax.servlet.http.HttpServletResponse;
037: import javax.servlet.jsp.PageContext;
038:
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041: import org.apache.struts.action.Action;
042: import org.apache.struts.action.ActionForm;
043: import org.apache.struts.action.ActionForward;
044: import org.apache.struts.action.ActionMapping;
045:
046: /**
047: * <a href="RSSAction.java.html"><b><i>View Source</i></b></a>
048: *
049: * @author Brian Wing Shun Chan
050: *
051: */
052: public class RSSAction extends Action {
053:
054: public ActionForward execute(ActionMapping mapping,
055: ActionForm form, HttpServletRequest req,
056: HttpServletResponse res) throws Exception {
057:
058: try {
059: ServletResponseUtil.sendFile(res, null, getRSS(req),
060: ContentTypes.TEXT_XML_UTF8);
061:
062: return null;
063: } catch (Exception e) {
064: req.setAttribute(PageContext.EXCEPTION, e);
065:
066: return mapping.findForward(ActionConstants.COMMON_ERROR);
067: }
068: }
069:
070: protected byte[] getRSS(HttpServletRequest req) throws Exception {
071: ThemeDisplay themeDisplay = (ThemeDisplay) req
072: .getAttribute(WebKeys.THEME_DISPLAY);
073:
074: String plid = ParamUtil.getString(req, "p_l_id");
075: long companyId = ParamUtil.getLong(req, "companyId");
076: long groupId = ParamUtil.getLong(req, "groupId");
077: long userId = ParamUtil.getLong(req, "userId");
078: long categoryId = ParamUtil.getLong(req, "categoryId");
079: long threadId = ParamUtil.getLong(req, "threadId");
080: int max = ParamUtil.getInteger(req, "max",
081: SearchContainer.DEFAULT_DELTA);
082: String type = ParamUtil.getString(req, "type",
083: RSSUtil.DEFAULT_TYPE);
084: double version = ParamUtil.getDouble(req, "version",
085: RSSUtil.DEFAULT_VERSION);
086: String displayStyle = ParamUtil.getString(req, "displayStyle",
087: RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
088:
089: String entryURL = themeDisplay.getURLPortal()
090: + themeDisplay.getPathMain()
091: + "/message_boards/find_message?p_l_id=" + plid;
092:
093: String rss = StringPool.BLANK;
094:
095: if (companyId > 0) {
096: String feedURL = StringPool.BLANK;
097:
098: rss = MBMessageServiceUtil
099: .getCompanyMessagesRSS(companyId, max, type,
100: version, displayStyle, feedURL, entryURL);
101: } else if (groupId > 0) {
102: String feedURL = themeDisplay.getURLPortal()
103: + themeDisplay.getPathMain()
104: + "/message_boards/find_recent_posts?p_l_id="
105: + plid;
106:
107: if (userId > 0) {
108: rss = MBMessageServiceUtil.getGroupMessagesRSS(groupId,
109: userId, max, type, version, displayStyle,
110: feedURL, entryURL);
111: } else {
112: rss = MBMessageServiceUtil.getGroupMessagesRSS(groupId,
113: max, type, version, displayStyle, feedURL,
114: entryURL);
115: }
116: } else if (categoryId > 0) {
117: String feedURL = themeDisplay.getURLPortal()
118: + themeDisplay.getPathMain()
119: + "/message_boards/find_category?p_l_id=" + plid
120: + "&categoryId=" + categoryId;
121:
122: try {
123: rss = MBMessageServiceUtil.getCategoryMessagesRSS(
124: categoryId, max, type, version, displayStyle,
125: feedURL, entryURL);
126: } catch (NoSuchCategoryException nsce) {
127: if (_log.isWarnEnabled()) {
128: _log.warn(nsce);
129: }
130: }
131: } else if (threadId > 0) {
132: String feedURL = themeDisplay.getURLPortal()
133: + themeDisplay.getPathMain()
134: + "/message_boards/find_thread?p_l_id=" + plid
135: + "&threadId=" + threadId;
136:
137: rss = MBMessageServiceUtil
138: .getThreadMessagesRSS(threadId, max, type, version,
139: displayStyle, feedURL, entryURL);
140: }
141:
142: return rss.getBytes(StringPool.UTF8);
143: }
144:
145: private static Log _log = LogFactory.getLog(RSSAction.class);
146:
147: }
|