Search in sources :

Example 6 with ComponentManager

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));
}
Also used : SimpleRenderCondition(com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition) RenderCondition(com.adobe.granite.ui.components.rendercondition.RenderCondition) SimpleRenderCondition(com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition) ExpressionCustomizer(com.adobe.granite.ui.components.ExpressionCustomizer) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ComponentManager(com.day.cq.wcm.api.components.ComponentManager) Resource(org.apache.sling.api.resource.Resource)

Aggregations

ComponentManager (com.day.cq.wcm.api.components.ComponentManager)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 Resource (org.apache.sling.api.resource.Resource)4 Component (com.day.cq.wcm.api.components.Component)3 HashMap (java.util.HashMap)2 List (java.util.List)2 PageRootProvider (com.adobe.acs.commons.wcm.PageRootProvider)1 ComponentExporter (com.adobe.cq.export.json.ComponentExporter)1 SlingModelFilter (com.adobe.cq.export.json.SlingModelFilter)1 Link (com.adobe.cq.wcm.core.components.commons.link.Link)1 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)1 CoreResourceWrapper (com.adobe.cq.wcm.core.components.internal.resource.CoreResourceWrapper)1 Container (com.adobe.cq.wcm.core.components.models.Container)1 ListItem (com.adobe.cq.wcm.core.components.models.ListItem)1 ContainerData (com.adobe.cq.wcm.core.components.models.datalayer.ContainerData)1 DataLayerBuilder (com.adobe.cq.wcm.core.components.models.datalayer.builder.DataLayerBuilder)1 AbstractComponentImpl (com.adobe.cq.wcm.core.components.util.AbstractComponentImpl)1 ExpressionCustomizer (com.adobe.granite.ui.components.ExpressionCustomizer)1 RenderCondition (com.adobe.granite.ui.components.rendercondition.RenderCondition)1 SimpleRenderCondition (com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition)1