1
19
20 package com.liferay.portlet.journal.action;
21
22 import com.liferay.portal.kernel.servlet.SessionErrors;
23 import com.liferay.portal.kernel.util.ParamUtil;
24 import com.liferay.portal.security.auth.PrincipalException;
25 import com.liferay.portal.struts.PortletAction;
26 import com.liferay.portlet.journal.DuplicateStructureIdException;
27 import com.liferay.portlet.journal.NoSuchStructureException;
28 import com.liferay.portlet.journal.StructureIdException;
29 import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
30
31 import javax.portlet.ActionRequest;
32 import javax.portlet.ActionResponse;
33 import javax.portlet.PortletConfig;
34 import javax.portlet.RenderRequest;
35 import javax.portlet.RenderResponse;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40
41
47 public class CopyStructureAction extends PortletAction {
48
49 public void processAction(
50 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
51 ActionRequest actionRequest, ActionResponse actionResponse)
52 throws Exception {
53
54 try {
55 copyStructure(actionRequest);
56
57 sendRedirect(actionRequest, actionResponse);
58 }
59 catch (Exception e) {
60 if (e instanceof NoSuchStructureException ||
61 e instanceof PrincipalException) {
62
63 SessionErrors.add(actionRequest, e.getClass().getName());
64
65 setForward(actionRequest, "portlet.journal.error");
66 }
67 else if (e instanceof DuplicateStructureIdException ||
68 e instanceof StructureIdException) {
69
70 SessionErrors.add(actionRequest, e.getClass().getName());
71 }
72 else {
73 throw e;
74 }
75 }
76 }
77
78 public ActionForward render(
79 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
80 RenderRequest renderRequest, RenderResponse renderResponse)
81 throws Exception {
82
83 return mapping.findForward(
84 getForward(renderRequest, "portlet.journal.copy_structure"));
85 }
86
87 protected void copyStructure(ActionRequest actionRequest) throws Exception {
88 long groupId = ParamUtil.getLong(actionRequest, "groupId");
89 String oldStructureId = ParamUtil.getString(
90 actionRequest, "oldStructureId");
91 String newStructureId = ParamUtil.getString(
92 actionRequest, "newStructureId");
93 boolean autoStructureId = ParamUtil.getBoolean(
94 actionRequest, "autoStructureId");
95
96 JournalStructureServiceUtil.copyStructure(
97 groupId, oldStructureId, newStructureId, autoStructureId);
98 }
99
100 }