use of com.day.cq.wcm.api.policies.ContentPolicyManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AmpUtil method getAmpPropertyFromPolicy.
/**
* Retrieves the value of the amp property from the request resource's content policy.
* @param slingRequest The request used to get the resource and its content policy.
* @return The value of the property of the resource's content policy. Returns empty String if fails to read the content
* policy.
*/
@NotNull
private static String getAmpPropertyFromPolicy(@NotNull SlingHttpServletRequest slingRequest) {
String ampProperty = StringUtils.EMPTY;
ContentPolicyManager policyManager = slingRequest.getResourceResolver().adaptTo(ContentPolicyManager.class);
if (policyManager != null) {
ContentPolicy contentPolicy = policyManager.getPolicy(slingRequest.getResource());
if (contentPolicy != null) {
ampProperty = contentPolicy.getProperties().get(AMP_MODE_PROP, StringUtils.EMPTY);
}
}
return ampProperty;
}
use of com.day.cq.wcm.api.policies.ContentPolicyManager 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;
}
use of com.day.cq.wcm.api.policies.ContentPolicyManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AllowedColorSwatchesDataSourceServlet method getAllowedColorSwatches.
protected List<Resource> getAllowedColorSwatches(@NotNull SlingHttpServletRequest request) {
List<Resource> colors = new ArrayList<>();
ResourceResolver resolver = request.getResourceResolver();
Resource contentResource = resolver.getResource((String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE));
ContentPolicyManager policyMgr = resolver.adaptTo(ContentPolicyManager.class);
if (policyMgr != null) {
ContentPolicy policy = policyMgr.getPolicy(contentResource);
if (policy != null) {
ValueMap color = null;
ValueMap properties = policy.getProperties();
if (properties != null) {
String[] allowedColorSwatches = properties.get(PN_ALLOWED_COLOR_SWATCHES, String[].class);
if (allowedColorSwatches != null && allowedColorSwatches.length > 0) {
for (String allowedColorSwatch : allowedColorSwatches) {
color = new ValueMapDecorator(new HashMap<String, Object>());
color.put(PN_COLOR_VALUE, allowedColorSwatch);
colors.add(new ValueMapResource(resolver, new ResourceMetadata(), JcrConstants.NT_UNSTRUCTURED, color));
}
}
}
}
}
return colors;
}
use of com.day.cq.wcm.api.policies.ContentPolicyManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServlet method getContentPolicy.
/**
* Returns the content policy bound to the given component.
*
* @param imageResource the resource identifying the accessed image component
* @return the content policy. May be {@code nulll} in case no content policy can be found.
*/
private ContentPolicy getContentPolicy(@NotNull Resource imageResource) {
ResourceResolver resourceResolver = imageResource.getResourceResolver();
ContentPolicyManager policyManager = resourceResolver.adaptTo(ContentPolicyManager.class);
if (policyManager != null) {
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
if (componentManager != null) {
com.day.cq.wcm.api.components.Component component = componentManager.getComponentOfResource(imageResource);
if (component != null && component.getProperties() != null) {
String delegatingResourceType = component.getProperties().get(AbstractImageDelegatingModel.IMAGE_DELEGATE, String.class);
if (StringUtils.isNotEmpty(delegatingResourceType)) {
imageResource = new CoreResourceWrapper(imageResource, delegatingResourceType);
}
}
}
return policyManager.getPolicy(imageResource);
} else {
LOGGER.warn("Could not get policy manager from resource resolver!");
}
return null;
}
use of com.day.cq.wcm.api.policies.ContentPolicyManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class EmbeddableOptionsDataSourceServlet method getEmbeddableOptions.
private List<Resource> getEmbeddableOptions(@NotNull SlingHttpServletRequest request) {
List<Resource> embeddableOptionsResources = 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) {
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) {
String[] allowedEmbeddables = properties.get(Embed.PN_DESIGN_ALLOWED_EMBEDDABLES, String[].class);
if (allowedEmbeddables != null && allowedEmbeddables.length > 0) {
for (String allowedEmbeddable : allowedEmbeddables) {
Resource dialogResource = resolver.getResource(allowedEmbeddable + "/" + NN_DIALOG);
if (dialogResource != null) {
embeddableOptionsResources.add(dialogResource);
}
}
}
}
}
return embeddableOptionsResources;
}
Aggregations