freemarker.ext.servlet.HttpRequestHashModel Java Examples

The following examples show how to use freemarker.ext.servlet.HttpRequestHashModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTestExecutorService.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected TemplateModel createModel(ObjectWrapper wrapper) throws Throwable {
	HttpServletRequest request = super.getRequestContext().getRequest();
	HttpServletResponse response = super.getRequestContext().getResponse();
	ServletContext servletContext = request.getSession().getServletContext();
	AllHttpScopesHashModel hashModel = new AllHttpScopesHashModel(wrapper, servletContext, request); //super.createModel(wrapper, servletContext, request, response);
	ControllerServlet servlet = new ControllerServlet();
	MockServletConfig config = new MockServletConfig(servletContext);
	servlet.init(config);
	ServletContextHashModel newServletContextModel = new ServletContextHashModel(servlet, wrapper);
	ServletContextHashModel servletContextModel = new ServletContextHashModel(servlet, wrapper);
	servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel);
	TaglibFactory taglibs = new TaglibFactory(servletContext);
	servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_APPLICATION, newServletContextModel);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_APPLICATION_PRIVATE, newServletContextModel);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_JSP_TAGLIBS, taglibs);
	HttpRequestHashModel requestModel = new HttpRequestHashModel(request, response, wrapper);
       request.setAttribute(ATTR_REQUEST_MODEL, requestModel);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_REQUEST_PRIVATE, requestModel);
	return hashModel;
}
 
Example #2
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Build a FreeMarker template model for the given model Map.
 * <p>The default implementation builds a {@link AllHttpScopesHashModel}.
 * @param model the model to use for rendering
 * @param request current HTTP request
 * @param response current servlet response
 * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof
 */
protected SimpleHash buildTemplateModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) {

	AllHttpScopesHashModel fmModel = new AllHttpScopesHashModel(getObjectWrapper(), getServletContext(), request);
	fmModel.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory);
	fmModel.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel);
	fmModel.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response));
	fmModel.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper()));
	fmModel.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request));
	fmModel.putAll(model);
	return fmModel;
}
 
Example #3
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Build a FreeMarker template model for the given model Map.
 * <p>The default implementation builds a {@link AllHttpScopesHashModel}.
 * @param model the model to use for rendering
 * @param request current HTTP request
 * @param response current servlet response
 * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof
 */
protected SimpleHash buildTemplateModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) {

	AllHttpScopesHashModel fmModel = new AllHttpScopesHashModel(getObjectWrapper(), getServletContext(), request);
	fmModel.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory);
	fmModel.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel);
	fmModel.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response));
	fmModel.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper()));
	fmModel.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request));
	fmModel.putAll(model);
	return fmModel;
}
 
Example #4
Source File: FreeMarkerView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a FreeMarker template model for the given model Map.
 * <p>The default implementation builds a {@link AllHttpScopesHashModel}.
 * @param model the model to use for rendering
 * @param request current HTTP request
 * @param response current servlet response
 * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof
 */
protected SimpleHash buildTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
	AllHttpScopesHashModel fmModel = new AllHttpScopesHashModel(getObjectWrapper(), getServletContext(), request);
	fmModel.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory);
	fmModel.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel);
	fmModel.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response));
	fmModel.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper()));
	fmModel.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request));
	fmModel.putAll(model);
	return fmModel;
}
 
Example #5
Source File: FreeMarkerViewHandler.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static void prepOfbizRoot(Map<String, Object> root, HttpServletRequest request, HttpServletResponse response) {
    ServletContext servletContext = request.getServletContext(); // SCIPIO: get context using servlet API 3.0
    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);

}
 
Example #6
Source File: FreeMarkerView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Build a FreeMarker template model for the given model Map.
 * <p>The default implementation builds a {@link AllHttpScopesHashModel}.
 * @param model the model to use for rendering
 * @param request current HTTP request
 * @param response current servlet response
 * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof
 */
protected SimpleHash buildTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
	AllHttpScopesHashModel fmModel = new AllHttpScopesHashModel(getObjectWrapper(), getServletContext(), request);
	fmModel.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory);
	fmModel.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel);
	fmModel.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response));
	fmModel.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper()));
	fmModel.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request));
	fmModel.putAll(model);
	return fmModel;
}
 
Example #7
Source File: DirectivesUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static HttpServletRequest getRequest(Environment env){
	HttpRequestHashModel req = (HttpRequestHashModel) getVariable(env, REQUEST, true);
	return req.getRequest();
}