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 java.lang.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(java.lang.String relPath)
Returns the child at the given relative path of this resource or
null if no such child exists. |
java.lang.Iterable<Resource> |
getChildren()
Returns an iterable of the direct children of this resource.
|
java.lang.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. |
java.lang.String |
getPath()
Returns the absolute path of this resource in the resource tree.
|
ResourceMetadata |
getResourceMetadata()
Returns the meta data of this resource.
|
ResourceResolver |
getResourceResolver()
Returns the
ResourceResolver from which this resource has been
retrieved. |
java.lang.String |
getResourceSuperType()
Returns the super type of the resource if the resource defines its
own super type.
|
java.lang.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(java.lang.String resourceType)
Is just a shortcut for
getResourceResolver().isResourceType(this, resourceType) . |
java.util.Iterator<Resource> |
listChildren()
Returns an iterator of the direct children of this resource.
|
static final java.lang.String RESOURCE_TYPE_NON_EXISTING
ResourceResolver
instances to mark a resource which could not
actually be resolved.getResourceType()
,
ResourceUtil.isNonExistingResource(Resource)
,
ResourceResolver#resolve(javax.servlet.http.HttpServletRequest,
String)
,
Constant Field Valuesjava.lang.String getPath()
java.lang.String getName()
path
.Resource getParent()
null
if this resource
represents the root of the resource tree.null
.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}.ResourceResolver.getParent(Resource)
java.util.Iterator<Resource> listChildren()
This method is a convenience and returns exactly the same resources as
calling getResourceResolver().listChildren(resource)
.
SlingException
- If an error occurs trying to
get the resource iterator.java.lang.IllegalStateException
- if the resource resolver has already been
closed}.ResourceResolver.listChildren(Resource)
java.lang.Iterable<Resource> getChildren()
This method is a convenience and returns exactly the same resources as
calling getResourceResolver().getChildren(resource)
.
SlingException
- If an error occurs trying to
get the resource iterator.java.lang.IllegalStateException
- if the resource resolver has already been
closed}.ResourceResolver.getChildren(Resource)
Resource getChild(java.lang.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)
.
relPath
- relative path to the child resourcenull
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}.ResourceResolver.getResource(Resource, String)
java.lang.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
.
java.lang.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)
.null
.java.lang.IllegalStateException
- if this resource resolver has already been
closed
.boolean hasChildren()
true
if the resource has any child resourcesjava.lang.IllegalStateException
- if this resource resolver has already been
closed
.boolean isResourceType(java.lang.String resourceType)
getResourceResolver().isResourceType(this, resourceType)
.resourceType
- the resource type to check this resource againsttrue
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 if resourceType
is nullResourceResolver.isResourceType(Resource, String)
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
ResourceResolver getResourceResolver()
ResourceResolver
from which this resource has been
retrieved.ValueMap getValueMap()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"