1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.calendar.action;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.servlet.SessionErrors;
20  import com.liferay.portal.kernel.upload.UploadPortletRequest;
21  import com.liferay.portal.model.Layout;
22  import com.liferay.portal.struts.PortletAction;
23  import com.liferay.portal.util.PortalUtil;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.calendar.service.CalEventServiceUtil;
26  
27  import java.io.File;
28  
29  import javax.portlet.ActionRequest;
30  import javax.portlet.ActionResponse;
31  import javax.portlet.PortletConfig;
32  
33  import org.apache.struts.action.ActionForm;
34  import org.apache.struts.action.ActionMapping;
35  
36  /**
37   * <a href="ImportEventsAction.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Bruno Farache
40   */
41  public class ImportEventsAction extends PortletAction {
42  
43      public void processAction(
44              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
45              ActionRequest actionRequest, ActionResponse actionResponse)
46          throws Exception {
47  
48          try {
49              UploadPortletRequest uploadRequest =
50                  PortalUtil.getUploadPortletRequest(actionRequest);
51  
52              Layout layout = (Layout)actionRequest.getAttribute(WebKeys.LAYOUT);
53  
54              File file = uploadRequest.getFile("file");
55  
56              CalEventServiceUtil.importICal4j(layout.getPlid(), file);
57  
58              sendRedirect(actionRequest, actionResponse);
59          }
60          catch (Exception e) {
61              _log.error(e, e);
62  
63              SessionErrors.add(actionRequest, e.getClass().getName());
64  
65              setForward(actionRequest, "portlet.calendar.error");
66          }
67      }
68  
69      private static Log _log = LogFactoryUtil.getLog(ExportEventsAction.class);
70  
71  }