Search in sources :

Example 26 with PageManager

use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.

the class WorkflowPackageManagerImpl method isWorkflowPackage.

/**
 * {@inheritDoc}
 */
public final boolean isWorkflowPackage(final ResourceResolver resourceResolver, final String path) {
    final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    final Page workflowPackagesPage = pageManager.getPage(path);
    if (workflowPackagesPage == null) {
        return false;
    }
    final Resource contentResource = workflowPackagesPage.getContentResource();
    if (contentResource == null) {
        return false;
    }
    if (!contentResource.isResourceType(WORKFLOW_PAGE_RESOURCE_TYPE)) {
        return false;
    }
    if (contentResource.getChild(NN_VLT_DEFINITION) == null) {
        return false;
    }
    return true;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page)

Example 27 with PageManager

use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.

the class WorkflowPackageManagerImpl method getPaths.

/**
 * {@inheritDoc}
 */
public final List<String> getPaths(final ResourceResolver resourceResolver, final String path, final String[] nodeTypes) throws RepositoryException {
    final List<String> collectionPaths = new ArrayList<String>();
    final Resource resource = resourceResolver.getResource(path);
    if (resource == null) {
        log.warn("Requesting paths for a non-existent Resource [ {} ]; returning empty results.", path);
        return Collections.EMPTY_LIST;
    } else if (!isWorkflowPackage(resourceResolver, path)) {
        log.debug("Requesting paths for a non-Resource Collection  [ {} ]; returning provided path.", path);
        return Arrays.asList(new String[] { path });
    } else {
        final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
        final Page page = pageManager.getContainingPage(path);
        if (page != null && page.getContentResource() != null) {
            final Node node = page.getContentResource().adaptTo(Node.class);
            final ResourceCollection resourceCollection = ResourceCollectionUtil.getResourceCollection(node, resourceCollectionManager);
            if (resourceCollection != null) {
                final List<Node> members = resourceCollection.list(nodeTypes);
                for (final Node member : members) {
                    collectionPaths.add(member.getPath());
                }
                return collectionPaths;
            }
        }
        return Arrays.asList(new String[] { path });
    }
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) ArrayList(java.util.ArrayList) List(java.util.List) ResourceCollection(com.day.cq.workflow.collection.ResourceCollection)

Example 28 with PageManager

use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.

the class WCMViewsFilter method accepts.

/**
 * Determines if the filter should process this request.
 *
 * @param request the request
 * @return true is the filter should attempt to process
 */
@SuppressWarnings("squid:S3776")
private boolean accepts(final SlingHttpServletRequest request) {
    final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
    final Resource resource = request.getResource();
    // Only process requests that match the include path prefixes if any are provided
    if (ArrayUtils.isEmpty(this.includePathPrefixes) || (!StringUtils.startsWithAny(request.getResource().getPath(), this.includePathPrefixes))) {
        return false;
    }
    // If the WCM Views on Request is set to disabled; do not process
    if (this.getRequestViews(request).contains(WCM_VIEW_DISABLED)) {
        return false;
    }
    // Only process resources that are part of a Page
    if (pageManager.getContainingPage(request.getResource()) == null) {
        return false;
    }
    final Node node = request.getResource().adaptTo(Node.class);
    if (node != null) {
        try {
            // and they dont have dropzone of their own
            if (// Do not process Page node inclusions
            node.isNodeType(NameConstants.NT_PAGE) || node.isNodeType("cq:PageContent") || JcrConstants.JCR_CONTENT.equals(node.getName())) {
                // Do not process Page jcr:content nodes (that may not have the cq:PageContent jcr:primaryType)
                return false;
            }
        } catch (RepositoryException e) {
            log.error("Repository exception prevented WCM Views Filter " + "from determining if the resource is acceptable", e);
            return false;
        }
    }
    if (CollectionUtils.isNotEmpty(this.resourceTypesIncludes)) {
        for (final Pattern pattern : this.resourceTypesIncludes) {
            final Matcher matcher = pattern.matcher(resource.getResourceType());
            if (matcher.matches()) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : Pattern(java.util.regex.Pattern) PageManager(com.day.cq.wcm.api.PageManager) Matcher(java.util.regex.Matcher) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) RepositoryException(javax.jcr.RepositoryException)

Example 29 with PageManager

use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.

the class PageRootProviderMultiImpl method getRootPage.

@Override
public Page getRootPage(Resource resource) {
    String pagePath = getRootPagePath(resource.getPath());
    if (pagePath != null) {
        PageManager pageManager = resource.getResourceResolver().adaptTo(PageManager.class);
        Page rootPage = pageManager.getPage(pagePath);
        if (rootPage == null) {
            log.debug("Page Root not found at [ {} ]", pagePath);
        } else if (!rootPage.isValid()) {
            log.debug("Page Root invalid at [ {} ]", pagePath);
        } else {
            return rootPage;
        }
    }
    return null;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Page(com.day.cq.wcm.api.Page)

Example 30 with PageManager

use of com.day.cq.wcm.api.PageManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PWAImplTest method setUp.

@BeforeEach
public void setUp() {
    context.load().json("/pwa" + CoreComponentTestContext.TEST_CONTENT_JSON, SITES_PAGE_PATH);
    resolver = context.resourceResolver();
    resource = spy(resolver.getResource(SITES_PAGE_PATH));
    mvp = resource.adaptTo(ModifiableValueMap.class);
    when(resource.getPath()).thenReturn(SITES_PAGE_PATH);
    ResourceResolver spyResolver = spy(resolver);
    when(resource.getResourceResolver()).thenReturn(spyResolver);
    Resource mockPWAResource = mock(Resource.class);
    when(spyResolver.getResource(SITES_PAGE_PATH + "/" + JcrConstants.JCR_CONTENT)).thenReturn(mockPWAResource);
    PageManager mockPageManager = mock(PageManager.class);
    Page mockPage = mock(Page.class);
    when(spyResolver.adaptTo(PageManager.class)).thenReturn(mockPageManager);
    when(mockPageManager.getContainingPage(resource)).thenReturn(mockPage);
    when(mockPage.getContentResource()).thenReturn(mockPWAResource);
    when(mockPage.getPath()).thenReturn(SITES_PAGE_PATH);
    Page mockParentPage = mock(Page.class);
    when(mockPage.getParent()).thenReturn(mockParentPage);
    mvp.put(PN_PWA_ENABLED, true);
    mvp.put(PN_PWA_START_URL, SITES_PAGE_PATH + ".html");
    when(mockPWAResource.getValueMap()).thenReturn(mvp);
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

PageManager (com.day.cq.wcm.api.PageManager)36 Page (com.day.cq.wcm.api.Page)31 Resource (org.apache.sling.api.resource.Resource)23 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)14 ArrayList (java.util.ArrayList)10 ValueMap (org.apache.sling.api.resource.ValueMap)8 HashMap (java.util.HashMap)7 Map (java.util.Map)5 Asset (com.day.cq.dam.api.Asset)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 PostConstruct (javax.annotation.PostConstruct)3 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)2 Image (com.adobe.cq.wcm.core.components.models.Image)2 Rendition (com.day.cq.dam.api.Rendition)2 ReplicationException (com.day.cq.replication.ReplicationException)2 NameConstants (com.day.cq.wcm.api.NameConstants)2 Template (com.day.cq.wcm.api.Template)2 Reference (com.day.cq.wcm.api.reference.Reference)2