use of com.day.cq.wcm.api.policies.ContentPolicyManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AllowedHeadingElementsDataSourceServlet method getAllowedHeadingElements.
private List<Resource> getAllowedHeadingElements(@NotNull SlingHttpServletRequest request) {
List<Resource> allowedHeadingElements = new ArrayList<>();
ResourceResolver resolver = request.getResourceResolver();
Resource contentResource = resolver.getResource((String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE));
ContentPolicyManager policyManager = resolver.adaptTo(ContentPolicyManager.class);
if (contentResource != null && policyManager != null) {
ContentPolicy policy = policyManager.getPolicy(contentResource);
if (policy != null) {
ValueMap props = policy.getProperties();
if (props != null) {
String[] headingElements = props.get(PN_ALLOWED_HEADING_ELEMENTS, String[].class);
String[] allowedTypes = props.get(PN_ALLOWED_TYPES, String[].class);
String defaultHeadingElement = props.get(PN_DEFAULT_HEADING_ELEMENT, props.get(PN_DEFAULT_TYPE, StringUtils.EMPTY));
if (headingElements == null || headingElements.length == 0) {
headingElements = allowedTypes;
}
if (headingElements != null && headingElements.length > 0) {
for (String headingElement : headingElements) {
allowedHeadingElements.add(new HeadingElementResource(headingElement, StringUtils.equals(headingElement, defaultHeadingElement), resolver));
}
}
}
}
}
return allowedHeadingElements;
}
Aggregations