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