0
|
1 <%
|
|
2 package nabble.view.web.tools;
|
|
3
|
|
4 import nabble.view.web.user.OnlineStatus;
|
|
5
|
|
6 import javax.servlet.ServletException;
|
|
7 import javax.servlet.http.HttpServlet;
|
|
8 import javax.servlet.http.HttpServletRequest;
|
|
9 import javax.servlet.http.HttpServletResponse;
|
|
10 import java.io.IOException;
|
|
11 import java.io.PrintWriter;
|
|
12 import java.util.ArrayList;
|
|
13 import java.util.Collections;
|
|
14 import java.util.Comparator;
|
|
15 import java.util.Map;
|
|
16
|
|
17
|
|
18 public final class OnlineUsers extends HttpServlet {
|
|
19
|
|
20 private static class Entry {
|
|
21 String url;
|
|
22 int count;
|
|
23 Entry(String url, int count) {
|
|
24 this.url = url;
|
|
25 this.count = count;
|
|
26 }
|
|
27 }
|
|
28
|
|
29 protected void service(HttpServletRequest request,HttpServletResponse response)
|
|
30 throws ServletException, IOException
|
|
31 {
|
|
32 Map<String, Integer> sites = OnlineStatus.getOnlineSites();
|
|
33 ArrayList<Entry> list = new ArrayList<Entry>(sites.size());
|
|
34 for (Map.Entry<String, Integer> entry : sites.entrySet()) {
|
|
35 list.add(new Entry(entry.getKey(), entry.getValue()));
|
|
36 }
|
|
37
|
|
38 Collections.sort(list, new Comparator<Entry>() {
|
|
39 public int compare(Entry o1, Entry o2) {
|
|
40 return o1.count == o2.count? 0 : o1.count > o2.count? -1 : 1;
|
|
41 }
|
|
42 });
|
|
43
|
|
44 PrintWriter out = response.getWriter();
|
|
45 %>
|
|
46 <html>
|
|
47 <head>
|
|
48 <title>Online Users</title>
|
|
49 <style type="text/css">
|
|
50 body {
|
|
51 font-family:Verdana, Arial, Serif;
|
|
52 font-size:.74em;
|
|
53 }
|
|
54 table td{padding:.4em .8em;border-bottom:1px solid #eee}
|
|
55 </style>
|
|
56 </head>
|
|
57 <body>
|
|
58 <div>
|
|
59 <a href="/tools/">Tools</a>
|
|
60 </div>
|
|
61 <h1>Online Users</h1>
|
|
62
|
|
63 <table>
|
|
64 <% for (Entry entry : list) { %>
|
|
65 <tr><td><a href="<%=entry.url%>"><%=entry.url%></a></td><td><%=entry.count%></td></tr>
|
|
66 <% } %>
|
|
67 </table>
|
|
68 </body>
|
|
69 </html>
|
|
70 <%
|
|
71 }
|
|
72
|
|
73 }
|
|
74 %> |