Package org.apache.sling.cms
Class CMSUtils
java.lang.Object
org.apache.sling.cms.CMSUtils
Shared utility functions
-
Method Summary
Modifier and TypeMethodDescriptionstatic final <T> @NotNull List<T>adaptResources(Collection<org.apache.sling.api.resource.Resource> resources, Class<T> type) Adapts the collection of resources ensuring that if any cannot be adapted it is excluded from the returned list.static final <T> @NotNull List<T>adaptResources(org.apache.sling.api.resource.Resource[] resources, Class<T> type) Adapts the array of resources ensuring that if any cannot be adapted it is excluded from the returned list.static final @Nullable org.apache.sling.api.resource.ResourcefindParentResourceofType(org.apache.sling.api.resource.Resource resource, String type) Looks up the resource tree to find the parent resource with the specified jcr:primaryType.static final @Nullable org.apache.sling.api.resource.ResourcefindPublishableParent(org.apache.sling.api.resource.Resource resource) Look up the resource tree to find a parent of a publishable type.static final booleanisPublished(org.apache.sling.api.resource.Resource resource) Return true of the resource (or it's publishable parent) is published or false otherwise.
-
Method Details
-
adaptResources
@NotNull public static final <T> @NotNull List<T> adaptResources(Collection<org.apache.sling.api.resource.Resource> resources, Class<T> type) Adapts the collection of resources ensuring that if any cannot be adapted it is excluded from the returned list.- Type Parameters:
T- the type to which the resources are adapted- Parameters:
resources- the collection of resources to adapttype- the type to which to adapt the resources- Returns:
- the list of adapted classes
-
adaptResources
@NotNull public static final <T> @NotNull List<T> adaptResources(org.apache.sling.api.resource.Resource[] resources, Class<T> type) Adapts the array of resources ensuring that if any cannot be adapted it is excluded from the returned list.- Type Parameters:
T- the type to which the resources are adapted- Parameters:
resources- the array of resources to adapttype- the type to which to adapt the resources- Returns:
- the list of adapted classes
-
findParentResourceofType
@Nullable public static final @Nullable org.apache.sling.api.resource.Resource findParentResourceofType(org.apache.sling.api.resource.Resource resource, String type) Looks up the resource tree to find the parent resource with the specified jcr:primaryType.- Parameters:
resource- the resource to search fromtype- the primary type to find- Returns:
- the parent of the type or null
-
findPublishableParent
@Nullable public static final @Nullable org.apache.sling.api.resource.Resource findPublishableParent(org.apache.sling.api.resource.Resource resource) Look up the resource tree to find a parent of a publishable type.- Parameters:
resource- the resource to search from- Returns:
- the parent publishable type
-
isPublished
public static final boolean isPublished(org.apache.sling.api.resource.Resource resource) Return true of the resource (or it's publishable parent) is published or false otherwise. If the resource is not contained within a publishable parent it is considered published.- Parameters:
resource- the resource to check- Returns:
- whether or not the resource is published
-