1
19
20 package com.liferay.portlet.imagegallery.action;
21
22 import com.liferay.portal.kernel.servlet.SessionErrors;
23 import com.liferay.portal.kernel.util.Constants;
24 import com.liferay.portal.kernel.util.ParamUtil;
25 import com.liferay.portal.model.Layout;
26 import com.liferay.portal.security.auth.PrincipalException;
27 import com.liferay.portal.struts.PortletAction;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.imagegallery.DuplicateFolderNameException;
30 import com.liferay.portlet.imagegallery.FolderNameException;
31 import com.liferay.portlet.imagegallery.NoSuchFolderException;
32 import com.liferay.portlet.imagegallery.service.IGFolderServiceUtil;
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
50 public class EditFolderAction extends PortletAction {
51
52 public void processAction(
53 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
54 ActionRequest actionRequest, ActionResponse actionResponse)
55 throws Exception {
56
57 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
58
59 try {
60 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
61 updateFolder(actionRequest);
62 }
63 else if (cmd.equals(Constants.DELETE)) {
64 deleteFolder(actionRequest);
65 }
66
67 sendRedirect(actionRequest, actionResponse);
68 }
69 catch (Exception e) {
70 if (e instanceof NoSuchFolderException ||
71 e instanceof PrincipalException) {
72
73 SessionErrors.add(actionRequest, e.getClass().getName());
74
75 setForward(actionRequest, "portlet.image_gallery.error");
76 }
77 else if (e instanceof DuplicateFolderNameException ||
78 e instanceof FolderNameException) {
79
80 SessionErrors.add(actionRequest, e.getClass().getName());
81 }
82 else {
83 throw e;
84 }
85 }
86 }
87
88 public ActionForward render(
89 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
90 RenderRequest renderRequest, RenderResponse renderResponse)
91 throws Exception {
92
93 try {
94 ActionUtil.getFolder(renderRequest);
95 }
96 catch (Exception e) {
97 if (e instanceof NoSuchFolderException ||
98 e instanceof PrincipalException) {
99
100 SessionErrors.add(renderRequest, e.getClass().getName());
101
102 return mapping.findForward("portlet.image_gallery.error");
103 }
104 else {
105 throw e;
106 }
107 }
108
109 return mapping.findForward(
110 getForward(renderRequest, "portlet.image_gallery.edit_folder"));
111 }
112
113 protected void deleteFolder(ActionRequest actionRequest) throws Exception {
114 long folderId = ParamUtil.getLong(actionRequest, "folderId");
115
116 IGFolderServiceUtil.deleteFolder(folderId);
117 }
118
119 protected void updateFolder(ActionRequest actionRequest) throws Exception {
120 Layout layout = (Layout)actionRequest.getAttribute(WebKeys.LAYOUT);
121
122 long folderId = ParamUtil.getLong(actionRequest, "folderId");
123
124 long parentFolderId = ParamUtil.getLong(
125 actionRequest, "parentFolderId");
126 String name = ParamUtil.getString(actionRequest, "name");
127 String description = ParamUtil.getString(actionRequest, "description");
128
129 boolean mergeWithParentFolder = ParamUtil.getBoolean(
130 actionRequest, "mergeWithParentFolder");
131
132 String[] communityPermissions = actionRequest.getParameterValues(
133 "communityPermissions");
134 String[] guestPermissions = actionRequest.getParameterValues(
135 "guestPermissions");
136
137 if (folderId <= 0) {
138
139
141 IGFolderServiceUtil.addFolder(
142 layout.getPlid(), parentFolderId, name, description,
143 communityPermissions, guestPermissions);
144 }
145 else {
146
147
149 IGFolderServiceUtil.updateFolder(
150 folderId, parentFolderId, name, description,
151 mergeWithParentFolder);
152 }
153 }
154
155 }