public abstract class AbstractResource extends SlingAdaptable implements Resource
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.
RESOURCE_TYPE_NON_EXISTING
Constructor and Description |
---|
AbstractResource() |
Modifier and Type | Method and Description |
---|---|
Resource |
getChild(String relPath)
Returns the indicated child of this resource.
|
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 of this resource.
|
ValueMap |
getValueMap()
This method calls
Adaptable.adaptTo(Class)
with the ValueMap class as an argument. |
boolean |
hasChildren()
Checks to see if there are direct children of this resource by invoking
ResourceResolver.hasChildren(Resource) . |
boolean |
isResourceType(String resourceType)
Returns
true if this resource is of the given resource type
or if any of the super resource types equals the given resource type. |
Iterator<Resource> |
listChildren()
Returns an iterator on the direct child resources.
|
adaptTo, setAdapterManager, unsetAdapterManager
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPath, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType
public String getName()
This method is implemented as a pure string operation by calling the
ResourceUtil.getName(String)
method with the path of this
resource.
public Resource getParent()
This method is implemented calling the ResourceResolver.getParent(Resource)
method.
getParent
in interface Resource
null
.ResourceResolver.getParent(Resource)
public Resource getChild(String relPath)
This method is implemented calling the
ResourceResolver.getResource(Resource, String)
method. As such
the relPath
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.
getChild
in interface Resource
relPath
- relative path to the child resourcenull
ResourceResolver.getResource(Resource, String)
public Iterator<Resource> listChildren()
This method is implemented calling the
ResourceResolver.listChildren(Resource)
method.
Implementations should not generally overwrite this method without calling this base class implementation.
listChildren
in interface Resource
ResourceResolver.listChildren(Resource)
public Iterable<Resource> getChildren()
Resource
This method is a convenience and returns exactly the same resources as
calling getResourceResolver().getChildren(resource)
.
getChildren
in interface Resource
Resource.getChildren()
public boolean hasChildren()
ResourceResolver.hasChildren(Resource)
.hasChildren
in interface Resource
true
if the resource has any child resourcespublic boolean isResourceType(String resourceType)
true
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)
isResourceType
in interface Resource
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)
public ValueMap getValueMap()
Adaptable.adaptTo(Class)
with the ValueMap
class as an argument. If the
adaptTo
method returns a map, this map is returned. If the
resource is not adaptable to a value map, next an adaption to Map
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.getValueMap
in interface Resource
Resource.getValueMap()
Copyright © 2017 The Apache Software Foundation. All rights reserved.