use of com.day.cq.wcm.api.components.ComponentManager 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