1
14
15 package com.liferay.portlet.wiki.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.kernel.util.Validator;
22 import com.liferay.portal.model.Layout;
23 import com.liferay.portal.struts.ActionConstants;
24 import com.liferay.portal.struts.PortletAction;
25 import com.liferay.portal.theme.ThemeDisplay;
26 import com.liferay.portal.util.PortalUtil;
27 import com.liferay.portal.util.PortletKeys;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.PortletURLImpl;
30 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
31 import com.liferay.util.RSSUtil;
32 import com.liferay.util.servlet.ServletResponseUtil;
33
34 import java.util.Locale;
35
36 import javax.portlet.ActionRequest;
37 import javax.portlet.ActionResponse;
38 import javax.portlet.PortletConfig;
39 import javax.portlet.PortletRequest;
40 import javax.portlet.PortletURL;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
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 companyId = ParamUtil.getLong(request, "companyId");
102 long nodeId = ParamUtil.getLong(request, "nodeId");
103 String title = ParamUtil.getString(request, "title");
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 PortletURL feedURL = new PortletURLImpl(
114 request, PortletKeys.WIKI, layout.getPlid(),
115 PortletRequest.RENDER_PHASE);
116
117 feedURL.setParameter("nodeId", String.valueOf(nodeId));
118
119 PortletURL entryURL = new PortletURLImpl(
120 request, PortletKeys.WIKI, layout.getPlid(),
121 PortletRequest.RENDER_PHASE);
122
123 entryURL.setParameter("nodeId", String.valueOf(nodeId));
124 entryURL.setParameter("title", title);
125
126 Locale locale = themeDisplay.getLocale();
127
128 String rss = StringPool.BLANK;
129
130 if ((nodeId > 0) && (Validator.isNotNull(title))) {
131 rss = WikiPageServiceUtil.getPagesRSS(
132 companyId, nodeId, title, max, type, version, displayStyle,
133 feedURL.toString(), entryURL.toString(), locale);
134 }
135 else if (nodeId > 0) {
136 rss = WikiPageServiceUtil.getNodePagesRSS(
137 nodeId, max, type, version, displayStyle, feedURL.toString(),
138 entryURL.toString());
139 }
140
141 return rss.getBytes(StringPool.UTF8);
142 }
143
144 protected boolean isCheckMethodOnProcessAction() {
145 return _CHECK_METHOD_ON_PROCESS_ACTION;
146 }
147
148 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
149
150 }