response.setContentType(MimeConstants.MIME_HTML);
PrintWriter out = response.getWriter();
out.print("<html><head><title>DWR - System Monitor</title></head><body>");
WebContext webContext = WebContextFactory.get();
out.print("<h1>DWR - System Monitor</h1>");
out.print("<h2>Global Settings:</h2>");
String contextPath = webContext.getContextPath();
out.print("<p>ContextPath: " + contextPath + "</p>");
out.print("<p>Current Page: " + webContext.getCurrentPage() + "</p>");
//ScriptSession scriptSession = webContext.getScriptSession();
Container container = webContext.getContainer();
SortedMap<String, Object> beans = new TreeMap<String, Object>();
SortedMap<String, String> settings = new TreeMap<String, String>();
SortedMap<String, String> urls = new TreeMap<String, String>();
for (String name : container.getBeanNames())
{
Object bean = container.getBean(name);
if (name.startsWith("url:"))
{
urls.put(name.substring(4), bean.getClass().getName());
}
else if (bean instanceof String)
{
settings.put(name, bean.toString());
}
else
{
beans.put(name, bean);
}
}
// Add all the beans to an ID map for <a name=ID>
IdManager ids = new IdManager();
// Remove the URL re-writers from the Settings map
for (Map.Entry<String, String> urlEntry : urls.entrySet())
{
for (Iterator<Map.Entry<String, String>> it = settings.entrySet().iterator(); it.hasNext();)
{
Map.Entry<String, String> settingEntry = it.next();
if (urlEntry.getKey().equals(settingEntry.getValue()))
{
it.remove();
urls.put(urlEntry.getKey(), urlEntry.getValue() + " (" + settingEntry.getKey() + ")");
}
}
}
out.print("<h2>Beans:</h2>");
for (Map.Entry<String, Object> entry : beans.entrySet())
{
String name = entry.getKey();
Object object = entry.getValue();
digWhatever(out, ids, name, object);
}
out.print("<h2>Settings:</h2>");
for (Map.Entry<String, String> entry : settings.entrySet())
{
out.print("<p>" + entry.getKey() + ": \"" + entry.getValue() + "\"</p>");
}
out.print("<h2>URLs:</h2>");
String prefix = contextPath + webContext.getHttpServletRequest().getServletPath();
for (Map.Entry<String, String> entry : urls.entrySet())
{
out.print("<p><a href='" + prefix + entry.getKey() + "'>" + entry.getKey() + "</a>: " + entry.getValue() + "</p>");
}
webContext.getContextPath();
out.print("</body></html>");
}