org.apache.sling.api.resource
Interface Resource

All Superinterfaces:
Adaptable
All Known Implementing Classes:
AbstractResource, MockResource, NonExistingResource, ResourceWrapper, SyntheticResource

public interface Resource
extends Adaptable

Resources are pieces of content on which Sling acts

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.

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.


Field Summary
static String RESOURCE_TYPE_NON_EXISTING
          The special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting").
 
Method Summary
 Resource getChild(String relPath)
          Returns the child at the given relative path of this resource or null if no such child exists.
 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 type of the resource or null if the getResourceType() has no supertype.
 String getResourceType()
          The resource type is meant to point to rendering/processing scripts, editing dialogs, etc.
 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.
 
Methods inherited from interface org.apache.sling.api.adapter.Adaptable
adaptTo
 

Field Detail

RESOURCE_TYPE_NON_EXISTING

static final String RESOURCE_TYPE_NON_EXISTING
The special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting"). This resource type is used by ResourceResolver instances to mark a resource which could not actually be resolved.

See Also:
getResourceType(), ResourceUtil.isNonExistingResource(Resource), ResourceResolver.resolve(javax.servlet.http.HttpServletRequest, String), Constant Field Values
Method Detail

getPath

String getPath()
Returns the absolute path of this resource in the resource tree.


getName

String getName()
Returns the name of this resource. The name of a resource is the last segment of the path.

Since:
2.1.0

getParent

Resource getParent()
Returns the parent resource or null if this resource represents the root of the resource tree.

Since:
2.1.0

listChildren

Iterator<Resource> listChildren()
Returns an iterator of the direct children of this resource.

This method is a convenience and returns exactly the same resources as calling getResourceResolver().listChildren(resource).

Since:
2.1.0
See Also:
ResourceResolver.listChildren(Resource)

getChild

Resource getChild(String relPath)
Returns the child at the given relative path of this resource or null if no such child exists.

This method is a convenience and returns exactly the same resources as calling getResourceResolver().getResource(resource, relPath).

Since:
2.1.0
See Also:
ResourceResolver.getResource(Resource, String)

getResourceType

String getResourceType()
The resource type is meant to point to rendering/processing scripts, editing dialogs, etc. It is usually a path in the repository, where scripts and other tools definitions are found, but the 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.


getResourceSuperType

String getResourceSuperType()
Returns the super type of the type of the resource or null if the getResourceType() has no supertype.


isResourceType

boolean isResourceType(String resourceType)
Returns true if the resource type or any of the resource's super type(s) equals the given resource type.

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 is also returned if resourceType is null.
Since:
2.1.0

getResourceMetadata

ResourceMetadata getResourceMetadata()
Returns the metadata of this resource. The concrete data contained in the 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.

See Also:
ResourceMetadata

getResourceResolver

ResourceResolver getResourceResolver()
Returns the ResourceResolver from which this resource has been retrieved.



Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.