1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.communities.action;
21  
22  import com.liferay.portal.LARFileException;
23  import com.liferay.portal.LARTypeException;
24  import com.liferay.portal.LayoutImportException;
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.servlet.SessionErrors;
28  import com.liferay.portal.kernel.servlet.SessionMessages;
29  import com.liferay.portal.kernel.upload.UploadPortletRequest;
30  import com.liferay.portal.kernel.util.ParamUtil;
31  import com.liferay.portal.service.LayoutServiceUtil;
32  import com.liferay.portal.util.PortalUtil;
33  
34  import java.io.File;
35  
36  import javax.portlet.ActionRequest;
37  import javax.portlet.ActionResponse;
38  import javax.portlet.PortletConfig;
39  
40  import org.apache.struts.action.ActionForm;
41  import org.apache.struts.action.ActionMapping;
42  
43  /**
44   * <a href="ImportPagesAction.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Alexander Chow
47   * @author Raymond Aug�
48   *
49   */
50  public class ImportPagesAction extends EditPagesAction {
51  
52      public void processAction(
53              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
54              ActionRequest actionRequest, ActionResponse actionResponse)
55          throws Exception {
56  
57          try {
58              UploadPortletRequest uploadRequest =
59                  PortalUtil.getUploadPortletRequest(actionRequest);
60  
61              long groupId = ParamUtil.getLong(uploadRequest, "groupId");
62              boolean privateLayout = ParamUtil.getBoolean(
63                  uploadRequest, "privateLayout");
64              File file = uploadRequest.getFile("importFileName");
65  
66              if (!file.exists()) {
67                  throw new LARFileException("Import file does not exist");
68              }
69  
70              LayoutServiceUtil.importLayouts(
71                  groupId, privateLayout, actionRequest.getParameterMap(), file);
72  
73              SessionMessages.add(actionRequest, "request_processed");
74          }
75          catch (Exception e) {
76              if ((e instanceof LARFileException) ||
77                  (e instanceof LARTypeException)) {
78  
79                  SessionErrors.add(actionRequest, e.getClass().getName());
80              }
81              else {
82                  _log.error(e, e);
83  
84                  SessionErrors.add(
85                      actionRequest, LayoutImportException.class.getName());
86              }
87          }
88      }
89  
90      private static Log _log = LogFactoryUtil.getLog(ImportPagesAction.class);
91  
92  }