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;
}
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 });
}
}
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;
}
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;
}
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);
}
Aggregations