Package org.apache.sling.resourcemerger.impl.picker

## Class SearchPathBasedResourcePicker

- java.lang.Object
- - org.apache.sling.resourcemerger.impl.picker.SearchPathBasedResourcePicker

All Implemented Interfaces:
  `ResourceMergerService`, `MergedResourcePicker2`

    public class SearchPathBasedResourcePicker
    extends Object
    implements MergedResourcePicker2, ResourceMergerService

### Field Summary

Fields
`static String` `DEFAULT_ROOT`

### Fields inherited from interface org.apache.sling.resourcemerger.spi.MergedResourcePicker2

`MERGE_ROOT, READ_ONLY, TRAVERSE_PARENT`

### Constructor Summary

Constructors
`SearchPathBasedResourcePicker()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `configure​(org.apache.sling.resourcemerger.impl.picker.SearchPathBasedResourcePicker.Configuration configuration)`
`org.apache.sling.api.resource.Resource` `getMergedResource​(org.apache.sling.api.resource.Resource resource)` Returns a merged resource if the provided resource is from one of the search paths and the resource is not hidden.
`String` `getMergedResourcePath​(String relativePath)` Returns the absolute path for the provided relative path.
`String` `getResourcePath​(String searchPath, String mergedResourcePath)` Return a resource path by taking the path of the merged resource, removing the mount point and replacing it with the search path.
`boolean` `isMergedResource​(org.apache.sling.api.resource.Resource resource)` Returns `true` if the provided `Resource` is a merged resource.
`List<org.apache.sling.api.resource.Resource>` `pickResources​(org.apache.sling.api.resource.ResourceResolver resolver, String relativePath, org.apache.sling.api.resource.Resource relatedResource)` Method invoked by the MergingResourceProvider to identify the resources to be merged for a given relative path.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_ROOT

    public static final String DEFAULT_ROOT

See Also:
  Constant Field Values

### Constructor Detail

#### SearchPathBasedResourcePicker

    public SearchPathBasedResourcePicker()

### Method Detail

#### pickResources

    public List<org.apache.sling.api.resource.Resource> pickResources​(org.apache.sling.api.resource.ResourceResolver resolver,
                                                                      String relativePath,
                                                                      org.apache.sling.api.resource.Resource relatedResource)

Description copied from interface: `MergedResourcePicker2`
Method invoked by the MergingResourceProvider to identify the resources to be merged for a given relative path. The resources returned may be either resources returned from the ResourceResolver directory or an instance of NonExistingResource. Returning an empty list will cause the resource to not exist for consumers (resolver.getResource(path) will return null).

Specified by:
  `pickResources` in interface `MergedResourcePicker2`
Parameters:
  `resolver` - the ResourceResolver
  `relativePath` - the path relative to the merge root
  `relatedResource` - an optional resource which is related to the given path (always the parent resource or `null`)
Returns:
  a List of Resource objects

#### getMergedResourcePath

    public String getMergedResourcePath​(String relativePath)

Returns the absolute path for the provided relative path.

Specified by:
  `getMergedResourcePath` in interface `ResourceMergerService`
Parameters:
  `relativePath` - The relative path
Returns:
  Returns the merged resource path

#### getMergedResource

    public org.apache.sling.api.resource.Resource getMergedResource​(org.apache.sling.api.resource.Resource resource)

Returns a merged resource if the provided resource is from one of the search paths and the resource is not hidden. If the resource is `null`, `null` is returned.

Specified by:
  `getMergedResource` in interface `ResourceMergerService`
Parameters:
  `resource` - The resource
Returns:
  Returns the merged resource or `null`

#### isMergedResource

    public boolean isMergedResource​(org.apache.sling.api.resource.Resource resource)

Returns `true` if the provided `Resource` is a merged resource. If the resource is `null`, `false` is returned.

Specified by:
  `isMergedResource` in interface `ResourceMergerService`
Parameters:
  `resource` - The resource
Returns:
  Returns `true` if the provided `Resource` is a merged resource.

#### getResourcePath

    public String getResourcePath​(String searchPath,
                                  String mergedResourcePath)

Return a resource path by taking the path of the merged resource, removing the mount point and replacing it with the search path. For example, if the provided search path is "/apps/" and the merged resource path is "/mnt/overlay/my/resource", the result will be "/apps/my/resource".

Specified by:
  `getResourcePath` in interface `ResourceMergerService`
Parameters:
  `searchPath` - The search path, this is an absolute path ending with a slash as returned by the resource resolver
  `mergedResourcePath` - An absolute path to a merged resource
Returns:
  The path to the resource

#### configure

    protected void configure​(org.apache.sling.resourcemerger.impl.picker.SearchPathBasedResourcePicker.Configuration configuration)