KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > ListGroupsAction


1 /*
2  * ListGroupsAction.java
3  *
4  */

5
6 package com.quikj.application.communicator.applications.webtalk.controller;
7
8 import javax.servlet.http.*;
9 import org.apache.struts.action.*;
10 import java.sql.*;
11 import java.util.*;
12
13 import com.quikj.application.communicator.admin.model.*;
14 import com.quikj.application.communicator.admin.controller.*;
15 import com.quikj.application.communicator.applications.webtalk.model.*;
16 import com.quikj.server.framework.*;
17
18 /**
19  *
20  * @author bhm
21  */

22 public class ListGroupsAction extends Action
23 {
24     
25     /** Creates a new instance of ListGroupsAction */
26     public ListGroupsAction()
27     {
28     }
29     
30     public ActionForward execute(ActionMapping mapping,
31     ActionForm form,
32     HttpServletRequest request,
33     HttpServletResponse response)
34     {
35         ActionErrors errors = new ActionErrors();
36         
37         Connection c = (Connection)request.getSession().getAttribute("connection");
38         if (c == null)
39         {
40             errors.add(ActionErrors.GLOBAL_ERROR,
41             new ActionError("error.not.logged.in"));
42             saveErrors(request, errors);
43             return mapping.findForward("logon");
44         }
45         
46         AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo");
47         if (element.isAdminLevel() == false)
48         {
49             errors.add(ActionErrors.GLOBAL_ERROR,
50             new ActionError("error.insufficient.privilege"));
51             saveErrors(request, errors);
52             
53             return mapping.findForward("main_menu");
54         }
55         
56         GroupTable tbl = new GroupTable();
57         tbl.setConnection(c);
58         
59         ArrayList list = tbl.listAllByDomain();
60
61         if (list == null)
62         {
63             errors.add(ActionErrors.GLOBAL_ERROR,
64             new ActionError("error.db.failure"));
65             
66             AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
67             "ListGroupsAction.execute()/by-"
68             + element.getName()
69             + ": "
70             + tbl.getErrorMessage());
71         }
72         else
73         {
74             int num_items = list.size();
75             
76             //store the list result items for the jsp
77
ArrayList name_list = new ArrayList();
78             for (int i = 0; i < num_items; i++)
79             {
80                 GroupElement ele = (GroupElement) list.get(i);
81                 
82                 HashMap map = new HashMap();
83                 map.put("name", ele.getName());
84                 map.put("submit", "Find");
85                 map.put("domain", ele.getDomain());
86                 name_list.add(map);
87             }
88             
89             request.setAttribute("groups", name_list);
90         }
91         
92         if (errors.isEmpty() == false)
93         {
94             saveErrors(request, errors);
95         }
96         
97         // add related tasks to the navigation bar
98
WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
99         menu.addLink(new LinkAttribute("Administer groups", "display_group_management"));
100         menu.addLink(new LinkAttribute("Search users", "display_user_search"));
101         menu.addLink(new LinkAttribute("Administer users", "display_user_management"));
102         request.setAttribute("menu", menu);
103         
104         return mapping.getInputForward();
105     }
106 }
Popular Tags