Search in sources :

Example 1 with IGuiFragmentManager

use of org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager in project entando-core by entando.

the class AbstractWidgetExecutorService method extractFragmentOutput.

protected String extractFragmentOutput(String fragmentCode, RequestContext reqCtx) throws Throwable {
    if (StringUtils.isBlank(fragmentCode)) {
        return null;
    }
    IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, reqCtx.getRequest());
    GuiFragment fragment = guiFragmentManager.getGuiFragment(fragmentCode);
    return extractFragmentOutput(fragment, reqCtx);
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment)

Example 2 with IGuiFragmentManager

use of org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager 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)

Example 3 with IGuiFragmentManager

use of org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager 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 4 with IGuiFragmentManager

use of org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager in project entando-core by entando.

the class AbstractWidgetExecutorService method extractWidgetOutput.

public static String extractWidgetOutput(RequestContext reqCtx, WidgetType type) throws ApsSystemException {
    if (null == type) {
        return "";
    }
    String widgetTypeCode = (type.isLogic()) ? type.getParentType().getCode() : type.getCode();
    try {
        IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, reqCtx.getRequest());
        GuiFragment guiFragment = guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
        if (null != guiFragment) {
            String fragmentOutput = extractFragmentOutput(guiFragment, reqCtx);
            if (StringUtils.isBlank(fragmentOutput)) {
                _logger.info("The fragment '{}' of widget '{}' is not available", guiFragment.getCode(), widgetTypeCode);
                return "The fragment '" + guiFragment.getCode() + "' of widget '" + widgetTypeCode + "' is not available";
            }
            return fragmentOutput;
        } else {
            String widgetJspPath = type.getJspPath();
            return extractJspWidgetOutput(widgetTypeCode, reqCtx, widgetJspPath);
        }
    } catch (Throwable t) {
        String msg = "Error creating widget output - Type '" + widgetTypeCode + "'";
        _logger.error(msg, t);
        throw new ApsSystemException(msg, t);
    }
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Aggregations

GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)4 IGuiFragmentManager (org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 Template (freemarker.template.Template)2 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 ExecutorBeanContainer (org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)2 RequestContext (com.agiletec.aps.system.RequestContext)1 ActionContext (com.opensymphony.xwork2.ActionContext)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ServletActionContext (org.apache.struts2.ServletActionContext)1