Search in sources :

Example 36 with PageManager

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

the class PWAImpl method initModel.

@PostConstruct
protected void initModel() {
    PageManager pageManager = resource.getResourceResolver().adaptTo(PageManager.class);
    if (pageManager == null) {
        return;
    }
    Page page = pageManager.getContainingPage(resource);
    while (page != null) {
        Resource contentResource = page.getContentResource();
        if (contentResource != null) {
            ValueMap valueMap = contentResource.getValueMap();
            Boolean isPWAEnabled = valueMap.get(PN_PWA_ENABLED, Boolean.class);
            if (isPWAEnabled != null && isPWAEnabled) {
                this.isEnabled = true;
                this.themeColor = colorToHex(valueMap.get(PN_PWA_THEME_COLOR, ""));
                this.iconPath = valueMap.get(PN_PWA_ICON_PATH, "");
                String startURL = valueMap.get(PN_PWA_START_URL, "");
                this.manifestPath = replaceSuffix(startURL, MANIFEST_NAME);
                String mappingName = page.getPath().replace(CONTENT_PATH, "").replace("/", ".");
                this.serviceWorkerPath = "/" + mappingName + "sw.js";
                break;
            }
        }
        page = page.getParent();
    }
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) PostConstruct(javax.annotation.PostConstruct)

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