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