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.wiki.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.util.Validator;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortletKeys;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.PortletURLImpl;
026    import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
027    import com.liferay.util.RSSUtil;
028    
029    import java.util.Locale;
030    
031    import javax.portlet.PortletRequest;
032    import javax.portlet.PortletURL;
033    
034    import javax.servlet.http.HttpServletRequest;
035    
036    /**
037     * @author Jorge Ferrer
038     */
039    public class RSSAction extends com.liferay.portal.struts.RSSAction {
040    
041            @Override
042            protected byte[] getRSS(HttpServletRequest request) throws Exception {
043                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
044                            WebKeys.THEME_DISPLAY);
045    
046                    Layout layout = themeDisplay.getLayout();
047    
048                    long companyId = ParamUtil.getLong(request, "companyId");
049                    long nodeId = ParamUtil.getLong(request, "nodeId");
050                    String title = ParamUtil.getString(request, "title");
051                    int max = ParamUtil.getInteger(
052                            request, "max", SearchContainer.DEFAULT_DELTA);
053                    String type = ParamUtil.getString(
054                            request, "type", RSSUtil.TYPE_DEFAULT);
055                    double version = ParamUtil.getDouble(
056                            request, "version", RSSUtil.VERSION_DEFAULT);
057                    String displayStyle = ParamUtil.getString(
058                            request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
059    
060                    PortletURL feedURL = new PortletURLImpl(
061                            request, PortletKeys.WIKI, layout.getPlid(),
062                            PortletRequest.RENDER_PHASE);
063    
064                    feedURL.setParameter("nodeId", String.valueOf(nodeId));
065    
066                    PortletURL entryURL = new PortletURLImpl(
067                            request, PortletKeys.WIKI, layout.getPlid(),
068                            PortletRequest.RENDER_PHASE);
069    
070                    entryURL.setParameter("nodeId", String.valueOf(nodeId));
071                    entryURL.setParameter("title", title);
072    
073                    Locale locale = themeDisplay.getLocale();
074    
075                    String rss = StringPool.BLANK;
076    
077                    if ((nodeId > 0) && Validator.isNotNull(title)) {
078                            rss = WikiPageServiceUtil.getPagesRSS(
079                                    companyId, nodeId, title, max, type, version, displayStyle,
080                                    feedURL.toString(), entryURL.toString(), locale);
081                    }
082                    else if (nodeId > 0) {
083                            rss = WikiPageServiceUtil.getNodePagesRSS(
084                                    nodeId, max, type, version, displayStyle, feedURL.toString(),
085                                    entryURL.toString());
086                    }
087    
088                    return rss.getBytes(StringPool.UTF8);
089            }
090    
091    }