}
// find page to render
AbstractPage page = null;
if (msg != null) {
page = new ErrorPage(msg);
} else {
if (isLoggedIn) {
// logged in users may see all pages
ServletContext ctx = req.getSession().getServletContext();
HashMap<String, AbstractPage> pageMap = getPageMap(ctx);
String pageStr = req.getParameter(AbstractPage.P_PAGE);
page = pageMap.get(pageStr);
if (page == null) {
String pagenameDefault = AbstractPage.extractPagename(HomePage.class);
page = pageMap.get(pagenameDefault);
}
} else {
// not logged in users may see only the login page
page = new LoginPage();
}
}
// get html
StringBuffer html = null;
try {
html = page.getHtml(req);
} catch (Exception e) {
html = new ErrorPage(e.getMessage()).getHtml(req);
}
// produce output
double calcTime = (System.nanoTime() - begin) / 1E6;
ServletResponseTools.streamStringBuffer(html, "text/html", "utf-8", calcTime, req, resp);