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.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  }