org.apache.sling.resourceresolver.impl.tree
Class ResourceProviderEntry

java.lang.Object
  extended by org.apache.sling.resourceresolver.impl.tree.ResourceProviderEntry
All Implemented Interfaces:
Comparable<ResourceProviderEntry>
Direct Known Subclasses:
RootResourceProviderEntry

public class ResourceProviderEntry
extends Object
implements Comparable<ResourceProviderEntry>

The ResourceProviderEntry class represents a node in the tree of resource providers spanned by the root paths of the provider resources.

That means this class has a map of child ResourceProviderEntries, keyed by the child name and a list of ProviderHandlers that are mapped to the path that this ResourceProviderEntry represents. To locate a list of potential ResourceProviders the path is split into elements and then that list used to walk down the tree of ResourceProviders. eg: for a path /a/b/c/d the list of ProviderHandlers would be accessed by rootProvider.get("a").get("b").get("c").get("d") assuming the final get("d") was not null. If it was, then the list of ProviderHanders would be rootProvider.get("a").get("b").get("c").

This class is comparable to itself to help keep the child entries list sorted by their prefix.


Constructor Summary
ResourceProviderEntry(String path, ProviderHandler[] providerList)
          Creates an instance of this class with the given path relative to the parent resource provider entry, encapsulating the given ResourceProvider, and a number of initial child entries.
 
Method Summary
protected  boolean addResourceProvider(String prefix, ProviderHandler provider)
          Adds the given resource provider into the tree for the given prefix.
 int compareTo(ResourceProviderEntry o)
           
 boolean containsKey(String key)
           
 org.apache.sling.api.resource.Resource create(ResourceResolverContext ctx, org.apache.sling.api.resource.ResourceResolver resourceResolver, String fullPath, Map<String,Object> properties)
          Create a resource
 void delete(ResourceResolverContext ctx, org.apache.sling.api.resource.ResourceResolver resourceResolver, org.apache.sling.api.resource.Resource resource)
          Delete the resource
 ResourceProviderEntry get(String key)
           
 String getPath()
           
 org.apache.sling.api.resource.Resource getResource(ResourceResolverContext ctx, org.apache.sling.api.resource.ResourceResolver resourceResolver, String path, boolean isResolve)
          Returns the resource with the given path or null if neither the resource provider of this entry nor the resource provider of any of the child entries can provide the resource.
 org.apache.sling.api.resource.Resource getResourceFromProviders(ResourceResolverContext ctx, org.apache.sling.api.resource.ResourceResolver resourceResolver, String fullPath)
           
 ProviderHandler[] getResourceProviders()
          Returns the resource providers contained in this entry
 void put(String key, ResourceProviderEntry value)
           
protected  boolean removeResourceProvider(String prefix, ProviderHandler resourceProvider)
          Remove the given resource provider from the tree
static String[] split(String st)
          Split the string by slash.
 String toString()
          
 Collection<ResourceProviderEntry> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceProviderEntry

public ResourceProviderEntry(String path,
                             ProviderHandler[] providerList)
Creates an instance of this class with the given path relative to the parent resource provider entry, encapsulating the given ResourceProvider, and a number of initial child entries.

Parameters:
path - The relative path supported by the provider
providerList - The resource provider to encapsulate by this entry.
Method Detail

getPath

public String getPath()

getResourceProviders

public ProviderHandler[] getResourceProviders()
Returns the resource providers contained in this entry


getResource

public org.apache.sling.api.resource.Resource getResource(ResourceResolverContext ctx,
                                                          org.apache.sling.api.resource.ResourceResolver resourceResolver,
                                                          String path,
                                                          boolean isResolve)
Returns the resource with the given path or null if neither the resource provider of this entry nor the resource provider of any of the child entries can provide the resource.

Parameters:
path - The path to the resource to return.
Returns:
The resource for the path or null if no resource can be found.
Throws:
org.apache.sling.api.SlingException - if an error occurrs trying to access an existing resource.

put

public void put(String key,
                ResourceProviderEntry value)

containsKey

public boolean containsKey(String key)

get

public ResourceProviderEntry get(String key)

values

public Collection<ResourceProviderEntry> values()

compareTo

public int compareTo(ResourceProviderEntry o)
Specified by:
compareTo in interface Comparable<ResourceProviderEntry>
See Also:
Comparable.compareTo(java.lang.Object)

addResourceProvider

protected boolean addResourceProvider(String prefix,
                                      ProviderHandler provider)
Adds the given resource provider into the tree for the given prefix. This will expand the tree of ResourceProviderEntries down the supplied prefix and add the provider to a ResourceProviderEntry that represents the last element of the path.

Returns:
true if the provider could be entered into the subtree below this entry. Otherwise false is returned.

removeResourceProvider

protected boolean removeResourceProvider(String prefix,
                                         ProviderHandler resourceProvider)
Remove the given resource provider from the tree


getResourceFromProviders

public org.apache.sling.api.resource.Resource getResourceFromProviders(ResourceResolverContext ctx,
                                                                       org.apache.sling.api.resource.ResourceResolver resourceResolver,
                                                                       String fullPath)

delete

public void delete(ResourceResolverContext ctx,
                   org.apache.sling.api.resource.ResourceResolver resourceResolver,
                   org.apache.sling.api.resource.Resource resource)
            throws org.apache.sling.api.resource.PersistenceException
Delete the resource

Throws:
NullPointerException - if resource is null
UnsupportedOperationException - If deletion is not allowed/possible
org.apache.sling.api.resource.PersistenceException - If deletion fails

create

public org.apache.sling.api.resource.Resource create(ResourceResolverContext ctx,
                                                     org.apache.sling.api.resource.ResourceResolver resourceResolver,
                                                     String fullPath,
                                                     Map<String,Object> properties)
                                              throws org.apache.sling.api.resource.PersistenceException
Create a resource

Returns:
The new resource
Throws:
UnsupportedOperationException - If creation is not allowed/possible
org.apache.sling.api.resource.PersistenceException - If creation fails

split

public static String[] split(String st)
Split the string by slash. This method never returns null.

Parameters:
st - The string to split
Returns:
an array of the strings between the separator

toString

public String toString()

Overrides:
toString in class Object
See Also:
AbstractMap.toString()


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