Search in sources :

Example 1 with Designer

use of com.day.cq.wcm.api.designer.Designer in project acs-aem-commons by Adobe-Consulting-Services.

the class AemObjectInjector method getResourceDesign.

private Design getResourceDesign(Object adaptable) {
    Page resourcePage = getResourcePage(adaptable);
    Designer designer = getDesigner(adaptable);
    if (adaptable instanceof SlingHttpServletRequest) {
        SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;
        if (resourcePage != null && designer != null) {
            String resourceDesignKey = COM_DAY_CQ_WCM_TAGS_DEFINE_OBJECTS_TAG + resourcePage.getPath();
            Object cachedResourceDesign = request.getAttribute(resourceDesignKey);
            if (cachedResourceDesign != null) {
                return (Design) cachedResourceDesign;
            } else {
                Design resourceDesign = designer.getDesign(resourcePage);
                request.setAttribute(resourceDesignKey, resourceDesign);
                return resourceDesign;
            }
        }
    }
    if (adaptable instanceof Resource) {
        return designer != null ? designer.getDesign(resourcePage) : null;
    }
    return null;
}
Also used : Design(com.day.cq.wcm.api.designer.Design) Designer(com.day.cq.wcm.api.designer.Designer) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 2 with Designer

use of com.day.cq.wcm.api.designer.Designer in project acs-aem-commons by Adobe-Consulting-Services.

the class AemObjectInjector method getCurrentDesign.

/**
 * Get the current design.
 *
 * @param adaptable a SlingHttpServletRequest
 * @return the current Design if the adaptable was a SlingHttpServletRequest, the default Design otherwise
 */
private Design getCurrentDesign(Object adaptable) {
    Page currentPage = getCurrentPage(adaptable);
    Designer designer = getDesigner(adaptable);
    if (currentPage != null && designer != null) {
        return designer.getDesign(currentPage);
    }
    return null;
}
Also used : Designer(com.day.cq.wcm.api.designer.Designer) Page(com.day.cq.wcm.api.Page)

Example 3 with Designer

use of com.day.cq.wcm.api.designer.Designer in project acs-aem-commons by Adobe-Consulting-Services.

the class DesignReferenceProvider method findReferences.

@Override
public List<Reference> findReferences(Resource resource) {
    ResourceResolver resourceResolver = resource.getResourceResolver();
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    Designer designer = resourceResolver.adaptTo(Designer.class);
    Page page = pageManager.getContainingPage(resource);
    if (page == null) {
        return Collections.emptyList();
    }
    Design design = designer.getDesign(page);
    if (design == null) {
        return Collections.emptyList();
    }
    return Collections.singletonList(new Reference(TYPE_DESIGN_PAGE, String.format("%s (Design)", design.getId()), design.getContentResource(), getLastModified(design)));
}
Also used : Design(com.day.cq.wcm.api.designer.Design) Designer(com.day.cq.wcm.api.designer.Designer) PageManager(com.day.cq.wcm.api.PageManager) Reference(com.day.cq.wcm.api.reference.Reference) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Page(com.day.cq.wcm.api.Page)

Example 4 with Designer

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

the class PageImplTest method getPageUnderTest.

protected Page getPageUnderTest(String pagePath, Object... properties) {
    Utils.enableDataLayer(context, true);
    Map<String, Object> propertyMap = MapUtil.toMap(properties);
    Resource resource = context.currentResource(pagePath + "/" + JcrConstants.JCR_CONTENT);
    MockSlingHttpServletRequest request = context.request();
    context.request().setContextPath("/core");
    if (resource != null && !propertyMap.isEmpty()) {
        if (propertyMap.containsKey(DESIGN_PATH_KEY)) {
            Designer designer = context.resourceResolver().adaptTo(Designer.class);
            if (designer != null) {
                Design design = designer.getDesign(pagePath);
                Design spyDesign = Mockito.spy(design);
                Mockito.doReturn(propertyMap.get(DESIGN_PATH_KEY)).when(spyDesign).getPath();
                request.setAttribute(DESIGN_CACHE_KEY, spyDesign);
            }
        }
        if (propertyMap.containsKey(CSS_CLASS_NAMES_KEY)) {
            ComponentContext spyComponentContext = Mockito.spy((ComponentContext) request.getAttribute(ComponentContext.CONTEXT_ATTR_NAME));
            Mockito.doReturn(Sets.newLinkedHashSet(Arrays.asList((String[]) propertyMap.get(CSS_CLASS_NAMES_KEY)))).when(spyComponentContext).getCssClassNames();
            request.setAttribute(ComponentContext.CONTEXT_ATTR_NAME, spyComponentContext);
        }
        context.contentPolicyMapping(resource.getResourceType(), properties);
    }
    return request.adaptTo(Page.class);
}
Also used : Design(com.day.cq.wcm.api.designer.Design) Designer(com.day.cq.wcm.api.designer.Designer) ComponentContext(com.day.cq.wcm.api.components.ComponentContext) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource)

