Class AbstractResource
- Direct Known Subclasses:
BaseResource
,ContentFileResource
,FileResource
,ServletResource
,SyntheticResource
AbstractResource
is an abstract implementation of the
Resource
interface.
Implementations of the Resource
interface are strongly encouraged to
either extend from this class or the ResourceWrapper
class instead of
implementing the Resource
from the ground up. This will ensure to
always be able to support new methods that might be introduced in the
Resource
interface in the future.
- Since:
- 2.1.0 (Sling API Bundle 2.1.0)
-
Field Summary
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the indicated child of this resource.Returns an iterable of the direct children of this resource.getName()
Returns the name of this resource.Returns the parent resource of this resource.This method callsAdaptable.adaptTo(Class)
with theValueMap
class as an argument.boolean
Checks to see if there are direct children of this resource by invokingResourceResolver.hasChildren(Resource)
.boolean
isResourceType
(String resourceType) Returnstrue
if this resource is of the given resource type or if any of the super resource types equals the given resource type.Returns an iterator on the direct child resources.Methods inherited from class org.apache.sling.api.adapter.SlingAdaptable
adaptTo, setAdapterManager, unsetAdapterManager
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.sling.api.resource.Resource
getPath, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType
-
Constructor Details
-
AbstractResource
public AbstractResource()
-
-
Method Details
-
getName
Returns the name of this resource.This method is implemented as a pure string operation by calling the
ResourceUtil.getName(String)
method with the path of this resource. -
getParent
Returns the parent resource of this resource.This method is implemented calling the
ResourceResolver.getParent(Resource)
method. -
getChild
Returns the indicated child of this resource.This method is implemented calling the
ResourceResolver.getResource(Resource, String)
method. As such therelPath
argument may even be an absolute path or a path containing relative path segments.
(current resource) and..
(parent resource).Implementations should not generally overwrite this method without calling this base class implementation.
-
listChildren
Returns an iterator on the direct child resources.This method is implemented calling the
ResourceResolver.listChildren(Resource)
method.Implementations should not generally overwrite this method without calling this base class implementation.
- Specified by:
listChildren
in interfaceResource
- Returns:
- An iterator for child resources.
- See Also:
-
getChildren
Description copied from interface:Resource
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)
.- Specified by:
getChildren
in interfaceResource
- Returns:
- An iterable for child resources
- See Also:
-
hasChildren
public boolean hasChildren()Checks to see if there are direct children of this resource by invokingResourceResolver.hasChildren(Resource)
.- Specified by:
hasChildren
in interfaceResource
- Returns:
true
if the resource has any child resources
-
isResourceType
Returnstrue
if this resource is of the given resource type or if any of the super resource types equals the given resource type.This method delegates to
ResourceResolver.isResourceType(Resource, String)
- Specified by:
isResourceType
in interfaceResource
- 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- See Also:
-
getValueMap
This method callsAdaptable.adaptTo(Class)
with theValueMap
class as an argument. If theadaptTo
method returns a map, this map is returned. If the resource is not adaptable to a value map, next an adaption toMap
is tried and if this is successful the map is wrapped as a value map. If the adaptions are not successful an empty value map is returned.- Specified by:
getValueMap
in interfaceResource
- Returns:
- A value map
- See Also:
-