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