Search in sources :

Example 76 with RequestContext

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

the class ContentInfoTag 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);
        PublicContentAuthorizationInfo authInfo = helper.getAuthorizationInfo(this.getContentId(), reqCtx);
        if (null == authInfo) {
            return super.doStartTag();
        }
        if (null == this.getParam() && null != this.getVar()) {
            this.pageContext.setAttribute(this.getVar(), authInfo);
        } else if (null != this.getParam()) {
            Object value = null;
            if ("contentId".equals(this.getParam())) {
                value = authInfo.getContentId();
            } else if ("modelId".equals(this.getParam())) {
                value = this.extractModelId(authInfo, reqCtx);
            } else if ("mainGroup".equals(this.getParam())) {
                value = authInfo.getMainGroup();
            } else if ("authToEdit".equals(this.getParam())) {
                IContentAuthorizationHelper contentAuthHelper = (IContentAuthorizationHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_AUTHORIZATION_HELPER, this.pageContext);
                HttpSession session = this.pageContext.getSession();
                UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
                boolean isAuth = contentAuthHelper.isAuthToEdit(currentUser, authInfo);
                value = Boolean.valueOf(isAuth);
            }
            if (null != value) {
                String var = this.getVar();
                if (null == var || "".equals(var)) {
                    this.pageContext.getOut().print(value);
                } else {
                    this.pageContext.setAttribute(this.getVar(), value);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error detected while initializing the tag", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error detected while initializing the tag", t);
    }
    return super.doStartTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) IContentViewerHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper) JspException(javax.servlet.jsp.JspException) PublicContentAuthorizationInfo(com.agiletec.plugins.jacms.aps.system.services.content.helper.PublicContentAuthorizationInfo) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession) RequestContext(com.agiletec.aps.system.RequestContext) IContentAuthorizationHelper(com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper)

Example 77 with RequestContext

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

the class ContentListTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        IContentListWidgetHelper helper = (IContentListWidgetHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_LIST_HELPER, this.pageContext);
        List<UserFilterOptionBean> defaultUserFilterOptions = helper.getConfiguredUserFilters(this, reqCtx);
        this.addUserFilterOptions(defaultUserFilterOptions);
        this.extractExtraWidgetParameters(reqCtx);
        if (null != this.getUserFilterOptions() && null != this.getUserFilterOptionsVar()) {
            this.pageContext.setAttribute(this.getUserFilterOptionsVar(), this.getUserFilterOptions());
        }
        List<String> contents = this.getContentsId(helper, reqCtx);
        this.pageContext.setAttribute(this.getListName(), contents);
    } catch (Throwable t) {
        _logger.error("error in end tag", t);
        throw new JspException("Error detected while finalising the tag", t);
    }
    this.release();
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IContentListWidgetHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper) UserFilterOptionBean(com.agiletec.plugins.jacms.aps.system.services.content.widget.UserFilterOptionBean) RequestContext(com.agiletec.aps.system.RequestContext)

Example 78 with RequestContext

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

the class ContentListUserFilterOptionTag 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.allowedMetadataUserFilterOptionKeys.length; i++) {
                if (i != 0)
                    message.append(",");
                message.append(IContentListWidgetHelper.allowedMetadataUserFilterOptionKeys[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();
        UserFilterOptionBean filter = helper.getUserFilterOption(contentType, this, reqCtx);
        if (null != filter) {
            parent.addUserFilterOption(filter);
        }
    } catch (Throwable t) {
        _logger.error("error in do end tag", t);
        // ApsSystemUtils.logThrowable(t, this, "doEndTag");
        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) UserFilterOptionBean(com.agiletec.plugins.jacms.aps.system.services.content.widget.UserFilterOptionBean) RequestContext(com.agiletec.aps.system.RequestContext)

Example 79 with RequestContext

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

the class BaseContentRenderer method render.

@Override
public String render(Content content, long modelId, String langCode, RequestContext reqCtx) {
    String renderedEntity = null;
    List<TextAttributeCharReplaceInfo> conversions = null;
    try {
        conversions = this.convertSpecialCharacters(content, langCode);
        String contentModel = this.getModelShape(modelId);
        Context velocityContext = new VelocityContext();
        ContentWrapper contentWrapper = (ContentWrapper) this.getEntityWrapper(content);
        contentWrapper.setRenderingLang(langCode);
        contentWrapper.setReqCtx(reqCtx);
        velocityContext.put(this.getEntityWrapperContextName(), contentWrapper);
        I18nManagerWrapper i18nWrapper = new I18nManagerWrapper(langCode, this.getI18nManager());
        velocityContext.put("i18n", i18nWrapper);
        SystemInfoWrapper systemInfoWrapper = new SystemInfoWrapper(reqCtx);
        velocityContext.put("info", systemInfoWrapper);
        StringWriter stringWriter = new StringWriter();
        boolean isEvaluated = Velocity.evaluate(velocityContext, stringWriter, "render", contentModel);
        if (!isEvaluated) {
            throw new ApsSystemException("Error rendering content");
        }
        stringWriter.flush();
        renderedEntity = stringWriter.toString();
    } catch (Throwable t) {
        _logger.error("Error rendering content", t);
        // ApsSystemUtils.logThrowable(t, this, "render", "Error rendering content");
        renderedEntity = "";
    } finally {
        if (null != conversions) {
            this.replaceSpecialCharacters(conversions);
        }
    }
    return renderedEntity;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) RequestContext(com.agiletec.aps.system.RequestContext) Context(org.apache.velocity.context.Context) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) TextAttributeCharReplaceInfo(com.agiletec.aps.system.common.renderer.TextAttributeCharReplaceInfo) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) I18nManagerWrapper(com.agiletec.aps.system.services.i18n.I18nManagerWrapper)

Example 80 with RequestContext

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

the class ActionURLTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    IURLManager urlManager = (IURLManager) ApsWebApplicationUtils.getBean(SystemConstants.URL_MANAGER, this.pageContext);
    try {
        PageURL pageUrl = urlManager.createURL(reqCtx);
        IPage currPage = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
        pageUrl.setPage(currPage);
        pageUrl.addParam(InternalServletTag.REQUEST_PARAM_ACTIONPATH, this.getPath());
        pageUrl.addParam(InternalServletTag.REQUEST_PARAM_FRAMEDEST, currentFrame.toString());
        if (null != this.getParameters()) {
            Iterator<String> iter = this.getParameters().keySet().iterator();
            while (iter.hasNext()) {
                String name = (String) iter.next();
                pageUrl.addParam(name, this.getParameters().get(name));
            }
        }
        String path = pageUrl.getURL();
        if (null != this.getVar()) {
            this.pageContext.setAttribute(this.getVar(), path);
        } else {
            this.pageContext.getOut().print(path);
        }
    } catch (IOException e) {
        _logger.error("Error closing tag", e);
        // ApsSystemUtils.logThrowable(e, this, "doEndTag");
        throw new JspException("Error closing tag ", e);
    }
    this.release();
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IPage(com.agiletec.aps.system.services.page.IPage) PageURL(com.agiletec.aps.system.services.url.PageURL) IURLManager(com.agiletec.aps.system.services.url.IURLManager) RequestContext(com.agiletec.aps.system.RequestContext) IOException(java.io.IOException)

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