KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > setup > ActiveSession


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.setup;
21
22 import java.text.DateFormat JavaDoc;
23 import java.util.Calendar JavaDoc;
24 import java.util.GregorianCalendar JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import com.sslexplorer.core.CoreUtil;
29 import com.sslexplorer.security.SessionInfo;
30 import com.sslexplorer.table.TableItem;
31
32 /**
33  * Wrapper bean for display an item an the list of sessions on the status
34  * page.
35  *
36  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  */

38
39 public class ActiveSession implements TableItem {
40
41     final static DateFormat JavaDoc dateFormat = DateFormat.getDateInstance();
42     final static DateFormat JavaDoc timeFormat = DateFormat.getTimeInstance();
43     
44     // Private instance variables
45
private SessionInfo info;
46
47     /**
48      * Constructor
49      *
50      * @param info session
51      * @param vpnSessions list of VPN client session the web session is attached to
52      */

53     public ActiveSession(SessionInfo info) {
54         super();
55         this.info = info;
56     }
57
58
59     /**
60      * Get the {@link SessionInfo} this object wraps.
61      *
62      * @return session
63      */

64     public SessionInfo getInfo() {
65         return info;
66     }
67
68     /**
69      * Get the time the session logged on as plain text in the current
70      * locales format.
71      *
72      * @return logon time as text
73      */

74     public String JavaDoc getLogonTimeText() {
75         Calendar JavaDoc c = getInfo().getLogonTime();
76         Calendar JavaDoc startOfDay = new GregorianCalendar JavaDoc();
77         startOfDay.set(Calendar.HOUR, 0);
78         startOfDay.set(Calendar.MINUTE, 0);
79         startOfDay.set(Calendar.SECOND, 0);
80         startOfDay.set(Calendar.MILLISECOND, 0);
81         Calendar JavaDoc endOfDay = new GregorianCalendar JavaDoc();
82         endOfDay.set(Calendar.HOUR, 23);
83         endOfDay.set(Calendar.MINUTE, 59);
84         endOfDay.set(Calendar.SECOND, 59);
85         endOfDay.set(Calendar.MILLISECOND, 999);
86         if(c.compareTo(endOfDay) <= 0 && c.compareTo(startOfDay) >= 0) {
87             return timeFormat.format(getInfo().getLogonTime().getTime());
88         }
89         else {
90             return dateFormat.format(getInfo().getLogonTime().getTime());
91         }
92     }
93
94     /* (non-Javadoc)
95      * @see com.sslexplorer.table.TableItem#getColumnValue(int)
96      */

97     public Object JavaDoc getColumnValue(int col) {
98         switch(col) {
99             case 0:
100                 return getInfo().getUser().getPrincipalName();
101             case 1:
102                 return getInfo().getAddress();
103             default:
104                 return getInfo().getLogonTime();
105         }
106     }
107     
108     public String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request) {
109         return CoreUtil.getThemePath(request.getSession()) + "/images/actions/user.gif";
110     }
111
112 }
113
Popular Tags