KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > group > ViewGroupAction


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.group;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.Group;
20 import com.blandware.atleap.service.core.GroupManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.GroupForm;
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 (group is to be
34  * viewed)
35  * </p>
36  * <p><a HREF="ViewGroupAction.java.htm"><i>View Source</i></a></p>
37  * <p/>
38  *
39  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
40  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
41  * @version $Revision: 1.2 $ $Date: 2006/03/10 17:10:25 $
42  * @struts.action path="/core/group/view"
43  * name="groupForm"
44  * scope="request"
45  * validate="false"
46  * roles="core-group-view"
47  * @struts.action-forward name="viewGroup"
48  * path=".core.group.view"
49  * @struts.action-forward name="listGroups"
50  * path="/core/group/list.do"
51  * redirect="true"
52  */

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

63     public ActionForward execute(ActionMapping mapping, ActionForm form,
64                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
65         GroupForm groupForm = (GroupForm) form;
66         String JavaDoc groupName = null;
67         if ( groupForm.getName() != null ) {
68             groupName = groupForm.getName();
69         } else {
70             if ( log.isWarnEnabled() ) {
71                 log.warn("Missing group name. Returning to list...");
72             }
73             return mapping.findForward("listGroups");
74         }
75
76         GroupManager groupManager = (GroupManager) getBean(Constants.GROUP_MANAGER_BEAN);
77         Group group = groupManager.retrieveGroup(groupName);
78         if ( group == null ) {
79             // group not found. it might be deleted by someone else
80
ActionMessages errors = new ActionMessages();
81             errors.add("groupNotFound", new ActionMessage("core.group.errors.notFound"));
82             saveErrors(request, errors);
83             return mapping.findForward("listGroups");
84         }
85
86         request.setAttribute("group", group);
87         return mapping.findForward("viewGroup");
88     }
89 }
Popular Tags