Search in sources :

Example 21 with PageManager

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;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Page(com.day.cq.wcm.api.Page)

Example 22 with PageManager

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;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ArrayList(java.util.ArrayList) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) SearchResult(com.day.cq.search.result.SearchResult) Result(com.adobe.acs.commons.quickly.results.Result)

Example 23 with PageManager

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);
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Rendition(com.day.cq.dam.api.Rendition) Resource(org.apache.sling.api.resource.Resource) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Asset(com.day.cq.dam.api.Asset) Page(com.day.cq.wcm.api.Page) Image(com.day.cq.wcm.foundation.Image)

Example 24 with PageManager

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() : "";
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page)

Example 25 with PageManager

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);
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) FieldUtils(org.apache.commons.lang.reflect.FieldUtils) ProcessDefinition(com.adobe.acs.commons.mcp.ProcessDefinition) ReplicationActionType(com.day.cq.replication.ReplicationActionType) HashMap(java.util.HashMap) SimpleFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ReplicationStatus(com.day.cq.replication.ReplicationStatus) ManagedProcess(com.adobe.acs.commons.mcp.model.ManagedProcess) RepositoryException(javax.jcr.RepositoryException) ReplicationException(com.day.cq.replication.ReplicationException) Map(java.util.Map) ReferenceSearch(com.day.cq.wcm.commons.ReferenceSearch) FormField(com.adobe.acs.commons.mcp.form.FormField) PersistenceException(org.apache.sling.api.resource.PersistenceException) ReplicationOptions(com.day.cq.replication.ReplicationOptions) Actions(com.adobe.acs.commons.fam.actions.Actions) PathfieldComponent(com.adobe.acs.commons.mcp.form.PathfieldComponent) EnumMap(java.util.EnumMap) Session(javax.jcr.Session) Replicator(com.day.cq.replication.Replicator) Resource(org.apache.sling.api.resource.Resource) RadioComponent(com.adobe.acs.commons.mcp.form.RadioComponent) PageManagerFactory(com.day.cq.wcm.api.PageManagerFactory) ActionManager(com.adobe.acs.commons.fam.ActionManager) Field(java.lang.reflect.Field) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) PageManager(com.day.cq.wcm.api.PageManager) LoginException(org.apache.sling.api.resource.LoginException) List(java.util.List) GenericReport(com.adobe.acs.commons.mcp.model.GenericReport) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) NameConstants(com.day.cq.wcm.api.NameConstants) TextfieldComponent(com.adobe.acs.commons.mcp.form.TextfieldComponent) AccessControlManager(javax.jcr.security.AccessControlManager) CheckboxComponent(com.adobe.acs.commons.mcp.form.CheckboxComponent) Pattern(java.util.regex.Pattern) Privilege(javax.jcr.security.Privilege) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) FormField(com.adobe.acs.commons.mcp.form.FormField) Field(java.lang.reflect.Field) PageManager(com.day.cq.wcm.api.PageManager) ReferenceSearch(com.day.cq.wcm.commons.ReferenceSearch) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) TreeMap(java.util.TreeMap)

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