1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.communities.action;
24  
25  import com.liferay.portal.LayoutImportException;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portal.service.LayoutServiceUtil;
28  import com.liferay.portal.util.PortalUtil;
29  import com.liferay.util.servlet.SessionErrors;
30  import com.liferay.util.servlet.SessionMessages;
31  import com.liferay.util.servlet.UploadPortletRequest;
32  
33  import java.io.File;
34  
35  import javax.portlet.ActionRequest;
36  import javax.portlet.ActionResponse;
37  import javax.portlet.PortletConfig;
38  
39  import org.apache.commons.logging.Log;
40  import org.apache.commons.logging.LogFactory;
41  import org.apache.struts.action.ActionForm;
42  import org.apache.struts.action.ActionMapping;
43  
44  /**
45   * <a href="ImportPagesAction.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Alexander Chow
48   * @author Raymond Augé
49   *
50   */
51  public class ImportPagesAction extends EditPagesAction {
52  
53      public void processAction(
54              ActionMapping mapping, ActionForm form, PortletConfig config,
55              ActionRequest req, ActionResponse res)
56          throws Exception {
57  
58          try {
59              UploadPortletRequest uploadReq =
60                  PortalUtil.getUploadPortletRequest(req);
61  
62              long groupId = ParamUtil.getLong(uploadReq, "groupId");
63              boolean privateLayout = ParamUtil.getBoolean(
64                  uploadReq, "privateLayout");
65              File file = uploadReq.getFile("importFileName");
66  
67              LayoutServiceUtil.importLayouts(
68                  groupId, privateLayout, req.getParameterMap(), file);
69  
70              SessionMessages.add(req, "request_processed");
71          }
72          catch (Exception e) {
73              _log.error(e, e);
74  
75              SessionErrors.add(req, LayoutImportException.class.getName());
76          }
77      }
78  
79      private static Log _log = LogFactory.getLog(ImportPagesAction.class);
80  
81  }