diff src/nabble/view/web/tools/OnlineUsers.jtp @ 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.jtp	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,74 @@
+<%
+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();
+		%>
+		<html>
+			<head>
+				<title>Online Users</title>
+				<style type="text/css">
+					body {
+						font-family:Verdana, Arial, Serif;
+						font-size:.74em;
+					}
+					table td{padding:.4em .8em;border-bottom:1px solid #eee}
+				</style>
+			</head>
+			<body>
+				<div>
+					<a href="/tools/">Tools</a>
+				</div>
+				<h1>Online Users</h1>
+
+				<table>
+				<% for (Entry entry : list) { %>
+					<tr><td><a href="<%=entry.url%>"><%=entry.url%></a></td><td><%=entry.count%></td></tr>
+				<% } %>
+				</table>
+			</body>
+		</html>
+		<%
+	}
+
+}
+%>
\ No newline at end of file