/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.wiki.web.internal.portlet.action;
import com.liferay.portal.kernel.dao.search.SearchContainer;
import com.liferay.portal.kernel.struts.StrutsAction;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.RSSUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.struts.BaseRSSStrutsAction;
import com.liferay.wiki.configuration.WikiGroupServiceOverriddenConfiguration;
import com.liferay.wiki.constants.WikiPortletKeys;
import com.liferay.wiki.service.WikiPageService;
import com.liferay.wiki.util.WikiUtil;
import com.liferay.wiki.web.internal.display.context.util.WikiRequestHelper;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Jorge Ferrer
*/
@Component(property = "path=/wiki/rss", service = StrutsAction.class)
public class RSSAction extends BaseRSSStrutsAction {
@Override
protected byte[] getRSS(HttpServletRequest request) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
long nodeId = ParamUtil.getLong(request, "nodeId");
String title = ParamUtil.getString(request, "title");
int max = ParamUtil.getInteger(
request, "max", SearchContainer.DEFAULT_DELTA);
String type = ParamUtil.getString(
request, "type", RSSUtil.FORMAT_DEFAULT);
double version = ParamUtil.getDouble(
request, "version", RSSUtil.VERSION_DEFAULT);
String displayStyle = ParamUtil.getString(
request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);
String layoutFullURL = _portal.getLayoutFullURL(
themeDisplay.getScopeGroupId(), WikiPortletKeys.WIKI);
StringBundler sb = new StringBundler(4);
sb.append(layoutFullURL);
sb.append(Portal.FRIENDLY_URL_SEPARATOR);
sb.append("wiki/");
sb.append(nodeId);
String feedURL = sb.toString();
String entryURL = feedURL + StringPool.SLASH + title;
Locale locale = themeDisplay.getLocale();
String rss = StringPool.BLANK;
if (nodeId > 0) {
String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(
themeDisplay.getPathMain(), themeDisplay.getPlid(), nodeId,
title);
if (Validator.isNotNull(title)) {
rss = _wikiPageService.getPagesRSS(
nodeId, title, max, type, version, displayStyle, feedURL,
entryURL, attachmentURLPrefix, locale);
}
else {
rss = _wikiPageService.getNodePagesRSS(
nodeId, max, type, version, displayStyle, feedURL, entryURL,
attachmentURLPrefix);
}
}
return rss.getBytes(StringPool.UTF8);
}
@Override
protected boolean isRSSFeedsEnabled(HttpServletRequest request)
throws Exception {
WikiRequestHelper wikiRequestHelper = new WikiRequestHelper(request);
WikiGroupServiceOverriddenConfiguration
wikiGroupServiceOverriddenConfiguration =
wikiRequestHelper.getWikiGroupServiceOverriddenConfiguration();
return wikiGroupServiceOverriddenConfiguration.enableRss();
}
@Reference(unbind = "-")
protected void setWikiPageService(WikiPageService wikiPageService) {
_wikiPageService = wikiPageService;
}
@Reference
private Portal _portal;
private WikiPageService _wikiPageService;
}