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.blogs.action;
022:
023: import com.liferay.portal.NoSuchCompanyException;
024: import com.liferay.portal.NoSuchGroupException;
025: import com.liferay.portal.NoSuchOrganizationException;
026: import com.liferay.portal.kernel.dao.search.SearchContainer;
027: import com.liferay.portal.kernel.util.ContentTypes;
028: import com.liferay.portal.kernel.util.ParamUtil;
029: import com.liferay.portal.kernel.util.StringPool;
030: import com.liferay.portal.model.Layout;
031: import com.liferay.portal.struts.ActionConstants;
032: import com.liferay.portal.struts.PortletAction;
033: import com.liferay.portal.theme.ThemeDisplay;
034: import com.liferay.portal.util.PortalUtil;
035: import com.liferay.portal.util.WebKeys;
036: import com.liferay.portlet.ActionRequestImpl;
037: import com.liferay.portlet.ActionResponseImpl;
038: import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
039: import com.liferay.util.RSSUtil;
040: import com.liferay.util.servlet.ServletResponseUtil;
041:
042: import javax.portlet.ActionRequest;
043: import javax.portlet.ActionResponse;
044: import javax.portlet.PortletConfig;
045:
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048: import javax.servlet.jsp.PageContext;
049:
050: import org.apache.commons.logging.Log;
051: import org.apache.commons.logging.LogFactory;
052: import org.apache.struts.action.ActionForm;
053: import org.apache.struts.action.ActionForward;
054: import org.apache.struts.action.ActionMapping;
055:
056: /**
057: * <a href="RSSAction.java.html"><b><i>View Source</i></b></a>
058: *
059: * @author Brian Wing Shun Chan
060: *
061: */
062: public class RSSAction extends PortletAction {
063:
064: public ActionForward strutsExecute(ActionMapping mapping,
065: ActionForm form, HttpServletRequest req,
066: HttpServletResponse res) throws Exception {
067:
068: try {
069: ServletResponseUtil.sendFile(res, null, getRSS(req),
070: ContentTypes.TEXT_XML_UTF8);
071:
072: return null;
073: } catch (Exception e) {
074: req.setAttribute(PageContext.EXCEPTION, e);
075:
076: return mapping.findForward(ActionConstants.COMMON_ERROR);
077: }
078: }
079:
080: public void processAction(ActionMapping mapping, ActionForm form,
081: PortletConfig config, ActionRequest req, ActionResponse res)
082: throws Exception {
083:
084: HttpServletRequest httpReq = ((ActionRequestImpl) req)
085: .getHttpServletRequest();
086: HttpServletResponse httpRes = ((ActionResponseImpl) res)
087: .getHttpServletResponse();
088:
089: ServletResponseUtil.sendFile(httpRes, null, getRSS(httpReq),
090: ContentTypes.TEXT_XML_UTF8);
091:
092: setForward(req, ActionConstants.COMMON_NULL);
093: }
094:
095: protected byte[] getRSS(HttpServletRequest req) throws Exception {
096: ThemeDisplay themeDisplay = (ThemeDisplay) req
097: .getAttribute(WebKeys.THEME_DISPLAY);
098:
099: Layout layout = themeDisplay.getLayout();
100:
101: long plid = ParamUtil.getLong(req, "p_l_id");
102: long companyId = ParamUtil.getLong(req, "companyId");
103: long groupId = ParamUtil.getLong(req, "groupId");
104: long organizationId = ParamUtil.getLong(req, "organizationId");
105: int max = ParamUtil.getInteger(req, "max",
106: SearchContainer.DEFAULT_DELTA);
107: String type = ParamUtil.getString(req, "type",
108: RSSUtil.DEFAULT_TYPE);
109: double version = ParamUtil.getDouble(req, "version",
110: RSSUtil.DEFAULT_VERSION);
111: String displayStyle = ParamUtil.getString(req, "displayStyle",
112: RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
113:
114: String feedURL = themeDisplay.getURLPortal()
115: + themeDisplay.getPathMain() + "/blogs/find_entry?";
116:
117: String entryURL = feedURL;
118:
119: String rss = StringPool.BLANK;
120:
121: if (companyId > 0) {
122: feedURL = StringPool.BLANK;
123:
124: try {
125: rss = BlogsEntryServiceUtil.getCompanyEntriesRSS(
126: companyId, max, type, version, displayStyle,
127: feedURL, entryURL);
128: } catch (NoSuchCompanyException nsce) {
129: if (_log.isWarnEnabled()) {
130: _log.warn(nsce);
131: }
132: }
133: } else if (groupId > 0) {
134: feedURL += "p_l_id=" + plid;
135:
136: entryURL = feedURL;
137:
138: try {
139: rss = BlogsEntryServiceUtil.getGroupEntriesRSS(groupId,
140: max, type, version, displayStyle, feedURL,
141: entryURL);
142: } catch (NoSuchGroupException nsge) {
143: if (_log.isWarnEnabled()) {
144: _log.warn(nsge);
145: }
146: }
147: } else if (organizationId > 0) {
148: feedURL = StringPool.BLANK;
149:
150: try {
151: rss = BlogsEntryServiceUtil.getOrganizationEntriesRSS(
152: organizationId, max, type, version,
153: displayStyle, feedURL, entryURL);
154: } catch (NoSuchOrganizationException nsge) {
155: if (_log.isWarnEnabled()) {
156: _log.warn(nsge);
157: }
158: }
159: } else if (layout != null) {
160: groupId = layout.getGroupId();
161:
162: feedURL = themeDisplay.getURLPortal()
163: + PortalUtil.getLayoutURL(themeDisplay)
164: + "/blogs/rss";
165:
166: entryURL = feedURL;
167:
168: try {
169: rss = BlogsEntryServiceUtil.getGroupEntriesRSS(groupId,
170: max, type, version, displayStyle, feedURL,
171: entryURL);
172: } catch (NoSuchGroupException nsge) {
173: if (_log.isWarnEnabled()) {
174: _log.warn(nsge);
175: }
176: }
177: }
178:
179: return rss.getBytes(StringPool.UTF8);
180: }
181:
182: protected boolean isCheckMethodOnProcessAction() {
183: return _CHECK_METHOD_ON_PROCESS_ACTION;
184: }
185:
186: private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
187:
188: private static Log _log = LogFactory.getLog(RSSAction.class);
189:
190: }
|