public String getTopBarHTML(final HttpServletRequest request, final HttpServletResponse response)
throws ServiceException {
Stopwatchs.start("Gens Top Bar HTML");
try {
final Template topBarTemplate = ConsoleRenderer.TEMPLATE_CFG.getTemplate("top-bar.ftl");
final StringWriter stringWriter = new StringWriter();
final Map<String, Object> topBarModel = new HashMap<String, Object>();
userMgmtService.tryLogInWithCookie(request, response);
final JSONObject currentUser = userQueryService.getCurrentUser(request);
Keys.fillServer(topBarModel);
topBarModel.put(Common.IS_LOGGED_IN, false);
topBarModel.put(Common.IS_MOBILE_REQUEST, Requests.mobileRequest(request));
topBarModel.put("mobileLabel", langPropsService.get("mobileLabel"));
topBarModel.put("onlineVisitor1Label", langPropsService.get("onlineVisitor1Label"));
topBarModel.put(Common.ONLINE_VISITOR_CNT, statisticQueryService.getOnlineVisitorCount());
if (null == currentUser) {
topBarModel.put(Common.LOGIN_URL, userService.createLoginURL(Common.ADMIN_INDEX_URI));
topBarModel.put("loginLabel", langPropsService.get("loginLabel"));
topBarModel.put("registerLabel", langPropsService.get("registerLabel"));
topBarTemplate.process(topBarModel, stringWriter);
return stringWriter.toString();
}
topBarModel.put(Common.IS_LOGGED_IN, true);
topBarModel.put(Common.LOGOUT_URL, userService.createLogoutURL("/"));
topBarModel.put(Common.IS_ADMIN, Role.ADMIN_ROLE.equals(currentUser.getString(User.USER_ROLE)));
topBarModel.put(Common.IS_VISITOR, Role.VISITOR_ROLE.equals(currentUser.getString(User.USER_ROLE)));
topBarModel.put("adminLabel", langPropsService.get("adminLabel"));
topBarModel.put("logoutLabel", langPropsService.get("logoutLabel"));
final String userName = currentUser.getString(User.USER_NAME);
topBarModel.put(User.USER_NAME, userName);
topBarTemplate.process(topBarModel, stringWriter);
return stringWriter.toString();
} catch (final JSONException e) {
LOGGER.log(Level.ERROR, "Gens top bar HTML failed", e);
throw new ServiceException(e);