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.ActionRequestImpl;
37 import com.liferay.portlet.ActionResponseImpl;
38 import com.liferay.portlet.wiki.NoSuchNodeException;
39 import com.liferay.portlet.wiki.NoSuchPageException;
40 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
41 import com.liferay.util.RSSUtil;
42 import com.liferay.util.servlet.ServletResponseUtil;
43
44 import java.util.Locale;
45
46 import javax.portlet.ActionRequest;
47 import javax.portlet.ActionResponse;
48 import javax.portlet.PortletConfig;
49
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.http.HttpServletResponse;
52 import javax.servlet.jsp.PageContext;
53
54 import org.apache.commons.logging.Log;
55 import org.apache.commons.logging.LogFactory;
56 import org.apache.struts.action.ActionForm;
57 import org.apache.struts.action.ActionForward;
58 import org.apache.struts.action.ActionMapping;
59
60
66 public class RSSAction extends PortletAction {
67
68 public ActionForward strutsExecute(
69 ActionMapping mapping, ActionForm form, HttpServletRequest req,
70 HttpServletResponse res)
71 throws Exception {
72
73 try {
74 ServletResponseUtil.sendFile(
75 res, null, getRSS(req), ContentTypes.TEXT_XML_UTF8);
76
77 return null;
78 }
79 catch (Exception e) {
80 req.setAttribute(PageContext.EXCEPTION, e);
81
82 return mapping.findForward(ActionConstants.COMMON_ERROR);
83 }
84 }
85
86 public void processAction(
87 ActionMapping mapping, ActionForm form, PortletConfig config,
88 ActionRequest req, ActionResponse res)
89 throws Exception {
90
91 HttpServletRequest httpReq =
92 ((ActionRequestImpl)req).getHttpServletRequest();
93 HttpServletResponse httpRes =
94 ((ActionResponseImpl)res).getHttpServletResponse();
95
96 ServletResponseUtil.sendFile(
97 httpRes, null, getRSS(httpReq), ContentTypes.TEXT_XML_UTF8);
98
99 setForward(req, ActionConstants.COMMON_NULL);
100 }
101
102 protected byte[] getRSS(HttpServletRequest req) throws Exception {
103 ThemeDisplay themeDisplay =
104 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
105
106 Layout layout = themeDisplay.getLayout();
107
108 long companyId = ParamUtil.getLong(req, "companyId");
109 long nodeId = ParamUtil.getLong(req, "nodeId");
110 String title = ParamUtil.getString(req, "title");
111 int max = ParamUtil.getInteger(
112 req, "max", SearchContainer.DEFAULT_DELTA);
113 String type = ParamUtil.getString(req, "type", RSSUtil.DEFAULT_TYPE);
114 double version = ParamUtil.getDouble(
115 req, "version", RSSUtil.DEFAULT_VERSION);
116 String displayStyle = ParamUtil.getString(
117 req, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
118
119 String feedURL =
120 themeDisplay.getURLPortal() +
121 PortalUtil.getLayoutURL(layout, themeDisplay) + "/wiki/" +
122 nodeId;
123
124 String entryURL = feedURL + StringPool.SLASH + title;
125
126 Locale locale = themeDisplay.getLocale();
127
128 String rss = StringPool.BLANK;
129
130 if ((nodeId > 0) && (Validator.isNotNull(title))) {
131 try {
132 rss = WikiPageServiceUtil.getPagesRSS(
133 companyId, nodeId, title, max, type, version, displayStyle,
134 feedURL, entryURL, locale);
135 }
136 catch (NoSuchPageException nspe) {
137 if (_log.isWarnEnabled()) {
138 _log.warn(nspe);
139 }
140 }
141 }
142 else if (nodeId > 0) {
143 try {
144 rss = WikiPageServiceUtil.getNodePagesRSS(
145 nodeId, max, type, version, displayStyle, feedURL,
146 entryURL);
147 }
148 catch (NoSuchNodeException nsne) {
149 if (_log.isWarnEnabled()) {
150 _log.warn(nsne);
151 }
152 }
153 }
154
155 return rss.getBytes(StringPool.UTF8);
156 }
157
158 protected boolean isCheckMethodOnProcessAction() {
159 return _CHECK_METHOD_ON_PROCESS_ACTION;
160 }
161
162 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
163
164 private static Log _log = LogFactory.getLog(RSSAction.class);
165
166 }