use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class WorkflowPackageManagerImpl method getPaths.
/**
* {@inheritDoc}
*/
public final List<String> getPaths(final ResourceResolver resourceResolver, final String path, final String[] nodeTypes) throws RepositoryException {
final List<String> collectionPaths = new ArrayList<String>();
final Resource resource = resourceResolver.getResource(path);
if (resource == null) {
log.warn("Requesting paths for a non-existent Resource [ {} ]; returning empty results.", path);
return Collections.EMPTY_LIST;
} else if (!isWorkflowPackage(resourceResolver, path)) {
log.debug("Requesting paths for a non-Resource Collection [ {} ]; returning provided path.", path);
return Arrays.asList(new String[] { path });
} else {
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getContainingPage(path);
if (page != null && page.getContentResource() != null) {
final Node node = page.getContentResource().adaptTo(Node.class);
final ResourceCollection resourceCollection = ResourceCollectionUtil.getResourceCollection(node, resourceCollectionManager);
if (resourceCollection != null) {
final List<Node> members = resourceCollection.list(nodeTypes);
for (final Node member : members) {
collectionPaths.add(member.getPath());
}
return collectionPaths;
}
}
return Arrays.asList(new String[] { path });
}
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class SendTemplatedEmailUtils method getPayloadProperties.
/**
* Tests whether the payload is a DAM asset or a cq:Page for DAM asset
* returns all properties at the metadata node for DAM assets for cq:Page
* returns all properties at the jcr:content node The Map<String, String>
* that is returned contains string representations of each of the
* respective properties
*
* @param payloadRes
* the payload as a resource
* @param sdf
* used by the method to transform Date properties into Strings
* @return Map<String, String> String representation of jcr properties
*/
protected static final Map<String, String> getPayloadProperties(Resource payloadRes, SimpleDateFormat sdf) {
Map<String, String> emailParams = new HashMap<String, String>();
if (payloadRes == null) {
return emailParams;
}
// Check if the payload is an asset
if (DamUtil.isAsset(payloadRes)) {
// get metadata resource
Resource mdRes = payloadRes.getChild(JcrConstants.JCR_CONTENT + "/" + DamConstants.METADATA_FOLDER);
Map<String, String> assetMetadata = getJcrKeyValuePairs(mdRes, sdf);
emailParams.putAll(assetMetadata);
} else {
// check if the payload is a page
Page payloadPage = payloadRes.adaptTo(Page.class);
if (payloadPage != null) {
Map<String, String> pageContent = getJcrKeyValuePairs(payloadPage.getContentResource(), sdf);
emailParams.putAll(pageContent);
}
}
return emailParams;
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class PageRootProviderMultiImpl method getRootPage.
@Override
public Page getRootPage(Resource resource) {
String pagePath = getRootPagePath(resource.getPath());
if (pagePath != null) {
PageManager pageManager = resource.getResourceResolver().adaptTo(PageManager.class);
Page rootPage = pageManager.getPage(pagePath);
if (rootPage == null) {
log.debug("Page Root not found at [ {} ]", pagePath);
} else if (!rootPage.isValid()) {
log.debug("Page Root invalid at [ {} ]", pagePath);
} else {
return rootPage;
}
}
return null;
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesBindingsValuesProvider method setSharedProperties.
private void setSharedProperties(Bindings bindings, Resource resource, Component component) {
Page pageRoot = pageRootProvider.getRootPage(resource);
if (pageRoot != null) {
String globalPropsPath = pageRoot.getPath() + "/jcr:content/" + SharedComponentProperties.NN_GLOBAL_COMPONENT_PROPERTIES;
Resource globalPropsResource = resource.getResourceResolver().getResource(globalPropsPath);
if (globalPropsResource != null) {
bindings.put(SharedComponentProperties.GLOBAL_PROPERTIES, globalPropsResource.getValueMap());
bindings.put(SharedComponentProperties.GLOBAL_PROPERTIES_RESOURCE, globalPropsResource);
}
String sharedPropsPath = pageRoot.getPath() + "/jcr:content/" + SharedComponentProperties.NN_SHARED_COMPONENT_PROPERTIES + "/" + component.getResourceType();
Resource sharedPropsResource = resource.getResourceResolver().getResource(sharedPropsPath);
if (sharedPropsResource != null) {
bindings.put(SharedComponentProperties.SHARED_PROPERTIES, sharedPropsResource.getValueMap());
bindings.put(SharedComponentProperties.SHARED_PROPERTIES_RESOURCE, sharedPropsResource);
}
} else {
log.debug("Could not determine shared properties root for resource {}", resource.getPath());
}
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesPageInfoProvider method updatePageInfo.
/**
* Add a "sharedComponentProperties" section to pageInfo so that JS libs in the authoring interface
* can determine whether or not to enable shared/global properties for a component on a site.
*/
@Override
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
if (scheduledSharedComponentsMapUpdate > 0 && System.currentTimeMillis() > scheduledSharedComponentsMapUpdate) {
scheduledSharedComponentsMapUpdate = -1L;
updateSharedComponentsMap();
}
JSONObject props = new JSONObject();
props.put("enabled", false);
Page page = pageRootProvider.getRootPage(resource);
if (page != null) {
Session session = request.getResourceResolver().adaptTo(Session.class);
try {
AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
Privilege privilegeAddChild = accessControlManager.privilegeFromName("jcr:addChildNodes");
Privilege privilegeModifyProps = accessControlManager.privilegeFromName("jcr:modifyProperties");
Privilege[] requiredPrivs = new Privilege[] { privilegeAddChild, privilegeModifyProps };
if (accessControlManager.hasPrivileges(page.getPath() + "/jcr:content", requiredPrivs)) {
props.put("enabled", true);
props.put("root", page.getPath());
props.put("components", Maps.transformValues(componentsWithSharedProperties, (Function<List<Boolean>, Object>) JSONArray::new));
} else {
log.debug("User does not have [ {} ] on [ {} ]", requiredPrivs, page.getPath() + "/jcr:content");
}
} catch (RepositoryException e) {
log.error("Unexpected error checking permissions to modify shared component properties", e);
}
} else {
log.debug("No Page Root could be found for [ {} ]", resource.getPath());
}
info.put("sharedComponentProperties", props);
}
Aggregations