Interface Resource
-
- All Superinterfaces:
Adaptable
- All Known Subinterfaces:
Asset,BinaryRendition,CarouselSet,ChannelConfig,ConnectorResource,ImageSet,MediaSet,Rendition,Rendition,SpinSet,SwatchSet,TemplatedResource
- All Known Implementing Classes:
AbstractResource,AuthorizableResource,Download,DownloadResource,FilteringResourceWrapper,GroupResource,Image,ImageResource,MergedMultiResource,NonExistingResource,Paragraph,ResourceWrapper,ResponsiveColumn,ResponsiveGrid,SyntheticResource,UserResource,ValueMapResource,ValueMapResourceWrapper,WCMFilteringResourceWrapper
@ProviderType public interface Resource extends Adaptable
Resources are pieces of content on which Sling actsThe
Resourceis also anAdaptableto get adapters to other types. A JCR based resource might support adapting to the JCR Node on which the resource is based.A
Resourceobject is valid for as long as theResourceResolverthat provided this instance is valid. The same applies in general to all objects returned by this instance, especially those returned by a call toAdaptable.adaptTo(Class).All implementations must support returning a value map from
getValueMap(), even if the map is empty.Implementor's Note: It is recommended to not implement this interface directly. Rather consider either extending from
AbstractResourceorResourceWrapper. This will make sure your implementation will not be suffering from missing method problems should the Sling Resource API be extended in the future.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringRESOURCE_TYPE_NON_EXISTINGThe special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting").
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description @Nullable ResourcegetChild(@NotNull java.lang.String relPath)Returns the child at the given relative path of this resource ornullif no such child exists.@NotNull java.lang.Iterable<Resource>getChildren()Returns an iterable of the direct children of this resource.@NotNull java.lang.StringgetName()Returns the name of this resource.@Nullable ResourcegetParent()Returns the parent resource ornullif this resource represents the root of the resource tree.@NotNull java.lang.StringgetPath()Returns the absolute path of this resource in the resource tree.@NotNull ResourceMetadatagetResourceMetadata()Returns the meta data of this resource.@NotNull ResourceResolvergetResourceResolver()Returns theResourceResolverfrom which this resource has been retrieved.@Nullable java.lang.StringgetResourceSuperType()Returns the super type of the resource if the resource defines its own super type.@NotNull java.lang.StringgetResourceType()The resource type is meant to point to rendering/processing scripts, editing dialogs, etc.@NotNull ValueMapgetValueMap()Returns a value map for this resource.booleanhasChildren()Checks if the resource has any child resources.booleanisResourceType(java.lang.String resourceType)Is just a shortcut forgetResourceResolver().isResourceType(this, resourceType).@NotNull java.util.Iterator<Resource>listChildren()Returns an iterator of the direct children of this resource.
-
-
-
Field Detail
-
RESOURCE_TYPE_NON_EXISTING
static final java.lang.String RESOURCE_TYPE_NON_EXISTING
The special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting"). This resource type is used byResourceResolverinstances to mark a resource which could not actually be resolved.
-
-
Method Detail
-
getPath
@NotNull @NotNull java.lang.String getPath()
Returns the absolute path of this resource in the resource tree.- Returns:
- The resource path
-
getName
@NotNull @NotNull java.lang.String getName()
Returns the name of this resource. The name of a resource is the last segment of thepath.- Returns:
- The resource name
- Since:
- 2.1 (Sling API Bundle 2.2.0)
-
getParent
@Nullable @Nullable Resource getParent()
Returns the parent resource ornullif this resource represents the root of the resource tree.- Returns:
- The parent resource or
null. - Throws:
SlingException- If an error occurs trying to get the resource object from the path.java.lang.IllegalStateException- if the resource resolver has already been closed}.- Since:
- 2.1 (Sling API Bundle 2.1.0)
- See Also:
ResourceResolver.getParent(Resource)
-
listChildren
@NotNull @NotNull java.util.Iterator<Resource> listChildren()
Returns an iterator of the direct children of this resource.This method is a convenience and returns exactly the same resources as calling
getResourceResolver().listChildren(resource).- Returns:
- An iterator for child resources.
- Throws:
SlingException- If an error occurs trying to get the resource iterator.java.lang.IllegalStateException- if the resource resolver has already been closed}.- Since:
- 2.1 (Sling API Bundle 2.1.0)
- See Also:
ResourceResolver.listChildren(Resource)
-
getChildren
@NotNull @NotNull java.lang.Iterable<Resource> getChildren()
Returns an iterable of the direct children of this resource.This method is a convenience and returns exactly the same resources as calling
getResourceResolver().getChildren(resource).- Returns:
- An iterable for child resources
- Throws:
SlingException- If an error occurs trying to get the resource iterator.java.lang.IllegalStateException- if the resource resolver has already been closed}.- Since:
- 2.2 (Sling API Bundle 2.2.0)
- See Also:
ResourceResolver.getChildren(Resource)
-
getChild
@Nullable @Nullable Resource getChild(@NotNull @NotNull java.lang.String relPath)
Returns the child at the given relative path of this resource ornullif no such child exists.This method is a convenience and returns exactly the same resources as calling
getResourceResolver().getResource(resource, relPath).- Parameters:
relPath- relative path to the child resource- Returns:
- The child resource or
null - Throws:
SlingException- If an error occurs trying to get the resource object from the path.java.lang.IllegalStateException- if the resource resolver has already been closed}.- Since:
- 2.1 (Sling API Bundle 2.1.0)
- See Also:
ResourceResolver.getResource(Resource, String)
-
getResourceType
@NotNull @NotNull java.lang.String getResourceType()
The resource type is meant to point to rendering/processing scripts, editing dialogs, etc. It is usually a path in the repository, where scripts and other tools definitions are found, but theResourceResolveris free to set this to any suitable value such as the primary node type of the JCR node from which the resource is created.If the resource instance represents a resource which is not actually existing, this method returns
RESOURCE_TYPE_NON_EXISTING.- Returns:
- The resource type
-
getResourceSuperType
@Nullable @Nullable java.lang.String getResourceSuperType()
Returns the super type of the resource if the resource defines its own super type. Otherwisenullis returned. A resource might return a resource super type to overwrite the resource type hierarchy. If a client is interested in the effective resource super type of a resource, it should callResourceResolver.getParentResourceType(Resource).- Returns:
- The super type of the resource or
null. - Throws:
java.lang.IllegalStateException- if this resource resolver has already beenclosed.
-
hasChildren
boolean hasChildren()
Checks if the resource has any child resources.- Returns:
trueif the resource has any child resources- Throws:
java.lang.IllegalStateException- if this resource resolver has already beenclosed.- Since:
- 2.4.4 (Sling API Bundle 2.5.0)
-
isResourceType
boolean isResourceType(java.lang.String resourceType)
Is just a shortcut forgetResourceResolver().isResourceType(this, resourceType).- Parameters:
resourceType- the resource type to check this resource against- Returns:
trueif the resource type or any of the resource's super type(s) equals the given resource type,falseotherwise;falsecan also be returned ifresourceTypeis null- Since:
- 2.1.0 (Sling API Bundle 2.1.0)
- See Also:
ResourceResolver.isResourceType(Resource, String)
-
getResourceMetadata
@NotNull @NotNull ResourceMetadata getResourceMetadata()
Returns the meta data of this resource. The concrete data contained in theResourceMetadataobject returned is implementation specific except for theResourceMetadata.RESOLUTION_PATHproperty which is required to be set to the part of the request URI used to resolve the resource.- Returns:
- The resource meta data
- See Also:
ResourceMetadata
-
getResourceResolver
@NotNull @NotNull ResourceResolver getResourceResolver()
Returns theResourceResolverfrom which this resource has been retrieved.- Returns:
- The resource resolver
-
getValueMap
@NotNull @NotNull ValueMap getValueMap()
Returns a value map for this resource. The value map allows to read the properties of the resource.- Returns:
- A value map
- Since:
- 2.5 (Sling API Bundle 2.7.0)
-
-