Search in sources :

Example 1 with AllHttpScopesHashModel

use of freemarker.ext.servlet.AllHttpScopesHashModel in project entando-core by entando.

the class AbstractTestExecutorService method createModel.

protected TemplateModel createModel(ObjectWrapper wrapper) throws Throwable {
    HttpServletRequest request = super.getRequestContext().getRequest();
    HttpServletResponse response = super.getRequestContext().getResponse();
    ServletContext servletContext = request.getSession().getServletContext();
    // super.createModel(wrapper, servletContext, request, response);
    AllHttpScopesHashModel hashModel = new AllHttpScopesHashModel(wrapper, servletContext, request);
    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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AllHttpScopesHashModel(freemarker.ext.servlet.AllHttpScopesHashModel) HttpRequestHashModel(freemarker.ext.servlet.HttpRequestHashModel) ServletContextHashModel(freemarker.ext.servlet.ServletContextHashModel) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) MockServletConfig(org.springframework.mock.web.MockServletConfig) TaglibFactory(freemarker.ext.jsp.TaglibFactory) ControllerServlet(org.entando.entando.aps.servlet.ControllerServlet)

Example 2 with AllHttpScopesHashModel

use of freemarker.ext.servlet.AllHttpScopesHashModel in project entando-core by entando.

the class FreemarkerTemplateParameterTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
        TemplateModel templateModel = ebc.getTemplateModel();
        if (!(templateModel instanceof AllHttpScopesHashModel)) {
            return EVAL_BODY_INCLUDE;
        }
        AllHttpScopesHashModel hashModel = (AllHttpScopesHashModel) templateModel;
        Object object = this.pageContext.getAttribute(this.getValueName());
        if (null == object) {
            Environment environment = Environment.getCurrentEnvironment();
            if (null != environment) {
                Object wrapper = environment.getVariable(this.getValueName());
                if (null != wrapper) {
                    if (wrapper instanceof StringModel) {
                        object = ((StringModel) wrapper).getWrappedObject();
                    } else {
                        object = wrapper;
                    }
                }
            }
        }
        if (null != object) {
            hashModel.put(this.getVar(), object);
        }
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        throw new JspException("Error during tag initialization", t);
    }
    return EVAL_BODY_INCLUDE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) AllHttpScopesHashModel(freemarker.ext.servlet.AllHttpScopesHashModel) Environment(freemarker.core.Environment) RequestContext(com.agiletec.aps.system.RequestContext) TemplateModel(freemarker.template.TemplateModel) StringModel(freemarker.ext.beans.StringModel) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)

Example 3 with AllHttpScopesHashModel

use of freemarker.ext.servlet.AllHttpScopesHashModel in project entando-core by entando.

the class FreemarkerTemplateParameterTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    if (this.isRemoveOnEndTag()) {
        ServletRequest request = this.pageContext.getRequest();
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        try {
            ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
            TemplateModel templateModel = ebc.getTemplateModel();
            if (templateModel instanceof AllHttpScopesHashModel) {
                AllHttpScopesHashModel hashModel = (AllHttpScopesHashModel) templateModel;
                hashModel.remove(this.getVar());
            }
        } catch (Throwable t) {
            _logger.error("error in doEndTag", t);
            throw new JspException("Error evaluating di end tag", t);
        }
    }
    this.release();
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) AllHttpScopesHashModel(freemarker.ext.servlet.AllHttpScopesHashModel) RequestContext(com.agiletec.aps.system.RequestContext) TemplateModel(freemarker.template.TemplateModel) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)

Example 4 with AllHttpScopesHashModel

use of freemarker.ext.servlet.AllHttpScopesHashModel 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;
}
Also used : AllHttpScopesHashModel(freemarker.ext.servlet.AllHttpScopesHashModel) ServletContextHashModel(freemarker.ext.servlet.ServletContextHashModel) TaglibFactory(freemarker.ext.jsp.TaglibFactory) TemplateModel(freemarker.template.TemplateModel)

Aggregations

AllHttpScopesHashModel (freemarker.ext.servlet.AllHttpScopesHashModel)4 TemplateModel (freemarker.template.TemplateModel)3 RequestContext (com.agiletec.aps.system.RequestContext)2 TaglibFactory (freemarker.ext.jsp.TaglibFactory)2 ServletContextHashModel (freemarker.ext.servlet.ServletContextHashModel)2 ServletRequest (javax.servlet.ServletRequest)2 JspException (javax.servlet.jsp.JspException)2 ExecutorBeanContainer (org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)2 Environment (freemarker.core.Environment)1 StringModel (freemarker.ext.beans.StringModel)1 HttpRequestHashModel (freemarker.ext.servlet.HttpRequestHashModel)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ControllerServlet (org.entando.entando.aps.servlet.ControllerServlet)1 MockServletConfig (org.springframework.mock.web.MockServletConfig)1