Interface Resource
- All Superinterfaces:
Adaptable
- All Known Implementing Classes:
AbstractResource
,AuthorizableResource
,BaseResource
,ContentFileResource
,FileResource
,NestedAuthorizableResource
,NonExistingResource
,PrincipalResource
,RedirectResource
,ResourceWrapper
,ServletResource
,StarResource
,SyntheticResource
The Resource
is also an Adaptable
to get adapters to
other types. A JCR based resource might support adapting to the JCR Node on
which the resource is based.
A Resource
object is valid for as long as the
ResourceResolver
that provided this instance is valid. The
same applies in general to all objects returned by this instance,
especially those returned by a call to Adaptable.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 AbstractResource
or
ResourceWrapper
. 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
FieldsModifier and TypeFieldDescriptionstatic final String
The special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting"). -
Method Summary
Modifier and TypeMethodDescription@Nullable Resource
Returns the child at the given relative path of this resource ornull
if no such child exists.Returns an iterable of the direct children of this resource.@NotNull String
getName()
Returns the name of this resource.@Nullable Resource
Returns the parent resource ornull
if this resource represents the root of the resource tree.@NotNull String
getPath()
Returns the absolute path of this resource in the resource tree.@NotNull ResourceMetadata
Returns the meta data of this resource.@NotNull ResourceResolver
Returns theResourceResolver
from which this resource has been retrieved.@Nullable String
Returns the super type of the resource if the resource defines its own super type.@NotNull String
The resource type is meant to point to rendering/processing scripts, editing dialogs, etc.@NotNull ValueMap
Returns a value map for this resource.boolean
Checks if the resource has any child resources.boolean
isResourceType
(String resourceType) Is just a shortcut forgetResourceResolver().isResourceType(this, resourceType)
.Returns an iterator of the direct children of this resource.
-
Field Details
-
RESOURCE_TYPE_NON_EXISTING
The special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting"). This resource type is used byResourceResolver
instances to mark a resource which could not actually be resolved.
-
-
Method Details
-
getPath
Returns the absolute path of this resource in the resource tree.- Returns:
- The resource path
-
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
Returns the parent resource ornull
if 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.IllegalStateException
- if the resource resolver has already been closed}.- Since:
- 2.1 (Sling API Bundle 2.1.0)
- See Also:
-
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.IllegalStateException
- if the resource resolver has already been closed}.- Since:
- 2.1 (Sling API Bundle 2.1.0)
- See Also:
-
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.IllegalStateException
- if the resource resolver has already been closed}.- Since:
- 2.2 (Sling API Bundle 2.2.0)
- See Also:
-
getChild
Returns the child at the given relative path of this resource ornull
if 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.IllegalStateException
- if the resource resolver has already been closed}.- Since:
- 2.1 (Sling API Bundle 2.1.0)
- See Also:
-
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 theResourceResolver
is 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
Returns the super type of the resource if the resource defines its own super type. Otherwisenull
is 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:
IllegalStateException
- if this resource resolver has already beenclosed
.
-
hasChildren
boolean hasChildren()Checks if the resource has any child resources.- Returns:
true
if the resource has any child resources- Throws:
IllegalStateException
- if this resource resolver has already beenclosed
.- Since:
- 2.4.4 (Sling API Bundle 2.5.0)
-
isResourceType
Is just a shortcut forgetResourceResolver().isResourceType(this, resourceType)
.- Parameters:
resourceType
- the resource type to check this resource against- Returns:
true
if the resource type or any of the resource's super type(s) equals the given resource type,false
otherwise;false
can also be returned ifresourceType
is null- Since:
- 2.1.0 (Sling API Bundle 2.1.0)
- See Also:
-
getResourceMetadata
Returns the meta data of this resource. The concrete data contained in theResourceMetadata
object returned is implementation specific except for theResourceMetadata.RESOLUTION_PATH
property 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:
-
getResourceResolver
Returns theResourceResolver
from which this resource has been retrieved.- Returns:
- The resource resolver
-
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)
-