Search in sources :

Example 1 with ExecutorBeanContainer

use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer 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 2 with ExecutorBeanContainer

use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer 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 3 with ExecutorBeanContainer

use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.

the class ControllerServlet method initFreemarker.

protected void initFreemarker(HttpServletRequest request, HttpServletResponse response, RequestContext reqCtx) throws TemplateModelException {
    Configuration config = new Configuration();
    DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
    config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    config.setObjectWrapper(wrapper);
    config.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);
    TemplateModel templateModel = this.createModel(wrapper, this.getServletContext(), request, response);
    ExecutorBeanContainer ebc = new ExecutorBeanContainer(config, templateModel);
    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER, ebc);
}
Also used : Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) TemplateModel(freemarker.template.TemplateModel) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)

Example 4 with ExecutorBeanContainer

use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.

the class GuiFragmentResult method doExecute.

/**
 * Execute this result, using the specified fragment.
 * @param code The code of the fragment
 * @param invocation The invocation
 */
@Override
public void doExecute(String code, ActionInvocation invocation) throws Exception {
    if (null == code) {
        code = conditionalParse(this._code, invocation);
    }
    if (null == code) {
        this.executeDispatcherResult(invocation);
        return;
    }
    ActionContext ctx = invocation.getInvocationContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req);
    try {
        GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code);
        String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null;
        if (StringUtils.isBlank(output)) {
            _logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace());
            boolean execution = this.executeDispatcherResult(invocation);
            if (!execution) {
                output = "The fragment '" + code + "' is not available";
            } else {
                return;
            }
        }
        RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
        ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
        Writer writer = this.getWriter();
        Template template = new Template(code, new StringReader(output), ebc.getConfiguration());
        template.process(ebc.getTemplateModel(), writer);
    } catch (Throwable t) {
        _logger.error("Error processing GuiFragment result!", t);
        throw new RuntimeException("Error processing GuiFragment result!", t);
    }
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Template(freemarker.template.Template) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringReader(java.io.StringReader) RequestContext(com.agiletec.aps.system.RequestContext) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer) Writer(java.io.Writer)

Example 5 with ExecutorBeanContainer

use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.

the class GuiFragmentTag method extractFragmentOutput.

protected String extractFragmentOutput(RequestContext reqCtx) throws ApsSystemException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, this.pageContext);
        GuiFragment guiFragment = guiFragmentManager.getGuiFragment(this.getCode());
        if (null == guiFragment || StringUtils.isBlank(guiFragment.getCurrentGui())) {
            return null;
        }
        ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
        Writer out = new OutputStreamWriter(baos);
        Template template = new Template(this.getCode(), new StringReader(guiFragment.getCurrentGui()), ebc.getConfiguration());
        template.process(ebc.getTemplateModel(), out);
        out.flush();
    } catch (Throwable t) {
        String msg = "Error creating fragment output - code '" + this.getCode() + "'";
        _logger.error(msg, t);
        throw new ApsSystemException(msg, t);
    }
    return baos.toString();
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) StringReader(java.io.StringReader) OutputStreamWriter(java.io.OutputStreamWriter) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Template(freemarker.template.Template)

Aggregations

ExecutorBeanContainer (org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)6 TemplateModel (freemarker.template.TemplateModel)4 RequestContext (com.agiletec.aps.system.RequestContext)3 AllHttpScopesHashModel (freemarker.ext.servlet.AllHttpScopesHashModel)2 Configuration (freemarker.template.Configuration)2 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)2 Template (freemarker.template.Template)2 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 ServletRequest (javax.servlet.ServletRequest)2 JspException (javax.servlet.jsp.JspException)2 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)2 IGuiFragmentManager (org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 ActionContext (com.opensymphony.xwork2.ActionContext)1 Environment (freemarker.core.Environment)1 StringModel (freemarker.ext.beans.StringModel)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1