1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.journal.action;
24  
25  import com.liferay.portal.kernel.servlet.SessionErrors;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portal.security.auth.PrincipalException;
28  import com.liferay.portal.struts.PortletAction;
29  import com.liferay.portlet.journal.DuplicateStructureIdException;
30  import com.liferay.portlet.journal.NoSuchStructureException;
31  import com.liferay.portlet.journal.StructureIdException;
32  import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
33  
34  import javax.portlet.ActionRequest;
35  import javax.portlet.ActionResponse;
36  import javax.portlet.PortletConfig;
37  import javax.portlet.RenderRequest;
38  import javax.portlet.RenderResponse;
39  
40  import org.apache.struts.action.ActionForm;
41  import org.apache.struts.action.ActionForward;
42  import org.apache.struts.action.ActionMapping;
43  
44  /**
45   * <a href="CopyStructureAction.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   */
49  public class CopyStructureAction extends PortletAction {
50  
51      public void processAction(
52              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
53              ActionRequest actionRequest, ActionResponse actionResponse)
54          throws Exception {
55  
56          try {
57              copyStructure(actionRequest);
58  
59              sendRedirect(actionRequest, actionResponse);
60          }
61          catch (Exception e) {
62              if (e instanceof NoSuchStructureException ||
63                  e instanceof PrincipalException) {
64  
65                  SessionErrors.add(actionRequest, e.getClass().getName());
66  
67                  setForward(actionRequest, "portlet.journal.error");
68              }
69              else if (e instanceof DuplicateStructureIdException ||
70                       e instanceof StructureIdException) {
71  
72                  SessionErrors.add(actionRequest, e.getClass().getName());
73              }
74              else {
75                  throw e;
76              }
77          }
78      }
79  
80      public ActionForward render(
81              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
82              RenderRequest renderRequest, RenderResponse renderResponse)
83          throws Exception {
84  
85          return mapping.findForward(
86              getForward(renderRequest, "portlet.journal.copy_structure"));
87      }
88  
89      protected void copyStructure(ActionRequest actionRequest) throws Exception {
90          long groupId = ParamUtil.getLong(actionRequest, "groupId");
91          String oldStructureId = ParamUtil.getString(
92              actionRequest, "oldStructureId");
93          String newStructureId = ParamUtil.getString(
94              actionRequest, "newStructureId");
95          boolean autoStructureId = ParamUtil.getBoolean(
96              actionRequest, "autoStructureId");
97  
98          JournalStructureServiceUtil.copyStructure(
99              groupId, oldStructureId, newStructureId, autoStructureId);
100     }
101 
102 }