Search in sources :

Example 6 with Component

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());
}
Also used : Page(com.day.cq.wcm.api.Page) Component(com.day.cq.wcm.api.components.Component) LinkHandler(com.adobe.cq.wcm.core.components.internal.link.LinkHandler) Test(org.junit.jupiter.api.Test)

Example 7 with Component

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);
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) ValueMap(org.apache.sling.api.resource.ValueMap) ComponentManager(com.day.cq.wcm.api.components.ComponentManager) Component(com.day.cq.wcm.api.components.Component) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 8 with Component

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;
}
Also used : JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) Component(com.day.cq.wcm.api.components.Component) JspWriter(javax.servlet.jsp.JspWriter) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 9 with Component

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));
                        }
                    }
                }
            }
        }
    }
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ComponentManager(com.day.cq.wcm.api.components.ComponentManager) Resource(org.apache.sling.api.resource.Resource) Component(com.day.cq.wcm.api.components.Component)

Example 10 with Component

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);
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Component(com.day.cq.wcm.api.components.Component)

Aggregations

Component (com.day.cq.wcm.api.components.Component)11 Resource (org.apache.sling.api.resource.Resource)5 ComponentManager (com.day.cq.wcm.api.components.ComponentManager)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 Page (com.day.cq.wcm.api.Page)2 HashMap (java.util.HashMap)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 SlingBindings (org.apache.sling.api.scripting.SlingBindings)2 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)2 PageRootProvider (com.adobe.acs.commons.wcm.PageRootProvider)1 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 RepositoryException (javax.jcr.RepositoryException)1 SimpleBindings (javax.script.SimpleBindings)1 JspException (javax.servlet.jsp.JspException)1 JspWriter (javax.servlet.jsp.JspWriter)1