KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > role > ViewRoleAction


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.role;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.Role;
20 import com.blandware.atleap.service.core.RoleManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.RoleForm;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.apache.struts.action.ActionMessage;
27 import org.apache.struts.action.ActionMessages;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 /**
33  * <p>Exposes bean to request to view its properties on JSP page (role is to be
34  * viewed)
35  * </p>
36  * <p><a HREF="ViewRoleAction.java.htm"><i>View Source</i></a></p>
37  * <p/>
38  *
39  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
40  * @version $Revision: 1.9 $ $Date: 2006/03/10 17:10:29 $
41  * @struts.action path="/core/role/view"
42  * name="roleForm"
43  * scope="request"
44  * validate="false"
45  * roles="core-role-view"
46  * @struts.action-forward name="viewRole"
47  * path=".core.role.view"
48  * @struts.action-forward name="listRoles"
49  * path="/core/role/list.do"
50  * redirect="true"
51  */

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

62     public ActionForward execute(ActionMapping mapping, ActionForm form,
63                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
64         RoleForm roleForm = (RoleForm) form;
65         String JavaDoc roleName = null;
66         if ( roleForm.getName() != null ) {
67             roleName = roleForm.getName();
68         } else {
69             if ( log.isWarnEnabled() ) {
70                 log.warn("Missing role name. Returning to list...");
71             }
72             return mapping.findForward("listRoles");
73         }
74
75         RoleManager roleManager = (RoleManager) getBean(Constants.ROLE_MANAGER_BEAN);
76         Role role = roleManager.retrieveRole(roleName);
77         if ( role == null ) {
78             // role not found. it might be deleted by someone else
79
ActionMessages errors = new ActionMessages();
80             errors.add("roleNotFound", new ActionMessage("core.role.errors.notFound"));
81             saveErrors(request, errors);
82             return mapping.findForward("listRoles");
83         }
84
85         request.setAttribute("role", role);
86         return mapping.findForward("viewRole");
87     }
88 }
Popular Tags