diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/nabble/view/web/tools/OnlineUsers.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,61 @@
+
+package nabble.view.web.tools;
+
+import nabble.view.web.user.OnlineStatus;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+
+
+public final class OnlineUsers extends HttpServlet {
+
+	private static class Entry {
+		String url;
+		int count;
+		Entry(String url, int count) {
+			this.url = url;
+			this.count = count;
+		}
+	}
+
+	protected void service(HttpServletRequest request,HttpServletResponse response)
+		throws ServletException, IOException
+	{
+		Map<String, Integer> sites = OnlineStatus.getOnlineSites();
+		ArrayList<Entry> list = new ArrayList<Entry>(sites.size());
+		for (Map.Entry<String, Integer> entry : sites.entrySet()) {
+			list.add(new Entry(entry.getKey(), entry.getValue()));
+		}
+
+		Collections.sort(list, new Comparator<Entry>() {
+			public int compare(Entry o1, Entry o2) {
+				return o1.count == o2.count? 0 : o1.count > o2.count? -1 : 1;
+			}
+		});
+
+		PrintWriter out = response.getWriter();
+		
+		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		" );
+ for (Entry entry : list) { 
+		out.print( "\n			<tr><td><a href=\"" );
+		out.print( (entry.url) );
+		out.print( "\">" );
+		out.print( (entry.url) );
+		out.print( "</a></td><td>" );
+		out.print( (entry.count) );
+		out.print( "</td></tr>\n		" );
+ } 
+		out.print( "\n		</table>\n	</body>\n</html>\n" );
+
+	}
+
+}
+