use of com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ElementNamesRenderCondition method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
// return false by default
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(false));
// get component path
Config config = new Config(request.getResource());
String componentPath = getParameter(config, request, PN_COMPONENT_PATH, String.class);
if (componentPath == null) {
return;
}
// get component resource
Resource component = request.getResourceResolver().getResource(componentPath);
if (component == null) {
return;
}
// override fragment path if set
ValueMap properties = component.getValueMap();
String displayMode = properties.get(PARAM_AND_PN_DISPLAY_MODE, String.class);
String displayModeParam = request.getParameter(PARAM_AND_PN_DISPLAY_MODE);
if (displayModeParam != null) {
displayMode = displayModeParam;
}
boolean shouldShow = displayMode != null && displayMode.equals(getParameter(config, request, PARAM_AND_PN_DISPLAY_MODE, String.class));
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(shouldShow));
}
use of com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageDelegateRenderCondition method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
boolean hasImageDelegation = false;
ResourceResolver resourceResolver = request.getResourceResolver();
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
String suffix = request.getRequestPathInfo().getSuffix();
if (componentManager != null && StringUtils.isNotEmpty(suffix)) {
Resource policiesRootPage = getPoliciesRootPage(resourceResolver, suffix);
if (policiesRootPage != null) {
String resourceType = suffix.substring(policiesRootPage.getPath().length() + 1, suffix.lastIndexOf('/'));
com.day.cq.wcm.api.components.Component component = componentManager.getComponent(resourceType);
if (component != null && component.isAccessible()) {
String imageDelegate = component.getProperties().get(AbstractImageDelegatingModel.IMAGE_DELEGATE, String.class);
if (StringUtils.isNotEmpty(imageDelegate)) {
hasImageDelegation = true;
com.day.cq.wcm.api.components.Component delegate = componentManager.getComponent(imageDelegate);
if (delegate != null && delegate.isAccessible()) {
ExpressionCustomizer customizer = ExpressionCustomizer.from(request);
customizer.setVariable(AbstractImageDelegatingModel.IMAGE_DELEGATE, delegate);
}
}
}
}
}
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(hasImageDelegation));
}
Aggregations