use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class AbstractPackagerServlet method getPackagerPageResource.
/**
* Gets the Packager Page resource.
*
* @param request the Sling HTTP Servlet Request object
* @return a the PathFilterSet wrapping the cq:Page or null
*/
protected PathFilterSet getPackagerPageResource(final SlingHttpServletRequest request) {
final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getContainingPage(request.getResource());
if (page != null) {
return new PathFilterSet(page.getPath());
}
return null;
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class LastModifiedOperationImpl method withParams.
@Override
protected List<Result> withParams(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final Command cmd) {
final long start = System.currentTimeMillis();
final List<Result> results = new ArrayList<Result>();
final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final List<Resource> pages = this.getLastModifiedPages(resourceResolver, cmd);
log.debug("LastModified pages -- [ {} ] results", pages.size());
for (final Resource resource : pages) {
final Page page = pageManager.getContainingPage(resource);
if (page == null) {
continue;
}
final String title = TextUtil.getFirstNonEmpty(page.getTitle(), page.getPageTitle(), page.getNavigationTitle(), page.getName());
final String description = page.getPath() + " by " + page.getLastModifiedBy() + " at " + DATE_FORMAT.format(page.getLastModified().getTime());
results.add(new Result.Builder(title).path(page.getPath()).description(description).resultType(OpenResultSerializerImpl.TYPE).build());
}
log.debug("Lastmod - Execution time: {} ms", System.currentTimeMillis() - start);
return results;
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class NamedTransformImageServlet method resolveImage.
/**
* Intelligently determines how to find the Image based on the associated SlingRequest.
*
* @param request the SlingRequest Obj
* @return the Image object configured w the info of where the image to render is stored in CRX
*/
protected final Image resolveImage(final SlingHttpServletRequest request) {
final Resource resource = request.getResource();
final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getContainingPage(resource);
if (DamUtil.isAsset(resource)) {
// For assets, pick the configured rendition if it exists
// If rendition does not exist, use original
final Asset asset = DamUtil.resolveToAsset(resource);
Rendition rendition = asset.getRendition(renditionPatternPicker);
if (rendition == null) {
log.warn("Could not find rendition [ {} ] for [ {} ]", renditionPatternPicker.toString(), resource.getPath());
rendition = asset.getOriginal();
}
final Resource renditionResource = request.getResourceResolver().getResource(rendition.getPath());
final Image image = new Image(resource);
image.set(Image.PN_REFERENCE, renditionResource.getPath());
return image;
} else if (DamUtil.isRendition(resource) || resourceResolver.isResourceType(resource, JcrConstants.NT_FILE) || resourceResolver.isResourceType(resource, JcrConstants.NT_RESOURCE)) {
// For renditions; use the requested rendition
final Image image = new Image(resource);
image.set(Image.PN_REFERENCE, resource.getPath());
return image;
} else if (page != null) {
if (resourceResolver.isResourceType(resource, NameConstants.NT_PAGE) || StringUtils.equals(resource.getPath(), page.getContentResource().getPath())) {
// Is a Page or Page's Content Resource; use the Page's image resource
return new Image(page.getContentResource(), NAME_IMAGE);
} else {
return new Image(resource);
}
} else {
if (resourceResolver.isResourceType(resource, RT_LOCAL_SOCIAL_IMAGE) && resource.getValueMap().get("mimetype", StringUtils.EMPTY).startsWith("image/")) {
// Is a UGC image
return new SocialImageImpl(resource, NAME_IMAGE);
} else if (resourceResolver.isResourceType(resource, RT_REMOTE_SOCIAL_IMAGE)) {
// Is a UGC image
return new SocialRemoteImageImpl(resource, NAME_IMAGE);
}
}
return new Image(resource);
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class ContainingPageReportCellCSVExporter method getValue.
@Override
public String getValue(Object obj) {
Resource result = (Resource) obj;
PageManager pageMgr = result.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(result);
return page != null ? page.getPath() : "";
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class PageRelocator method movePage.
@SuppressWarnings("squid:S00112")
private void movePage(ResourceResolver rr, String sourcePage) throws Exception {
PageManager manager = pageManagerFactory.getPageManager(rr);
Field replicatorField = FieldUtils.getDeclaredField(manager.getClass(), "replicator", true);
FieldUtils.writeField(replicatorField, manager, replicatorQueue);
String destination = convertSourceToDestination(sourcePage);
String destinationParent = destination.substring(0, destination.lastIndexOf('/'));
note(sourcePage, Report.target, destination);
String beforeName = "";
final long start = System.currentTimeMillis();
String contentPath = sourcePage + "/jcr:content";
List<String> refs = new ArrayList<>();
List<String> publishRefs = new ArrayList<>();
if (maxReferences != 0 && resourceExists(rr, contentPath)) {
ReferenceSearch refSearch = new ReferenceSearch();
refSearch.setExact(true);
refSearch.setHollow(true);
refSearch.setMaxReferencesPerPage(maxReferences);
refSearch.setSearchRoot(referenceSearchRoot);
refSearch.search(rr, sourcePath).values().stream().peek(p -> refs.add(p.getPagePath())).filter(p -> isActivated(rr, p.getPagePath())).map(ReferenceSearch.Info::getPagePath).collect(Collectors.toCollection(() -> publishRefs));
}
note(sourcePage, Report.all_references, refs.size());
note(sourcePage, Report.published_references, publishRefs.size());
if (!dryRun) {
Actions.retry(10, 500, res -> {
waitUntilResourceFound(res, destinationParent);
Resource source = rr.getResource(sourcePage);
if (resourceExists(res, contentPath)) {
manager.move(source, destination, beforeName, true, true, listToStringArray(refs), listToStringArray(publishRefs));
} else {
Map<String, Object> props = new HashMap<>();
Resource parent = res.getResource(destinationParent);
res.create(parent, source.getName(), source.getValueMap());
}
res.commit();
res.refresh();
source = rr.getResource(sourcePage);
if (source != null && source.hasChildren()) {
for (Resource child : source.getChildren()) {
res.move(child.getPath(), destination);
}
res.commit();
}
}).accept(rr);
}
long end = System.currentTimeMillis();
note(sourcePage, Report.move_time, end - start);
}
Aggregations