Search in sources :

Example 16 with PageManager

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

the class LanguageNavigationImpl method getItems.

@Override
public List<NavigationItem> getItems() {
    if (items == null) {
        PageManager pageManager = currentPage.getPageManager();
        rootPage = pageManager.getPage(navigationRoot);
        if (rootPage != null) {
            int rootPageLevel = rootPage.getDepth();
            startLevel = rootPageLevel + 1;
            structureDepth += rootPageLevel;
            items = getItems(rootPage);
        } else {
            items = Collections.emptyList();
        }
    }
    return Collections.unmodifiableList(items);
}
Also used : PageManager(com.day.cq.wcm.api.PageManager)

Example 17 with PageManager

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

the class LanguageNavigationImpl method getLocalizedPage.

private Page getLocalizedPage(Page page, Page languageRoot) {
    Page localizedPage;
    String path = languageRoot.getPath();
    String relativePath = page.getPath();
    if (relativePath.startsWith(path)) {
        localizedPage = page;
    } else {
        String separator = "/";
        int i = relativePath.indexOf(separator);
        int occurrence = StringUtils.countMatches(path, separator) + 1;
        while (--occurrence > 0 && i != -1) {
            i = relativePath.indexOf(separator, i + 1);
        }
        relativePath = (i > 0) ? relativePath.substring(i) : "";
        path = path.concat(relativePath);
        PageManager pageManager = page.getPageManager();
        localizedPage = pageManager.getPage(path);
    }
    return localizedPage;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Page(com.day.cq.wcm.api.Page)

Example 18 with PageManager

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

the class RedirectItemImpl method getRedirectPage.

private Page getRedirectPage(@NotNull SlingHttpServletRequest request) {
    Page page = null;
    ResourceResolver resourceResolver = request.getResourceResolver();
    Resource targetResource = resourceResolver.getResource(redirectTarget);
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    if (pageManager != null && targetResource != null) {
        page = pageManager.getContainingPage(targetResource);
    }
    return page;
}
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)

Example 19 with PageManager

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

the class ComponentUtils method generateId.

/**
 * Returns an auto generated component ID.
 *
 * The ID is the first {@value ComponentUtils#ID_HASH_LENGTH} characters of an SHA-1 hexadecimal hash of the component path,
 * prefixed with the component name. Example: title-810f3af321
 *
 * If the component is referenced, the path is taken to be a concatenation of the component path,
 * with the path of the first parent context resource that exists on the page or in the template.
 * This ensures the ID is unique if the same component is referenced multiple times on the same page or template.
 *
 * Collision
 * ---------
 * c = expected collisions
 * c ~= (i^2)/(2m) - where i is the number of items and m is the number of possibilities for each item.
 * m = 16^n - for a hexadecimal string, where n is the number of characters.
 *
 * For i = 1000 components with the same name, and n = 10 characters:
 *
 * c ~= (1000^2)/(2*(16^10))
 * c ~= 0.00000045
 *
 * @return the auto generated component ID
 */
@NotNull
private static String generateId(@NotNull final Resource resource, @Nullable final Page currentPage, @Nullable final String resourceCallerPath, @Nullable final ComponentContext componentContext) {
    String resourceType = resource.getResourceType();
    String prefix = StringUtils.substringAfterLast(resourceType, "/");
    String path = resource.getPath();
    if (currentPage != null && componentContext != null) {
        PageManager pageManager = currentPage.getPageManager();
        Page resourcePage = pageManager.getContainingPage(resource);
        Template template = currentPage.getTemplate();
        boolean inCurrentPage = (resourcePage != null && StringUtils.equals(resourcePage.getPath(), currentPage.getPath()));
        boolean inTemplate = (template != null && path.startsWith(template.getPath()));
        if (resourceCallerPath != null) {
            path = resourceCallerPath.concat(resource.getPath());
        } else if (!inCurrentPage && !inTemplate) {
            ComponentContext parentContext = componentContext.getParent();
            while (parentContext != null) {
                Resource parentContextResource = parentContext.getResource();
                if (parentContextResource != null) {
                    Page parentContextPage = pageManager.getContainingPage(parentContextResource);
                    inCurrentPage = (parentContextPage != null && StringUtils.equals(parentContextPage.getPath(), currentPage.getPath()));
                    inTemplate = (template != null && parentContextResource.getPath().startsWith(template.getPath()));
                    if (inCurrentPage || inTemplate) {
                        path = parentContextResource.getPath().concat(resource.getPath());
                        break;
                    }
                }
                parentContext = parentContext.getParent();
            }
        }
    }
    return ComponentUtils.generateId(prefix, path);
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ComponentContext(com.day.cq.wcm.api.components.ComponentContext) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) Template(com.day.cq.wcm.api.Template) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with PageManager

use of com.day.cq.wcm.api.PageManager in project APM by Cognifide.

the class HistoryImpl method getOrCreateLogDir.

private Page getOrCreateLogDir(ResourceResolver resolver) throws WCMException {
    PageManager pageManager = resolver.adaptTo(PageManager.class);
    Page historyPage = pageManager.getPage(HISTORY_PATH);
    if (historyPage == null) {
        boolean autoCommit = true;
        historyPage = pageManager.create("/etc/cqsm", "history", "/apps/cqsm/core/templates/historyTemplate", "History", autoCommit);
    }
    return historyPage;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Page(com.day.cq.wcm.api.Page)

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