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;
}
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;
}
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;
}
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;
}
Aggregations