Search in sources :

Example 1 with ResourceCollection

use of com.day.cq.workflow.collection.ResourceCollection 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)

Aggregations

Page (com.day.cq.wcm.api.Page)1 PageManager (com.day.cq.wcm.api.PageManager)1 ResourceCollection (com.day.cq.workflow.collection.ResourceCollection)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Node (javax.jcr.Node)1 Resource (org.apache.sling.api.resource.Resource)1