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.journal.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.security.auth.PrincipalException;
20  import com.liferay.portal.struts.PortletAction;
21  import com.liferay.portlet.journal.DuplicateStructureIdException;
22  import com.liferay.portlet.journal.NoSuchStructureException;
23  import com.liferay.portlet.journal.StructureIdException;
24  import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
25  
26  import javax.portlet.ActionRequest;
27  import javax.portlet.ActionResponse;
28  import javax.portlet.PortletConfig;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  import org.apache.struts.action.ActionForm;
33  import org.apache.struts.action.ActionForward;
34  import org.apache.struts.action.ActionMapping;
35  
36  /**
37   * <a href="CopyStructureAction.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class CopyStructureAction 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              copyStructure(actionRequest);
50  
51              sendRedirect(actionRequest, actionResponse);
52          }
53          catch (Exception e) {
54              if (e instanceof NoSuchStructureException ||
55                  e instanceof PrincipalException) {
56  
57                  SessionErrors.add(actionRequest, e.getClass().getName());
58  
59                  setForward(actionRequest, "portlet.journal.error");
60              }
61              else if (e instanceof DuplicateStructureIdException ||
62                       e instanceof StructureIdException) {
63  
64                  SessionErrors.add(actionRequest, e.getClass().getName());
65              }
66              else {
67                  throw e;
68              }
69          }
70      }
71  
72      public ActionForward render(
73              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
74              RenderRequest renderRequest, RenderResponse renderResponse)
75          throws Exception {
76  
77          return mapping.findForward(
78              getForward(renderRequest, "portlet.journal.copy_structure"));
79      }
80  
81      protected void copyStructure(ActionRequest actionRequest) throws Exception {
82          long groupId = ParamUtil.getLong(actionRequest, "groupId");
83          String oldStructureId = ParamUtil.getString(
84              actionRequest, "oldStructureId");
85          String newStructureId = ParamUtil.getString(
86              actionRequest, "newStructureId");
87          boolean autoStructureId = ParamUtil.getBoolean(
88              actionRequest, "autoStructureId");
89  
90          JournalStructureServiceUtil.copyStructure(
91              groupId, oldStructureId, newStructureId, autoStructureId);
92      }
93  
94  }