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