Search in sources :

Example 1 with IFrameDecoratorContainer

use of com.agiletec.aps.tags.util.IFrameDecoratorContainer in project entando-core by entando.

the class AbstractWidgetExecutorService method extractDecoratorsOutput.

protected String extractDecoratorsOutput(RequestContext reqCtx, Widget widget, List<IFrameDecoratorContainer> decorators, boolean isWidgetDecorator, boolean includeHeader) throws Throwable {
    if (null == decorators || decorators.isEmpty()) {
        return "";
    }
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < decorators.size(); i++) {
        IFrameDecoratorContainer decoratorContainer = (includeHeader) ? decorators.get(i) : decorators.get(decorators.size() - i - 1);
        if ((isWidgetDecorator != decoratorContainer.isWidgetDecorator()) || !decoratorContainer.needsDecoration(widget, reqCtx)) {
            continue;
        }
        String fragmentCode = (includeHeader) ? decoratorContainer.getHeaderFragmentCode() : decoratorContainer.getFooterFragmentCode();
        String fragmentOutput = extractFragmentOutput(fragmentCode, reqCtx);
        if (StringUtils.isNotBlank(fragmentCode)) {
            builder.append(fragmentOutput);
        } else {
            String jspPath = (includeHeader) ? decoratorContainer.getHeaderJspPath() : decoratorContainer.getFooterJspPath();
            if (StringUtils.isNotBlank(jspPath)) {
                String output = extractJspOutput(reqCtx, jspPath);
                builder.append(output);
            }
        }
    }
    return builder.toString();
}
Also used : IFrameDecoratorContainer(com.agiletec.aps.tags.util.IFrameDecoratorContainer)

Example 2 with IFrameDecoratorContainer

use of com.agiletec.aps.tags.util.IFrameDecoratorContainer in project entando-core by entando.

the class AbstractWidgetExecutorService method buildWidgetsOutput.

protected void buildWidgetsOutput(RequestContext reqCtx, IPage page, String[] widgetOutput) throws ApsSystemException {
    try {
        List<IFrameDecoratorContainer> decorators = this.extractDecorators(reqCtx);
        Widget[] widgets = page.getWidgets();
        for (int frame = 0; frame < widgets.length; frame++) {
            reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME, new Integer(frame));
            Widget widget = widgets[frame];
            widgetOutput[frame] = this.buildWidgetOutput(reqCtx, widget, decorators);
        }
    } catch (Throwable t) {
        String msg = "Error detected during widget preprocessing";
        _logger.error(msg, t);
        throw new ApsSystemException(msg, t);
    }
}
Also used : IFrameDecoratorContainer(com.agiletec.aps.tags.util.IFrameDecoratorContainer) Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 3 with IFrameDecoratorContainer

use of com.agiletec.aps.tags.util.IFrameDecoratorContainer in project entando-core by entando.

the class AbstractWidgetExecutorService method extractDecorators.

protected List<IFrameDecoratorContainer> extractDecorators(RequestContext reqCtx) throws ApsSystemException {
    HttpServletRequest request = reqCtx.getRequest();
    WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
    List<IFrameDecoratorContainer> containters = new ArrayList<IFrameDecoratorContainer>();
    try {
        String[] beanNames = wac.getBeanNamesForType(IFrameDecoratorContainer.class);
        for (int i = 0; i < beanNames.length; i++) {
            IFrameDecoratorContainer container = (IFrameDecoratorContainer) wac.getBean(beanNames[i]);
            containters.add(container);
        }
        BeanComparator comparator = new BeanComparator("order");
        Collections.sort(containters, comparator);
    } catch (Throwable t) {
        _logger.error("Error extracting widget decorators", t);
        throw new ApsSystemException("Error extracting widget decorators", t);
    }
    return containters;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IFrameDecoratorContainer(com.agiletec.aps.tags.util.IFrameDecoratorContainer) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeanComparator(org.apache.commons.beanutils.BeanComparator) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

IFrameDecoratorContainer (com.agiletec.aps.tags.util.IFrameDecoratorContainer)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 Widget (com.agiletec.aps.system.services.page.Widget)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1