1
19
20 package com.liferay.portlet.wiki.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.kernel.util.Validator;
27 import com.liferay.portal.model.Layout;
28 import com.liferay.portal.struts.ActionConstants;
29 import com.liferay.portal.struts.PortletAction;
30 import com.liferay.portal.theme.ThemeDisplay;
31 import com.liferay.portal.util.PortalUtil;
32 import com.liferay.portal.util.PortletKeys;
33 import com.liferay.portal.util.WebKeys;
34 import com.liferay.portlet.PortletURLImpl;
35 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
36 import com.liferay.util.RSSUtil;
37 import com.liferay.util.servlet.ServletResponseUtil;
38
39 import java.util.Locale;
40
41 import javax.portlet.ActionRequest;
42 import javax.portlet.ActionResponse;
43 import javax.portlet.PortletConfig;
44 import javax.portlet.PortletRequest;
45 import javax.portlet.PortletURL;
46
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49
50 import org.apache.struts.action.ActionForm;
51 import org.apache.struts.action.ActionForward;
52 import org.apache.struts.action.ActionMapping;
53
54
60 public class RSSAction extends PortletAction {
61
62 public ActionForward strutsExecute(
63 ActionMapping mapping, ActionForm form, HttpServletRequest request,
64 HttpServletResponse response)
65 throws Exception {
66
67 try {
68 ServletResponseUtil.sendFile(
69 response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8);
70
71 return null;
72 }
73 catch (Exception e) {
74 PortalUtil.sendError(e, request, response);
75
76 return null;
77 }
78 }
79
80 public void processAction(
81 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
82 ActionRequest actionRequest, ActionResponse actionResponse)
83 throws Exception {
84
85 try {
86 HttpServletRequest request = PortalUtil.getHttpServletRequest(
87 actionRequest);
88 HttpServletResponse response = PortalUtil.getHttpServletResponse(
89 actionResponse);
90
91 ServletResponseUtil.sendFile(
92 response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8);
93
94 setForward(actionRequest, ActionConstants.COMMON_NULL);
95 }
96 catch (Exception e) {
97 PortalUtil.sendError(e, actionRequest, actionResponse);
98 }
99 }
100
101 protected byte[] getRSS(HttpServletRequest request) throws Exception {
102 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
103 WebKeys.THEME_DISPLAY);
104
105 Layout layout = themeDisplay.getLayout();
106
107 long companyId = ParamUtil.getLong(request, "companyId");
108 long nodeId = ParamUtil.getLong(request, "nodeId");
109 String title = ParamUtil.getString(request, "title");
110 int max = ParamUtil.getInteger(
111 request, "max", SearchContainer.DEFAULT_DELTA);
112 String type = ParamUtil.getString(
113 request, "type", RSSUtil.DEFAULT_TYPE);
114 double version = ParamUtil.getDouble(
115 request, "version", RSSUtil.DEFAULT_VERSION);
116 String displayStyle = ParamUtil.getString(
117 request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
118
119 PortletURL feedURL = new PortletURLImpl(
120 request, PortletKeys.WIKI, layout.getPlid(),
121 PortletRequest.RENDER_PHASE);
122
123 feedURL.setParameter("nodeId", String.valueOf(nodeId));
124
125 PortletURL entryURL = new PortletURLImpl(
126 request, PortletKeys.WIKI, layout.getPlid(),
127 PortletRequest.RENDER_PHASE);
128
129 entryURL.setParameter("nodeId", String.valueOf(nodeId));
130 entryURL.setParameter("title", title);
131
132 Locale locale = themeDisplay.getLocale();
133
134 String rss = StringPool.BLANK;
135
136 if ((nodeId > 0) && (Validator.isNotNull(title))) {
137 rss = WikiPageServiceUtil.getPagesRSS(
138 companyId, nodeId, title, max, type, version, displayStyle,
139 feedURL.toString(), entryURL.toString(), locale);
140 }
141 else if (nodeId > 0) {
142 rss = WikiPageServiceUtil.getNodePagesRSS(
143 nodeId, max, type, version, displayStyle, feedURL.toString(),
144 entryURL.toString());
145 }
146
147 return rss.getBytes(StringPool.UTF8);
148 }
149
150 protected boolean isCheckMethodOnProcessAction() {
151 return _CHECK_METHOD_ON_PROCESS_ACTION;
152 }
153
154 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
155
156 }