use of com.adobe.granite.ui.components.ExpressionCustomizer in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageDelegateRenderConditionTest method testDoGet.
@Test
public void testDoGet() throws Exception {
ImageDelegateRenderCondition imageDelegateRenderCondition = new ImageDelegateRenderCondition();
context.requestPathInfo().setSuffix(SUFFIX);
imageDelegateRenderCondition.doGet(context.request(), context.response());
RenderCondition renderCondition = (RenderCondition) context.request().getAttribute(RenderCondition.class.getName());
assertNotNull(renderCondition);
assertTrue(renderCondition.check());
ExpressionCustomizer expressionCustomizer = (ExpressionCustomizer) context.request().getAttribute(ExpressionCustomizer.class.getName());
assertNotNull(expressionCustomizer);
assertTrue(expressionCustomizer.hasVariable(AbstractImageDelegatingModel.IMAGE_DELEGATE));
}
use of com.adobe.granite.ui.components.ExpressionCustomizer 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