001
014
015 package com.liferay.portlet.blogs.action;
016
017 import com.liferay.portal.kernel.dao.search.SearchContainer;
018 import com.liferay.portal.kernel.util.ContentTypes;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.workflow.WorkflowConstants;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.struts.PortletAction;
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.WebKeys;
028 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
029 import com.liferay.util.RSSUtil;
030
031 import java.io.OutputStream;
032
033 import javax.portlet.PortletConfig;
034 import javax.portlet.ResourceRequest;
035 import javax.portlet.ResourceResponse;
036
037 import org.apache.struts.action.ActionForm;
038 import org.apache.struts.action.ActionMapping;
039
040
043 public class RSSAction extends PortletAction {
044
045 public void serveResource(
046 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
047 ResourceRequest resourceRequest, ResourceResponse resourceResponse)
048 throws Exception {
049
050 resourceResponse.setContentType(ContentTypes.TEXT_XML_UTF8);
051
052 OutputStream outputStream = resourceResponse.getPortletOutputStream();
053
054 try {
055 outputStream.write(getRSS(resourceRequest));
056 }
057 finally {
058 outputStream.close();
059 }
060 }
061
062 protected byte[] getRSS(ResourceRequest resourceRequest) throws Exception {
063 ThemeDisplay themeDisplay = (ThemeDisplay)resourceRequest.getAttribute(
064 WebKeys.THEME_DISPLAY);
065
066 Layout layout = themeDisplay.getLayout();
067
068 long plid = ParamUtil.getLong(resourceRequest, "p_l_id");
069 long companyId = ParamUtil.getLong(resourceRequest, "companyId");
070 long groupId = ParamUtil.getLong(resourceRequest, "groupId");
071 long organizationId = ParamUtil.getLong(
072 resourceRequest, "organizationId");
073 int status = WorkflowConstants.STATUS_APPROVED;
074 int max = ParamUtil.getInteger(
075 resourceRequest, "max", SearchContainer.DEFAULT_DELTA);
076 String type = ParamUtil.getString(
077 resourceRequest, "type", RSSUtil.DEFAULT_TYPE);
078 double version = ParamUtil.getDouble(
079 resourceRequest, "version", RSSUtil.DEFAULT_VERSION);
080 String displayStyle = ParamUtil.getString(
081 resourceRequest, "displayStyle",
082 RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
083
084 String feedURL =
085 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
086 "/blogs/find_entry?";
087
088 String entryURL = feedURL;
089
090 String rss = StringPool.BLANK;
091
092 if (companyId > 0) {
093 feedURL = StringPool.BLANK;
094
095 rss = BlogsEntryServiceUtil.getCompanyEntriesRSS(
096 companyId, status, max, type, version, displayStyle, feedURL,
097 entryURL, themeDisplay);
098 }
099 else if (groupId > 0) {
100 feedURL += "p_l_id=" + plid;
101
102 entryURL = feedURL;
103
104 rss = BlogsEntryServiceUtil.getGroupEntriesRSS(
105 groupId, status, max, type, version, displayStyle, feedURL,
106 entryURL, themeDisplay);
107 }
108 else if (organizationId > 0) {
109 feedURL = StringPool.BLANK;
110
111 rss = BlogsEntryServiceUtil.getOrganizationEntriesRSS(
112 organizationId, status, max, type, version, displayStyle,
113 feedURL, entryURL, themeDisplay);
114 }
115 else if (layout != null) {
116 groupId = themeDisplay.getScopeGroupId();
117
118 feedURL =
119 PortalUtil.getLayoutFullURL(themeDisplay) +
120 Portal.FRIENDLY_URL_SEPARATOR + "blogs/rss";
121
122 entryURL = feedURL;
123
124 rss = BlogsEntryServiceUtil.getGroupEntriesRSS(
125 groupId, status, max, type, version, displayStyle, feedURL,
126 entryURL, themeDisplay);
127 }
128
129 return rss.getBytes(StringPool.UTF8);
130 }
131
132 protected boolean isCheckMethodOnProcessAction() {
133 return _CHECK_METHOD_ON_PROCESS_ACTION;
134 }
135
136 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
137
138 }