Search in sources :

Example 1 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class ContentListFilterTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        if (!this.isRightKey()) {
            StringBuilder message = new StringBuilder();
            for (int i = 0; i < IContentListWidgetHelper.allowedMetadataFilterKeys.length; i++) {
                if (i != 0) {
                    message.append(",");
                }
                message.append(IContentListWidgetHelper.allowedMetadataFilterKeys[i]);
            }
            throw new RuntimeException("The key '" + this.getKey() + "' is unknown; " + "Please use a valid one - " + message);
        }
        IContentListWidgetHelper helper = (IContentListWidgetHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_LIST_HELPER, this.pageContext);
        IContentListTagBean parent = (IContentListTagBean) findAncestorWithClass(this, IContentListTagBean.class);
        String contentType = parent.getContentType();
        EntitySearchFilter filter = helper.getFilter(contentType, (IEntityFilterBean) this, reqCtx);
        if (null != filter) {
            parent.addFilter(filter);
        }
    } catch (Throwable t) {
        _logger.error("error in end tag", t);
        throw new JspException("Tag error detected ", t);
    }
    return super.doEndTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IContentListWidgetHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper) IContentListTagBean(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListTagBean) RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 2 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class ContentTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        IContentViewerHelper helper = (IContentViewerHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_VIEWER_HELPER, this.pageContext);
        String contentId = (this.getContentId() != null && this.getContentId().trim().length() > 0) ? this.getContentId() : null;
        ContentRenderizationInfo renderInfo = helper.getRenderizationInfo(contentId, this.getModelId(), this.isPublishExtraTitle(), reqCtx);
        String renderedContent = (null != renderInfo) ? renderInfo.getRenderedContent() : "";
        if (null != this.getVar()) {
            this.pageContext.setAttribute(this.getVar(), renderedContent);
        } else {
            this.pageContext.getOut().print(renderedContent);
        }
        if (null != renderInfo && null != this.getAttributeValuesByRoleVar()) {
            this.pageContext.setAttribute(this.getAttributeValuesByRoleVar(), renderInfo.getAttributeValues());
        }
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        throw new JspException("Error detected while initialising the tag", t);
    }
    return EVAL_PAGE;
}
Also used : ContentRenderizationInfo(com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo) ServletRequest(javax.servlet.ServletRequest) IContentViewerHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 3 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class SearcherTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        String word = request.getParameter("search");
        SearcherTagHelper helper = new SearcherTagHelper();
        List<String> result = helper.executeSearch(word, reqCtx);
        this.pageContext.setAttribute(this.getListName(), result);
        request.setAttribute("search", word);
    } catch (Throwable t) {
        _logger.error("error in do start tag", t);
        // ApsSystemUtils.logThrowable(e, this, "doStartTag");
        throw new JspException("Error detected while initialising the tag", t);
    }
    return SKIP_BODY;
}
Also used : SearcherTagHelper(com.agiletec.plugins.jacms.aps.tags.util.SearcherTagHelper) ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 4 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestContentListHelper method valueRequestContext.

private RequestContext valueRequestContext(String pageCode, int frame) throws Throwable {
    RequestContext reqCtx = this.getRequestContext();
    try {
        Widget widgetToAdd = this.getShowletForTest("content_viewer_list", null);
        this.setPageWidgets(pageCode, frame, widgetToAdd);
        IPage page = this._pageManager.getOnlinePage(pageCode);
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, page);
        Widget widget = page.getWidgets()[frame];
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET, widget);
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME, new Integer(frame));
    } catch (Throwable t) {
        this.setPageWidgets(pageCode, frame, null);
        throw t;
    }
    return reqCtx;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) RequestContext(com.agiletec.aps.system.RequestContext)

Example 5 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestContentListHelper method testGetContents_1.

public void testGetContents_1() throws Throwable {
    String pageCode = "pagina_1";
    int frame = 1;
    try {
        this.setUserOnSession("guest");
        RequestContext reqCtx = this.valueRequestContext(pageCode, frame);
        MockContentListTagBean bean = new MockContentListTagBean();
        bean.setContentType("EVN");
        EntitySearchFilter filter = new EntitySearchFilter("DataInizio", true);
        filter.setOrder(EntitySearchFilter.DESC_ORDER);
        bean.addFilter(filter);
        List<String> contents = this._helper.getContentsId(bean, reqCtx);
        String[] expected = { "EVN194", "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191" };
        assertEquals(expected.length, contents.size());
        for (int i = 0; i < expected.length; i++) {
            assertEquals(expected[i], contents.get(i));
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        this.setPageWidgets(pageCode, frame, null);
    }
}
Also used : RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Aggregations

RequestContext (com.agiletec.aps.system.RequestContext)91 ServletRequest (javax.servlet.ServletRequest)25 JspException (javax.servlet.jsp.JspException)22 IPage (com.agiletec.aps.system.services.page.IPage)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 Lang (com.agiletec.aps.system.services.lang.Lang)10 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)5 Widget (com.agiletec.aps.system.services.page.Widget)5 NavigatorTarget (com.agiletec.aps.system.services.page.widget.NavigatorTarget)5 IURLManager (com.agiletec.aps.system.services.url.IURLManager)5 ContentRenderizationInfo (com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo)5 DataObjectRenderizationInfo (org.entando.entando.aps.system.services.dataobjectdispenser.DataObjectRenderizationInfo)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ControllerManager (com.agiletec.aps.system.services.controller.ControllerManager)3 IPageManager (com.agiletec.aps.system.services.page.IPageManager)3 HeadInfoContainer (com.agiletec.aps.tags.util.HeadInfoContainer)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 IContentListWidgetHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper)3