Class AbstractResource
- java.lang.Object
-
- org.apache.sling.api.adapter.SlingAdaptable
-
- org.apache.sling.api.resource.AbstractResource
-
- Direct Known Subclasses:
AuthorizableResource,ResponsiveColumn,ResponsiveGrid,SyntheticResource
public abstract class AbstractResource extends SlingAdaptable implements Resource
TheAbstractResourceis an abstract implementation of theResourceinterface.Implementations of the
Resourceinterface are strongly encouraged to either extend from this class or theResourceWrapperclass instead of implementing theResourcefrom the ground up. This will ensure to always be able to support new methods that might be introduced in theResourceinterface 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
Constructors Constructor Description AbstractResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourcegetChild(java.lang.String relPath)Returns the indicated child of this resource.java.lang.Iterable<Resource>getChildren()Returns an iterable of the direct children of this resource.java.lang.StringgetName()Returns the name of this resource.ResourcegetParent()Returns the parent resource of this resource.ValueMapgetValueMap()This method callsAdaptable.adaptTo(Class)with theValueMapclass as an argument.booleanhasChildren()Checks to see if there are direct children of this resource by invokingResourceResolver.hasChildren(Resource).booleanisResourceType(java.lang.String resourceType)Returnstrueif this resource is of the given resource type or if any of the super resource types equals the given resource type.java.util.Iterator<Resource>listChildren()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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sling.api.resource.Resource
getPath, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType
-
-
-
-
Method Detail
-
getName
public java.lang.String 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
public Resource getParent()
Returns the parent resource of this resource.This method is implemented calling the
ResourceResolver.getParent(Resource)method.- Specified by:
getParentin interfaceResource- Returns:
- The parent resource or
null. - See Also:
ResourceResolver.getParent(Resource)
-
getChild
public Resource getChild(java.lang.String relPath)
Returns the indicated child of this resource.This method is implemented calling the
ResourceResolver.getResource(Resource, String)method. As such therelPathargument 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.
- Specified by:
getChildin interfaceResource- Parameters:
relPath- relative path to the child resource- Returns:
- The child resource or
null - See Also:
ResourceResolver.getResource(Resource, String)
-
listChildren
public java.util.Iterator<Resource> 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:
listChildrenin interfaceResource- Returns:
- An iterator for child resources.
- See Also:
ResourceResolver.listChildren(Resource)
-
getChildren
public java.lang.Iterable<Resource> getChildren()
Description copied from interface:ResourceReturns 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:
getChildrenin interfaceResource- Returns:
- An iterable for child resources
- See Also:
Resource.getChildren()
-
hasChildren
public boolean hasChildren()
Checks to see if there are direct children of this resource by invokingResourceResolver.hasChildren(Resource).- Specified by:
hasChildrenin interfaceResource- Returns:
trueif the resource has any child resources
-
isResourceType
public boolean isResourceType(java.lang.String resourceType)
Returnstrueif 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:
isResourceTypein interfaceResource- Parameters:
resourceType- the resource type to check this resource against- Returns:
trueif the resource type or any of the resource's super type(s) equals the given resource type,falseotherwise;falsecan also be returned ifresourceTypeis null- See Also:
ResourceResolver.isResourceType(Resource, String)
-
getValueMap
public ValueMap getValueMap()
This method callsAdaptable.adaptTo(Class)with theValueMapclass as an argument. If theadaptTomethod returns a map, this map is returned. If the resource is not adaptable to a value map, next an adaption toMapis 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:
getValueMapin interfaceResource- Returns:
- A value map
- See Also:
Resource.getValueMap()
-
-