@ProviderType public interface Resource extends Adaptable
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.
Modifier and Type | Field and Description |
---|---|
static String |
RESOURCE_TYPE_NON_EXISTING
The special resource type for resource instances representing nonexisting
resources (value is "sling:nonexisting").
|
Modifier and Type | Method and Description |
---|---|
Resource |
getChild(String relPath)
Returns the child at the given relative path of this resource or
null if no such child exists. |
Iterable<Resource> |
getChildren()
Returns an iterable of the direct children of this resource.
|
String |
getName()
Returns the name of this resource.
|
Resource |
getParent()
Returns the parent resource or
null if this resource
represents the root of the resource tree. |
String |
getPath()
Returns the absolute path of this resource in the resource tree.
|
ResourceMetadata |
getResourceMetadata()
Returns the metadata of this resource.
|
ResourceResolver |
getResourceResolver()
Returns the
ResourceResolver from which this resource has been
retrieved. |
String |
getResourceSuperType()
Returns the super type of the resource if the resource defines its
own super type.
|
String |
getResourceType()
The resource type is meant to point to rendering/processing scripts,
editing dialogs, etc.
|
ValueMap |
getValueMap()
Returns a value map for this resource.
|
boolean |
hasChildren()
Checks if the resource has any child resources.
|
boolean |
isResourceType(String resourceType)
Returns
true if the resource type or any of the resource's
super type(s) equals the given resource type. |
Iterator<Resource> |
listChildren()
Returns an iterator of the direct children of this resource.
|
static final String RESOURCE_TYPE_NON_EXISTING
ResourceResolver
instances to mark a resource which could not
actually be resolved.@Nonnull String getPath()
@Nonnull String getName()
path
.@CheckForNull Resource getParent()
null
if this resource
represents the root of the resource tree.@Nonnull Iterator<Resource> listChildren()
This method is a convenience and returns exactly the same resources as
calling getResourceResolver().listChildren(resource)
.
ResourceResolver.listChildren(Resource)
@Nonnull Iterable<Resource> getChildren()
This method is a convenience and returns exactly the same resources as
calling getResourceResolver().getChildren(resource)
.
ResourceResolver.getChildren(Resource)
@CheckForNull Resource getChild(@Nonnull String relPath)
null
if no such child exists.
This method is a convenience and returns exactly the same resources as
calling getResourceResolver().getResource(resource, relPath)
.
ResourceResolver.getResource(Resource, String)
@Nonnull String getResourceType()
ResourceResolver
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
.
@CheckForNull String getResourceSuperType()
null
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 call ResourceResolver.getParentResourceType(Resource)
.boolean hasChildren()
true
if the resource has any child resourcesboolean isResourceType(String resourceType)
true
if the resource type or any of the resource's
super type(s) equals the given resource type.resourceType
- The resource type to check this resource against.true
if the resource type or any of the resource's
super type(s) equals the given resource type. false
is also returned if resourceType
is
null
.@Nonnull ResourceMetadata getResourceMetadata()
ResourceMetadata
object returned is implementation specific
except for the ResourceMetadata.RESOLUTION_PATH
property which is
required to be set to the part of the request URI used to resolve the
resource.ResourceMetadata
@Nonnull ResourceResolver getResourceResolver()
ResourceResolver
from which this resource has been
retrieved.@Nonnull ValueMap getValueMap()
Copyright © 2015 The Apache Software Foundation. All rights reserved.