use of freemarker.ext.jsp.TaglibFactory in project ofbiz-framework by apache.
the class ScreenRenderer method populateContextForRequest.
public static void populateContextForRequest(MapStack<String> context, ScreenRenderer screens, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) {
HttpSession session = request.getSession();
// attribute names to skip for session and application attributes; these are all handled as special cases, duplicating results and causing undesired messages
Set<String> attrNamesToSkip = UtilMisc.toSet("delegator", "dispatcher", "security", "webSiteId", "org.apache.catalina.jsp_classpath");
Map<String, Object> parameterMap = UtilHttp.getCombinedMap(request, attrNamesToSkip);
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
populateBasicContext(context, screens, parameterMap, (Delegator) request.getAttribute("delegator"), (LocalDispatcher) request.getAttribute("dispatcher"), (Security) request.getAttribute("security"), UtilHttp.getLocale(request), userLogin);
context.put("autoUserLogin", session.getAttribute("autoUserLogin"));
context.put("person", session.getAttribute("person"));
context.put("partyGroup", session.getAttribute("partyGroup"));
// some things also seem to require this, so here it is:
request.setAttribute("userLogin", userLogin);
// set up the user's time zone
context.put("timeZone", UtilHttp.getTimeZone(request));
// ========== setup values that are specific to OFBiz webapps
VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
if (visualTheme == null) {
String defaultVisualThemeId = EntityUtilProperties.getPropertyValue("general", "VISUAL_THEME", (Delegator) request.getAttribute("delegator"));
visualTheme = ThemeFactory.getVisualThemeFromId(defaultVisualThemeId);
}
context.put("visualTheme", visualTheme);
context.put("modelTheme", visualTheme.getModelTheme());
context.put("request", request);
context.put("response", response);
context.put("session", session);
context.put("application", servletContext);
context.put("webappName", session.getAttribute("_WEBAPP_NAME_"));
if (servletContext != null) {
String rootDir = (String) context.get("rootDir");
String webSiteId = (String) context.get("webSiteId");
String https = (String) context.get("https");
if (UtilValidate.isEmpty(rootDir)) {
rootDir = servletContext.getRealPath("/");
context.put("rootDir", rootDir);
}
if (UtilValidate.isEmpty(webSiteId)) {
webSiteId = WebSiteWorker.getWebSiteId(request);
context.put("webSiteId", webSiteId);
}
if (UtilValidate.isEmpty(https)) {
https = (String) servletContext.getAttribute("https");
context.put("https", https);
}
}
context.put("javaScriptEnabled", Boolean.valueOf(UtilHttp.isJavaScriptEnabled(request)));
// these ones are FreeMarker specific and will only work in FTL templates, mainly here for backward compatibility
context.put("sessionAttributes", new HttpSessionHashModel(session, FreeMarkerWorker.getDefaultOfbizWrapper()));
context.put("requestAttributes", new HttpRequestHashModel(request, FreeMarkerWorker.getDefaultOfbizWrapper()));
TaglibFactory JspTaglibs = new TaglibFactory(servletContext);
context.put("JspTaglibs", JspTaglibs);
context.put("requestParameters", UtilHttp.getParameterMap(request));
ServletContextHashModel ftlServletContext = (ServletContextHashModel) request.getAttribute("ftlServletContext");
context.put("Application", ftlServletContext);
context.put("Request", context.get("requestAttributes"));
// some information from/about the ControlServlet environment
context.put("controlPath", request.getAttribute("_CONTROL_PATH_"));
context.put("contextRoot", request.getAttribute("_CONTEXT_ROOT_"));
context.put("serverRoot", request.getAttribute("_SERVER_ROOT_URL_"));
context.put("checkLoginUrl", LoginWorker.makeLoginUrl(request));
String externalLoginKey = null;
boolean externalLoginKeyEnabled = "true".equals(EntityUtilProperties.getPropertyValue("security", "security.login.externalLoginKey.enabled", "true", (Delegator) request.getAttribute("delegator")));
if (externalLoginKeyEnabled) {
externalLoginKey = ExternalLoginKeysManager.getExternalLoginKey(request);
}
String externalKeyParam = externalLoginKey == null ? "" : "&externalLoginKey=" + externalLoginKey;
context.put("externalLoginKey", externalLoginKey);
context.put("externalKeyParam", externalKeyParam);
// setup message lists
List<String> eventMessageList = UtilGenerics.toList(request.getAttribute("eventMessageList"));
if (eventMessageList == null) {
eventMessageList = new LinkedList<>();
}
List<String> errorMessageList = UtilGenerics.toList(request.getAttribute("errorMessageList"));
if (errorMessageList == null) {
errorMessageList = new LinkedList<>();
}
if (request.getAttribute("_EVENT_MESSAGE_") != null) {
eventMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_EVENT_MESSAGE_"), "\n", "<br/>"));
request.removeAttribute("_EVENT_MESSAGE_");
}
List<String> msgList = UtilGenerics.toList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
if (msgList != null) {
eventMessageList.addAll(msgList);
request.removeAttribute("_EVENT_MESSAGE_LIST_");
}
if (request.getAttribute("_ERROR_MESSAGE_") != null) {
errorMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_ERROR_MESSAGE_"), "\n", "<br/>"));
request.removeAttribute("_ERROR_MESSAGE_");
}
if (session.getAttribute("_ERROR_MESSAGE_") != null) {
errorMessageList.add(UtilFormatOut.replaceString((String) session.getAttribute("_ERROR_MESSAGE_"), "\n", "<br/>"));
session.removeAttribute("_ERROR_MESSAGE_");
}
msgList = UtilGenerics.toList(request.getAttribute("_ERROR_MESSAGE_LIST_"));
if (msgList != null) {
errorMessageList.addAll(msgList);
request.removeAttribute("_ERROR_MESSAGE_LIST_");
}
context.put("eventMessageList", eventMessageList);
context.put("errorMessageList", errorMessageList);
if (request.getAttribute("serviceValidationException") != null) {
context.put("serviceValidationException", request.getAttribute("serviceValidationException"));
request.removeAttribute("serviceValidationException");
}
// if there was an error message, this is an error
context.put("isError", errorMessageList.size() > 0 ? Boolean.TRUE : Boolean.FALSE);
// if a parameter was passed saying this is an error, it is an error
if ("true".equals(parameterMap.get("isError"))) {
context.put("isError", Boolean.TRUE);
}
// to preserve these values, push the MapStack
context.push();
}
use of freemarker.ext.jsp.TaglibFactory in project ofbiz-framework by apache.
the class FreeMarkerViewHandler method prepOfbizRoot.
public static void prepOfbizRoot(Map<String, Object> root, HttpServletRequest request, HttpServletResponse response) {
ServletContext servletContext = (ServletContext) request.getAttribute("servletContext");
HttpSession session = request.getSession();
// add in the OFBiz objects
root.put("delegator", request.getAttribute("delegator"));
root.put("dispatcher", request.getAttribute("dispatcher"));
root.put("security", request.getAttribute("security"));
root.put("userLogin", session.getAttribute("userLogin"));
// add the response object (for transforms) to the context as a BeanModel
root.put("response", response);
// add the application object (for transforms) to the context as a BeanModel
root.put("application", servletContext);
// add the servlet context -- this has been deprecated, and now requires servlet, do we really need it?
// root.put("applicationAttributes", new ServletContextHashModel(servletContext, FreeMarkerWorker.getDefaultOfbizWrapper()));
// add the session object (for transforms) to the context as a BeanModel
root.put("session", session);
// add the session
root.put("sessionAttributes", new HttpSessionHashModel(session, FreeMarkerWorker.getDefaultOfbizWrapper()));
// add the request object (for transforms) to the context as a BeanModel
root.put("request", request);
// add the request
root.put("requestAttributes", new HttpRequestHashModel(request, FreeMarkerWorker.getDefaultOfbizWrapper()));
// add the request parameters -- this now uses a Map from UtilHttp
Map<String, Object> requestParameters = UtilHttp.getParameterMap(request);
root.put("requestParameters", requestParameters);
// add the TabLibFactory
TaglibFactory JspTaglibs = new TaglibFactory(servletContext);
root.put("JspTaglibs", JspTaglibs);
}
use of freemarker.ext.jsp.TaglibFactory in project entando-core by entando.
the class ControllerServlet method createModel.
@Override
protected TemplateModel createModel(ObjectWrapper wrapper, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws TemplateModelException {
TemplateModel template = super.createModel(wrapper, servletContext, request, response);
if (template instanceof AllHttpScopesHashModel) {
AllHttpScopesHashModel hashModel = ((AllHttpScopesHashModel) template);
ServletContextHashModel servletContextModel = (ServletContextHashModel) hashModel.get(KEY_APPLICATION);
if (null == servletContextModel.getServlet()) {
ServletContextHashModel newServletContextModel = new ServletContextHashModel(this, wrapper);
servletContextModel = new ServletContextHashModel(this, wrapper);
servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel);
TaglibFactory taglibs = new TaglibFactory(servletContext);
servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs);
hashModel.putUnlistedModel(KEY_APPLICATION, newServletContextModel);
hashModel.putUnlistedModel(KEY_APPLICATION_PRIVATE, newServletContextModel);
}
}
return template;
}
Aggregations