initConfiguration(cfg, viewContext);
servletContext.setAttribute(FreeMarkerViewRenderer.FREEMARKER_CONFIG, cfg);
}
HttpServletRequest request = viewContext.getRequest();
HttpServletResponse response = viewContext.getResponse();
String controllerPath = viewContext.getControllerPath();
Enumeration<?> attrNames = request.getAttributeNames();
while(attrNames.hasMoreElements()){
String attr = (String)attrNames.nextElement();
Object value = request.getAttribute(attr);
view.setAttribute(attr, value);
}
String path = view.getPath();
if (path == null){
path = controllerPath.toLowerCase() + "/" + viewContext.getActionName() + ".ftl";
}
else{
if (path.indexOf("/") == -1){
path = controllerPath.toLowerCase() + "/" + path;
}
else if (!path.startsWith("/")){
path = "/" + path;
}
if (!path.endsWith(".ftl")){
path += ".ftl";
}
}
if (view.getContentType() != null){
response.setContentType(view.getContentType());
}
Template t = cfg.getTemplate(path, request.getLocale());
t.process(view.getAttributes(), response.getWriter());
}