KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > block > OnLineBlock


1
2
3  /*
4  -- GeiNuke --
5 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
6  http://www.hostingjava.it/-geinuke/
7
8 This file is part of GeiNuke.
9
10     GeiNuke is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     GeiNuke is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with GeiNuke; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */

24 package com.geinuke.block;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Hashtable JavaDoc;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 import org.apache.velocity.context.Context;
34
35 import com.geinuke.common.BlockWidgetI;
36 import com.geinuke.common.GlobalConfigurationI;
37 import com.geinuke.common.NukeRoleI;
38 import com.geinuke.common.UserI;
39 import com.geinuke.middle.ISessionBL;
40 import com.geinuke.middle.IUserBL;
41 import com.geinuke.servlet.GeiServlet;
42 import com.geinuke.vo.*;
43
44
45 public class OnLineBlock implements BlockWidgetI{
46     
47     public ArrayList JavaDoc getLastSessions(ISessionBL sbl,IUserBL ubl)throws Exception JavaDoc{
48         ArrayList JavaDoc list=null,aux=null;
49         aux=sbl.getLastSessions(RoleVO.ID_ANONYMOUS,10);
50         list=new ArrayList JavaDoc();
51         Hashtable JavaDoc ht=new Hashtable JavaDoc();
52         if(aux!=null){
53             SessionVO s=null;
54             UserVO u=null;
55             for(int i=0;i<aux.size();i++){
56                 s=(SessionVO)aux.get(i);
57                 u=(UserVO)ubl.getUserByID(s.getIdU());
58                 if(!ht.containsKey(""+u.getId())){
59                     list.add(u);
60                     ht.put(""+u.getId(),""+u.getId());
61                 }
62             }
63         }
64         
65         return list;
66     }
67     
68     public void fillBlock(BlockDBVO block,Context ctx, HttpServletRequest JavaDoc req,
69             HttpServletResponse JavaDoc res,UserI user,
70             GlobalConfigurationI gConf)throws Exception JavaDoc{
71         
72         ArrayList JavaDoc guestList=null,userList=null,adList=null;
73         ISessionBL bl=(ISessionBL)GeiServlet.getBL("ISessionBL");
74         IUserBL ubl=(IUserBL)GeiServlet.getBL("IUserBL");
75         ArrayList JavaDoc roles=ubl.getAllRoles();
76         RoleVO ro=null;
77         HashMap JavaDoc results=new HashMap JavaDoc();
78         int score=0;
79         int tot=0;
80         for(int i=0;i<roles.size();i++){
81             ro=(RoleVO)roles.get(i);
82             score=bl.getSessionsByIdRole(ro.getId()).size();
83             tot+=score;
84             results.put(ro.getRoleName(),score+"");
85         }
86         //guestList=bl.getSessionsByIdRole(NukeRoleI.ID_ANONYMOUS);
87
//userList=bl.getSessionsByIdRole(NukeRoleI.ID_USER);
88
//adList=bl.getSessionsByIdRole(NukeRoleI.ID_ADMINISTRATOR);
89
ArrayList JavaDoc last=this.getLastSessions(bl,ubl);
90         
91         PortalCFGVO po=(PortalCFGVO)req.getSession(true).getAttribute("portalCFG");
92         
93         ctx.put("names",ctx);
94         ctx.put("roles",roles);
95         ctx.put("resultsN",results.keySet());
96         ctx.put("results",results);
97         ctx.put("hits",""+po.getSessionHits() );
98         ctx.put("last",last);
99         //ctx.put("guestListSize",""+guestList.size());
100
//ctx.put("userListSize",""+userList.size());
101
//ctx.put("adListSize",""+adList.size());
102
//int total=adList.size()+userList.size()+guestList.size();
103
ctx.put("allSize",""+tot);
104         
105         
106         
107     
108     }
109
110 }
111
112
Popular Tags