use of com.day.cq.wcm.api.components.Component in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class NavigationItemImplTest method test.
@Test
protected void test() {
Page page = mock(Page.class);
when(page.getProperties()).thenReturn(ValueMap.EMPTY);
LinkHandler linkHandler = mock(LinkHandler.class);
Component component = mock(Component.class);
NavigationItemImpl navigationItem = new NavigationItemImpl(page, true, true, linkHandler, 0, Collections.emptyList(), "id", component);
assertEquals(page, navigationItem.getPage());
assertTrue(navigationItem.isActive());
assertEquals(Collections.emptyList(), navigationItem.getChildren());
assertEquals(0, navigationItem.getLevel());
}
use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class UrlFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse) {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
RequestPathInfo pathInfo = slingRequest.getRequestPathInfo();
Component definitionComponent = findUrlFilterDefinitionComponent(slingRequest.getResource(), slingRequest.getResourceResolver().adaptTo(ComponentManager.class));
if (definitionComponent != null) {
String definitionPath = definitionComponent.getPath();
log.debug("found url filter definition resource at {}", definitionPath);
ValueMap properties = definitionComponent.getProperties();
if (properties != null) {
if (checkSelector(pathInfo, properties) && checkSuffix(pathInfo, properties) && checkExtension(pathInfo, properties)) {
log.debug("url filter definition resource at {} passed for request {}.", definitionPath, slingRequest.getRequestPathInfo());
} else {
log.info("url filter definition resource at {} FAILED for request {}.", definitionPath, slingRequest.getRequestPathInfo());
slingResponse.sendError(403);
return;
}
}
}
}
chain.doFilter(request, response);
}
use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class PlaceholderTag method doEndTag.
/**
* {@inheritDoc}
*/
@Override
public int doEndTag() throws JspException {
SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
Component component = WCMUtils.getComponent(request.getResource());
if (componentHelper.isEditMode(request)) {
JspWriter writer = pageContext.getOut();
String placeholder;
String bodyContentString = bodyContent != null ? bodyContent.getString() : null;
if (StringUtils.isNotBlank(bodyContentString)) {
// use the body content as the default placeholder
placeholder = Placeholder.getDefaultPlaceholder(request, component, bodyContentString, getDdClass());
} else {
String classicUIPlaceholder = componentHelper.generateClassicUIPlaceholder(getAllClassNames(), null);
placeholder = Placeholder.getDefaultPlaceholder(request, component, classicUIPlaceholder, getDdClass());
}
try {
writer.print(placeholder);
} catch (IOException e) {
throw new JspException(e);
}
}
reset();
return EVAL_PAGE;
}
use of com.day.cq.wcm.api.components.Component in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class Editor method readChildren.
private void readChildren() {
items = new ArrayList<>();
String containerPath = request.getRequestPathInfo().getSuffix();
if (StringUtils.isNotEmpty(containerPath)) {
ResourceResolver resolver = request.getResourceResolver();
container = resolver.getResource(containerPath);
if (container != null) {
ComponentManager componentManager = request.getResourceResolver().adaptTo(ComponentManager.class);
if (componentManager != null) {
for (Resource resource : container.getChildren()) {
if (resource != null) {
Component component = componentManager.getComponentOfResource(resource);
if (component != null) {
items.add(new Item(request, resource));
}
}
}
}
}
}
}
use of com.day.cq.wcm.api.components.Component in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class CarouselImplTest method getCarouselUnderTest.
private Carousel getCarouselUnderTest(@NotNull final String resourcePath) {
Utils.enableDataLayer(context, true);
context.currentResource(Objects.requireNonNull(context.resourceResolver().getResource(resourcePath)));
Component component = mock(Component.class);
when(component.getResourceType()).thenReturn(CarouselImpl.RESOURCE_TYPE);
MockSlingHttpServletRequest request = context.request();
SlingBindings slingBindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
slingBindings.put(WCMBindings.COMPONENT, component);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return context.request().adaptTo(Carousel.class);
}
Aggregations