1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.service.ServiceContext;
22  import com.liferay.portal.service.ServiceContextFactory;
23  import com.liferay.portal.struts.PortletAction;
24  import com.liferay.portal.util.PortalUtil;
25  import com.liferay.portlet.calendar.model.CalEvent;
26  import com.liferay.portlet.calendar.service.CalEventServiceUtil;
27  
28  import java.io.File;
29  
30  import javax.portlet.ActionRequest;
31  import javax.portlet.ActionResponse;
32  import javax.portlet.PortletConfig;
33  
34  import org.apache.struts.action.ActionForm;
35  import org.apache.struts.action.ActionMapping;
36  
37  /**
38   * <a href="ImportEventsAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Bruno Farache
41   */
42  public class ImportEventsAction extends PortletAction {
43  
44      public void processAction(
45              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
46              ActionRequest actionRequest, ActionResponse actionResponse)
47          throws Exception {
48  
49          try {
50              UploadPortletRequest uploadRequest =
51                  PortalUtil.getUploadPortletRequest(actionRequest);
52  
53              ServiceContext serviceContext = ServiceContextFactory.getInstance(
54                  CalEvent.class.getName(), actionRequest);
55  
56              File file = uploadRequest.getFile("file");
57  
58              CalEventServiceUtil.importICal4j(
59                  serviceContext.getScopeGroupId(), file);
60  
61              sendRedirect(actionRequest, actionResponse);
62          }
63          catch (Exception e) {
64              _log.error(e, e);
65  
66              SessionErrors.add(actionRequest, e.getClass().getName());
67  
68              setForward(actionRequest, "portlet.calendar.error");
69          }
70      }
71  
72      private static Log _log = LogFactoryUtil.getLog(ExportEventsAction.class);
73  
74  }