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