001
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.GetterUtil;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.util.StringBundler;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
024 import com.liferay.portal.theme.ThemeDisplay;
025 import com.liferay.portal.util.Portal;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portal.util.PortletKeys;
028 import com.liferay.portal.util.WebKeys;
029 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
030 import com.liferay.portlet.wiki.util.WikiUtil;
031 import com.liferay.util.RSSUtil;
032
033 import java.util.Locale;
034
035 import javax.portlet.PortletPreferences;
036
037 import javax.servlet.http.HttpServletRequest;
038
039
042 public class RSSAction extends com.liferay.portal.struts.RSSAction {
043
044 @Override
045 protected byte[] getRSS(HttpServletRequest request) throws Exception {
046 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
047 WebKeys.THEME_DISPLAY);
048
049 long companyId = ParamUtil.getLong(request, "companyId");
050 long nodeId = ParamUtil.getLong(request, "nodeId");
051 String title = ParamUtil.getString(request, "title");
052 int max = ParamUtil.getInteger(
053 request, "max", SearchContainer.DEFAULT_DELTA);
054 String type = ParamUtil.getString(
055 request, "type", RSSUtil.FORMAT_DEFAULT);
056 double version = ParamUtil.getDouble(
057 request, "version", RSSUtil.VERSION_DEFAULT);
058 String displayStyle = ParamUtil.getString(
059 request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);
060
061 String layoutFullURL = PortalUtil.getLayoutFullURL(
062 themeDisplay.getScopeGroupId(), PortletKeys.WIKI);
063
064 StringBundler sb = new StringBundler(4);
065
066 sb.append(layoutFullURL);
067 sb.append(Portal.FRIENDLY_URL_SEPARATOR);
068 sb.append("wiki/");
069 sb.append(nodeId);
070
071 String feedURL = sb.toString();
072
073 String entryURL = feedURL + StringPool.SLASH + title;
074
075 Locale locale = themeDisplay.getLocale();
076
077 String rss = StringPool.BLANK;
078
079 if (nodeId > 0) {
080 String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(
081 themeDisplay.getPathMain(), themeDisplay.getPlid(), nodeId,
082 title);
083
084 if (Validator.isNotNull(title)) {
085 rss = WikiPageServiceUtil.getPagesRSS(
086 companyId, nodeId, title, max, type, version, displayStyle,
087 feedURL, entryURL, attachmentURLPrefix, locale);
088 }
089 else {
090 rss = WikiPageServiceUtil.getNodePagesRSS(
091 nodeId, max, type, version, displayStyle, feedURL, entryURL,
092 attachmentURLPrefix);
093 }
094 }
095
096 return rss.getBytes(StringPool.UTF8);
097 }
098
099 protected boolean isRSSFeedsEnabled(HttpServletRequest request)
100 throws Exception {
101
102 if (!super.isRSSFeedsEnabled(request)) {
103 return false;
104 }
105
106 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
107 WebKeys.THEME_DISPLAY);
108
109 PortletPreferences portletPreferences =
110 PortletPreferencesLocalServiceUtil.getPreferences(
111 themeDisplay.getCompanyId(), PortletKeys.PREFS_OWNER_ID_DEFAULT,
112 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, themeDisplay.getPlid(),
113 PortletKeys.WIKI, null);
114
115 if (portletPreferences != null) {
116 return GetterUtil.getBoolean(
117 portletPreferences.getValue("enableRss", null), true);
118 }
119
120 return true;
121 }
122
123 }