Search in sources :

Example 86 with RequestContext

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

the class I18nTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    RequestContext reqCtx = (RequestContext) this.pageContext.getRequest().getAttribute(RequestContext.REQCTX);
    try {
        Lang currentLang = null;
        if (reqCtx != null) {
            currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        } else {
            ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
            currentLang = langManager.getDefaultLang();
        }
        String label = this.extractLabel(currentLang);
        if (this._varName != null) {
            this.pageContext.setAttribute(this._varName, label);
        } else {
            if (this.getEscapeXml()) {
                out(this.pageContext, this.getEscapeXml(), label);
            } else {
                this.pageContext.getOut().print(label);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        throw new JspException("Error during tag initialization", t);
    }
    return super.doStartTag();
}
Also used : JspException(javax.servlet.jsp.JspException) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 87 with RequestContext

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

the class InternalServletTag method doEndTag.

/**
 * Invokes the widget configured in the current page.
 *
 * @throws JspException in case of error that occurred in both this method
 * or in one of the included JSPs
 */
@Override
public int doEndTag() throws JspException {
    int result = super.doEndTag();
    ServletRequest req = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
    try {
        IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        ResponseWrapper responseWrapper = new ResponseWrapper((HttpServletResponse) this.pageContext.getResponse());
        String output = this.buildWidgetOutput(page, responseWrapper);
        if (responseWrapper.isRedirected()) {
            String redirect = responseWrapper.getRedirectPath();
            reqCtx.addExtraParam(SystemConstants.EXTRAPAR_EXTERNAL_REDIRECT, redirect);
            result = SKIP_PAGE;
        } else {
            this.pageContext.getOut().print(output);
        }
    } catch (Throwable t) {
        _logger.error("Error in widget preprocessing", t);
        String msg = "Error in widget preprocessing";
        throw new JspException(msg, t);
    }
    return result;
}
Also used : ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) IPage(com.agiletec.aps.system.services.page.IPage) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) RequestContext(com.agiletec.aps.system.RequestContext)

Example 88 with RequestContext

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

the class PageInfoTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    try {
        IPageManager pageManager = (IPageManager) ApsWebApplicationUtils.getBean(SystemConstants.PAGE_MANAGER, this.pageContext);
        IPage page = pageManager.getOnlinePage(this.getPageCode());
        if (null == page) {
            _logger.error("Required info for null page : inserted code '{}'", this.getPageCode());
        }
        if (this.getInfo() == null || this.getInfo().equals(CODE_INFO)) {
            this.setValue(page.getCode());
        } else if (this.getInfo().equals(TITLE_INFO)) {
            this.extractPageTitle(page, currentLang);
        } else if (this.getInfo().equals(URL_INFO)) {
            this.extractPageUrl(page, currentLang, reqCtx);
        } else if (this.getInfo().equals(OWNER_INFO)) {
            this.extractPageOwner(page, reqCtx);
        } else if (this.getInfo().equals(CHILD_OF_INFO)) {
            this.extractIsChildOfTarget(page);
        } else if (this.getInfo().equals(HAS_CHILD)) {
            boolean hasChild = (page.getChildrenCodes() != null && page.getChildrenCodes().length > 0);
            this._value = new Boolean(hasChild).toString();
        }
        this.evalValue();
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error during tag initialization ", t);
    }
    this.release();
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) IPageManager(com.agiletec.aps.system.services.page.IPageManager) JspException(javax.servlet.jsp.JspException) IPage(com.agiletec.aps.system.services.page.IPage) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 89 with RequestContext

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

the class PagerTagHelper method getMaxElementForItem.

protected int getMaxElementForItem(int maxItems, ServletRequest request) {
    if (maxItems == 0) {
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        if (reqCtx != null) {
            Widget widget = (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET);
            ApsProperties config = widget.getConfig();
            String stringMax = (null != config) ? (String) config.get("maxElemForItem") : null;
            if (stringMax != null && stringMax.length() > 0) {
                maxItems = Integer.parseInt(stringMax);
            }
        }
    }
    return maxItems;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) RequestContext(com.agiletec.aps.system.RequestContext) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

RequestContext (com.agiletec.aps.system.RequestContext)89 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)12 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 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 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ControllerManager (com.agiletec.aps.system.services.controller.ControllerManager)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 IContentViewerHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper)3