1
19
20 package com.liferay.portlet.calendar.action;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.util.ContentTypes;
25 import com.liferay.portal.kernel.util.FileUtil;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.struts.ActionConstants;
28 import com.liferay.portal.struts.PortletAction;
29 import com.liferay.portal.theme.ThemeDisplay;
30 import com.liferay.portal.util.PortalUtil;
31 import com.liferay.portal.util.WebKeys;
32 import com.liferay.portlet.calendar.service.CalEventServiceUtil;
33 import com.liferay.util.servlet.ServletResponseUtil;
34
35 import java.io.BufferedInputStream;
36 import java.io.File;
37 import java.io.FileInputStream;
38 import java.io.InputStream;
39
40 import javax.portlet.ActionRequest;
41 import javax.portlet.ActionResponse;
42 import javax.portlet.PortletConfig;
43
44 import javax.servlet.http.HttpServletResponse;
45
46 import org.apache.struts.action.ActionForm;
47 import org.apache.struts.action.ActionMapping;
48
49
57 public class ExportEventsAction extends PortletAction {
58
59 public void processAction(
60 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
61 ActionRequest actionRequest, ActionResponse actionResponse)
62 throws Exception {
63
64 File file = null;
65 InputStream is = null;
66
67 try {
68 ThemeDisplay themeDisplay =
69 (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
70
71 long eventId = ParamUtil.getLong(actionRequest, "eventId");
72
73 String exportFileName = ParamUtil.getString(
74 actionRequest, "exportFileName");
75
76 if (eventId > 0) {
77 file = CalEventServiceUtil.exportEvent(eventId);
78 }
79 else {
80 file = CalEventServiceUtil.exportGroupEvents(
81 themeDisplay.getScopeGroupId(), exportFileName);
82 }
83
84 is = new BufferedInputStream(new FileInputStream(file));
85
86 HttpServletResponse response = PortalUtil.getHttpServletResponse(
87 actionResponse);
88
89 ServletResponseUtil.sendFile(
90 response, file.getName(), is, ContentTypes.TEXT_CALENDAR);
91
92 setForward(actionRequest, ActionConstants.COMMON_NULL);
93 }
94 catch (Exception e) {
95 _log.error(e, e);
96 }
97 finally {
98 ServletResponseUtil.cleanUp(is);
99
100 FileUtil.delete(file);
101 }
102 }
103
104 protected boolean isCheckMethodOnProcessAction() {
105 return _CHECK_METHOD_ON_PROCESS_ACTION;
106 }
107
108 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
109
110 private static Log _log = LogFactoryUtil.getLog(ExportEventsAction.class);
111
112 }