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;
}
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;
}
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)));
}
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);
}
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;
}
Aggregations