Mercurial Hosting > nabble
comparison src/nabble/view/web/tools/OnlineUsers.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
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 out.print( "\n<html>\n <head>\n <title>Online Users</title>\n <style type=\"text/css\">\n body {\n font-family:Verdana, Arial, Serif;\n font-size:.74em;\n }\n table td{padding:.4em .8em;border-bottom:1px solid #eee}\n </style>\n </head>\n <body>\n <div>\n <a href=\"/tools/\">Tools</a>\n </div>\n <h1>Online Users</h1>\n\n <table>\n " ); | |
47 for (Entry entry : list) { | |
48 out.print( "\n <tr><td><a href=\"" ); | |
49 out.print( (entry.url) ); | |
50 out.print( "\">" ); | |
51 out.print( (entry.url) ); | |
52 out.print( "</a></td><td>" ); | |
53 out.print( (entry.count) ); | |
54 out.print( "</td></tr>\n " ); | |
55 } | |
56 out.print( "\n </table>\n </body>\n</html>\n" ); | |
57 | |
58 } | |
59 | |
60 } | |
61 |