Search in sources :

Example 1 with SimpleRenderCondition

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));
}
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) Config(com.adobe.granite.ui.components.Config) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 2 with SimpleRenderCondition

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

RenderCondition (com.adobe.granite.ui.components.rendercondition.RenderCondition)2 SimpleRenderCondition (com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition)2 Resource (org.apache.sling.api.resource.Resource)2 Config (com.adobe.granite.ui.components.Config)1 ExpressionCustomizer (com.adobe.granite.ui.components.ExpressionCustomizer)1 ComponentManager (com.day.cq.wcm.api.components.ComponentManager)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ValueMap (org.apache.sling.api.resource.ValueMap)1