Search in sources :

Example 71 with Page

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 });
    }
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) ArrayList(java.util.ArrayList) List(java.util.List) ResourceCollection(com.day.cq.workflow.collection.ResourceCollection)

Example 72 with Page

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;
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page)

Example 73 with Page

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;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Page(com.day.cq.wcm.api.Page)

Example 74 with Page

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());
    }
}
Also used : Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page)

Example 75 with Page

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);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Function(com.google.common.base.Function) JSONObject(org.apache.sling.commons.json.JSONObject) JSONArray(org.apache.sling.commons.json.JSONArray) Page(com.day.cq.wcm.api.Page) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session)

Aggregations

Page (com.day.cq.wcm.api.Page)100 Resource (org.apache.sling.api.resource.Resource)45 PageManager (com.day.cq.wcm.api.PageManager)34 Test (org.junit.jupiter.api.Test)22 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)18 ValueMap (org.apache.sling.api.resource.ValueMap)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 SlingBindings (org.apache.sling.api.scripting.SlingBindings)12 NotNull (org.jetbrains.annotations.NotNull)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Optional (java.util.Optional)6 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)6 Nullable (org.jetbrains.annotations.Nullable)6 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)5 Template (com.day.cq.wcm.api.Template)5 StringUtils (org.apache.commons.lang3.StringUtils)5 Before (org.junit.Before)5