1
22
23 package com.liferay.portlet.blogs.action;
24
25 import com.liferay.portal.kernel.dao.search.SearchContainer;
26 import com.liferay.portal.kernel.util.ContentTypes;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.StringPool;
29 import com.liferay.portal.model.Layout;
30 import com.liferay.portal.struts.ActionConstants;
31 import com.liferay.portal.struts.PortletAction;
32 import com.liferay.portal.theme.ThemeDisplay;
33 import com.liferay.portal.util.PortalUtil;
34 import com.liferay.portal.util.WebKeys;
35 import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
36 import com.liferay.util.RSSUtil;
37 import com.liferay.util.servlet.ServletResponseUtil;
38
39 import javax.portlet.ActionRequest;
40 import javax.portlet.ActionResponse;
41 import javax.portlet.PortletConfig;
42
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
45
46 import org.apache.struts.action.ActionForm;
47 import org.apache.struts.action.ActionForward;
48 import org.apache.struts.action.ActionMapping;
49
50
56 public class RSSAction extends PortletAction {
57
58 public ActionForward strutsExecute(
59 ActionMapping mapping, ActionForm form, HttpServletRequest request,
60 HttpServletResponse response)
61 throws Exception {
62
63 try {
64 ServletResponseUtil.sendFile(
65 response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8);
66
67 return null;
68 }
69 catch (Exception e) {
70 PortalUtil.sendError(e, request, response);
71
72 return null;
73 }
74 }
75
76 public void processAction(
77 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
78 ActionRequest actionRequest, ActionResponse actionResponse)
79 throws Exception {
80
81 try {
82 HttpServletRequest request = PortalUtil.getHttpServletRequest(
83 actionRequest);
84 HttpServletResponse response = PortalUtil.getHttpServletResponse(
85 actionResponse);
86
87 ServletResponseUtil.sendFile(
88 response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8);
89
90 setForward(actionRequest, ActionConstants.COMMON_NULL);
91 }
92 catch (Exception e) {
93 PortalUtil.sendError(e, actionRequest, actionResponse);
94 }
95 }
96
97 protected byte[] getRSS(HttpServletRequest request) throws Exception {
98 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
99 WebKeys.THEME_DISPLAY);
100
101 Layout layout = themeDisplay.getLayout();
102
103 long plid = ParamUtil.getLong(request, "p_l_id");
104 long companyId = ParamUtil.getLong(request, "companyId");
105 long groupId = ParamUtil.getLong(request, "groupId");
106 long organizationId = ParamUtil.getLong(request, "organizationId");
107 int max = ParamUtil.getInteger(
108 request, "max", SearchContainer.DEFAULT_DELTA);
109 String type = ParamUtil.getString(
110 request, "type", RSSUtil.DEFAULT_TYPE);
111 double version = ParamUtil.getDouble(
112 request, "version", RSSUtil.DEFAULT_VERSION);
113 String displayStyle = ParamUtil.getString(
114 request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
115
116 String feedURL =
117 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
118 "/blogs/find_entry?";
119
120 String entryURL = feedURL;
121
122 String rss = StringPool.BLANK;
123
124 if (companyId > 0) {
125 feedURL = StringPool.BLANK;
126
127 rss = BlogsEntryServiceUtil.getCompanyEntriesRSS(
128 companyId, max, type, version, displayStyle, feedURL, entryURL,
129 themeDisplay);
130 }
131 else if (groupId > 0) {
132 feedURL += "p_l_id=" + plid;
133
134 entryURL = feedURL;
135
136 rss = BlogsEntryServiceUtil.getGroupEntriesRSS(
137 groupId, max, type, version, displayStyle, feedURL, entryURL,
138 themeDisplay);
139 }
140 else if (organizationId > 0) {
141 feedURL = StringPool.BLANK;
142
143 rss = BlogsEntryServiceUtil.getOrganizationEntriesRSS(
144 organizationId, max, type, version, displayStyle, feedURL,
145 entryURL, themeDisplay);
146 }
147 else if (layout != null) {
148 groupId = layout.getGroupId();
149
150 feedURL =
151 themeDisplay.getURLPortal() +
152 PortalUtil.getLayoutURL(themeDisplay) + "/-/blogs/rss";
153
154 entryURL = feedURL;
155
156 rss = BlogsEntryServiceUtil.getGroupEntriesRSS(
157 groupId, max, type, version, displayStyle, feedURL, entryURL,
158 themeDisplay);
159 }
160
161 return rss.getBytes(StringPool.UTF8);
162 }
163
164 protected boolean isCheckMethodOnProcessAction() {
165 return _CHECK_METHOD_ON_PROCESS_ACTION;
166 }
167
168 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
169
170 }