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