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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations