KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > user > DeleteUserAction


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.core.user;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.service.core.UserManager;
20 import com.blandware.atleap.service.exception.BeanNotFoundException;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.UserForm;
23 import org.apache.commons.validator.GenericValidator;
24 import org.apache.struts.action.*;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 /**
30  * <p>Deletes user
31  * </p>
32  * <p><a HREF="DeleteUserAction.java.htm"><i>View Source</i></a></p>
33  * <p/>
34  *
35  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
36  * @version $Revision: 1.19 $ $Date: 2006/03/10 17:10:30 $
37  * @struts.action path="/core/user/delete"
38  * name="userForm"
39  * scope="request"
40  * validate="false"
41  * roles="core-user-delete"
42  * @struts.action-forward name="listUsers"
43  * path="/core/user/list.do"
44  * redirect="true"
45  * @struts.action-forward name="unsatisfiable"
46  * path="/core/user/list.do"
47  */

48 public final class DeleteUserAction extends BaseAction {
49     /**
50      * @param mapping The ActionMapping used to select this instance
51      * @param form The optional ActionForm bean for this request (if any)
52      * @param request The HTTP request we are proceeding
53      * @param response The HTTP response we are creating
54      * @return an ActionForward instance describing where and how
55      * control should be forwarded, or null if response
56      * has already been completed
57      */

58     public ActionForward execute(ActionMapping mapping, ActionForm form,
59                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
60
61         UserForm userForm = (UserForm) form;
62         String JavaDoc userName = userForm.getName();
63         if (GenericValidator.isBlankOrNull(userName)) {
64             if (log.isWarnEnabled()) {
65                 log.warn("Missing user name. Returning to list...");
66             }
67             return mapping.findForward("listUsers");
68         }
69
70         if (userName.equals(request.getRemoteUser())) {
71             // currently logged in user cannot be deleted
72
saveToken(request);
73             ActionMessages errors = new ActionMessages();
74             errors.add("loggedUserCannotDelete", new ActionMessage("core.user.form.loggedUser.cannotDelete"));
75             saveErrors(request, errors);
76             return mapping.findForward("listUsers");
77         }
78
79         UserManager userManager = (UserManager) getBean(Constants.USER_MANAGER_BEAN);
80         try {
81             userManager.deleteUser(userName);
82         } catch (BeanNotFoundException e) {
83             // user not found. it might be deleted by someone else
84
ActionMessages errors = new ActionMessages();
85             errors.add("userNotFound", new ActionMessage("core.user.errors.notFound"));
86             saveErrors(request, errors);
87             return mapping.findForward("listUsers");
88         }
89         return mapping.findForward("listUsers");
90     }
91
92 }
Popular Tags