else {
vars = new HashMap<String, Object>();
vars.put("it", model);
}
RequestContext requestContext = new RequestContext();
requestContext.setHttpServletRequest(requestInvoker != null ? requestInvoker.get() : null);
vars.put("RequestContext", requestContext);
vars.put("Request", requestInvoker != null ? requestInvoker.get() : null);
Principal ctx = null;
if (requestInvoker.get() != null) {
ctx = requestInvoker.get().getUserPrincipal();
if (ctx == null && requestInvoker.get().getSession(false) != null) {
final String username = (String) requestInvoker.get().getSession().getAttribute("SSO_UserName");
if (username != null) {
ctx = new Principal() {
@Override
public String getName() {
return username;
}
};
}
}
}
vars.put("Principal", ctx);
// The following are here for backward compatibility and should be deprecated as soon as possible
Map<String, Object> global = Maps.newHashMap();
if (manager != null) {
GlobalModelContext globalModel = manager.getGlobalModel();
global.put("sysenv", globalModel.getEnvironment()); // TODO: DEPRECATE
}
vars.put("global", global); // TODO: DEPRECATE
vars.put("pathToRoot", requestContext.getPathToRoot()); // TODO: DEPRECATE
String layout = DEFAULT_LAYOUT;
Explorer explorer = null;
final boolean hasExplorerName = !requestContext.getExplorerName().isEmpty();
try {
if (hasExplorerName) {
explorer = manager.getExplorer(requestContext.getExplorerName());
}
}
catch (Exception e) {
LOG.warn(e.getMessage());
}
if (explorer == null) {
if (hasExplorerName) {
throw new WebApplicationException(new RuntimeException("Invalid explorer"), Response.Status.NOT_FOUND);
} else {
explorer = EmptyExplorer.getInstance();
}
}
layout = explorer.getLayoutName();
vars.put("Explorer", explorer);
if (vars.containsKey("layout")) {
layout = (String) vars.get("layout");
}
final StringWriter stringWriter = new StringWriter();
try {
if (requestContext.getIsAjaxRequest()) {
fmConfig.getTemplate(resolvedPath).process(vars, stringWriter);
}
else {
if (layout == null) {
layout = DEFAULT_LAYOUT;