Example 5 with Designer

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

the class AllowedEmbeddablesDataSourceServlet method getAllowedEmbeddables.

private List<Resource> getAllowedEmbeddables(@NotNull SlingHttpServletRequest request) {
    List<Resource> allowedEmbeddableResources = new ArrayList<>();
    ResourceResolver resolver = request.getResourceResolver();
    Resource contentResource = resolver.getResource((String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE));
    ContentPolicyManager policyManager = resolver.adaptTo(ContentPolicyManager.class);
    if (policyManager == null || contentResource == null) {
        return allowedEmbeddableResources;
    }
    ValueMap properties = null;
    ContentPolicy policy = policyManager.getPolicy(contentResource);
    if (policy != null) {
        properties = policy.getProperties();
    } else {
        Designer designer = resolver.adaptTo(Designer.class);
        if (designer != null) {
            properties = designer.getStyle(contentResource);
        }
    }
    if (properties == null) {
        return allowedEmbeddableResources;
    }
    String[] allowedEmbeddableResourceTypes = properties.get(Embed.PN_DESIGN_ALLOWED_EMBEDDABLES, String[].class);
    if (allowedEmbeddableResourceTypes != null && allowedEmbeddableResourceTypes.length > 0) {
        allowedEmbeddableResources.add(new AllowedEmbeddableResource("Select", "", resolver));
        for (String embeddableResourceType : allowedEmbeddableResourceTypes) {
            Resource componentResource = resolver.getResource(embeddableResourceType);
            if (componentResource != null) {
                allowedEmbeddableResources.add(new AllowedEmbeddableResource(componentResource.getValueMap().get(JcrConstants.JCR_TITLE, componentResource.getName()), embeddableResourceType, resolver));
            }
        }
    }
    return allowedEmbeddableResources;
}
Also used : Designer(com.day.cq.wcm.api.designer.Designer) ContentPolicyManager(com.day.cq.wcm.api.policies.ContentPolicyManager) ValueMap(org.apache.sling.api.resource.ValueMap) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy)

Aggregations

Designer (com.day.cq.wcm.api.designer.Designer)10 Resource (org.apache.sling.api.resource.Resource)7 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 Page (com.day.cq.wcm.api.Page)3 Design (com.day.cq.wcm.api.designer.Design)3 Style (com.day.cq.wcm.api.designer.Style)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 Test (org.junit.jupiter.api.Test)3 ContentPolicy (com.day.cq.wcm.api.policies.ContentPolicy)2 ContentPolicyManager (com.day.cq.wcm.api.policies.ContentPolicyManager)2 ArrayList (java.util.ArrayList)2 CoreComponentTestContext (com.adobe.cq.wcm.core.components.context.CoreComponentTestContext)1 TextValueDataResourceSource (com.adobe.cq.wcm.core.components.internal.servlets.TextValueDataResourceSource)1 MockStyle (com.adobe.cq.wcm.core.components.testing.MockStyle)1 Value (com.adobe.granite.ui.components.Value)1 DataSource (com.adobe.granite.ui.components.ds.DataSource)1 PageManager (com.day.cq.wcm.api.PageManager)1 ComponentContext (com.day.cq.wcm.api.components.ComponentContext)1 Reference (com.day.cq.wcm.api.reference.Reference)1 AemContext (io.wcm.testing.mock.aem.junit5.AemContext)1