Class JcrResourceProvider

java.lang.Object
org.apache.sling.spi.resource.provider.ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider

@Adaptable(adaptableClass=ResourceProvider.class,adapters={@Adapter(value=javax.jcr.Session.class,condition="If the JcrResourceProvider is loaded"),@Adapter(value=java.security.Principal.class,condition="If the underlying java.jcr.Session implements JackrabbitSession")}) public class JcrResourceProvider extends ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
  • Constructor Details

    • JcrResourceProvider

      public JcrResourceProvider()
  • Method Details

    • activate

      protected void activate(org.osgi.service.component.ComponentContext context, org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.Configuration configuration)
    • deactivate

      protected void deactivate()
    • bindDynamicClassLoaderManager

      protected void bindDynamicClassLoaderManager(DynamicClassLoaderManager dynamicClassLoaderManager)
    • unbindDynamicClassLoaderManager

      protected void unbindDynamicClassLoaderManager(DynamicClassLoaderManager dynamicClassLoaderManager)
    • start

      public void start(@NotNull @NotNull ProviderContext ctx)
      Description copied from class: ResourceProvider
      With a call to this method, the provider implementation is notified that it is used in the resource tree.
      Overrides:
      start in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The context for this provider.
    • stop

      public void stop()
      Description copied from class: ResourceProvider
      With a call to this method, the provider implementation is notified that it is not used anymore in the resource tree.
      Overrides:
      stop in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
    • update

      public void update(long changeSet)
      Description copied from class: ResourceProvider
      With a call to this method, the provider implementation is notified that any information regarding the registration of the provider has changed. For example, observation listeners might have changed. This method is only called while the provider is used in the resource tree.
      Overrides:
      update in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      changeSet - A bit set of provider info that has changed.
      See Also:
    • isIdAddressingEnabled

      public static boolean isIdAddressingEnabled()
      Check if ID addressing is enabled.
      Returns:
      true if ID addressing is enabled, false otherwise.
    • authenticate

      @NotNull public @NotNull org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState authenticate(@NotNull @NotNull Map<String,Object> authenticationInfo) throws LoginException
      Create a new ResourceResolver wrapping a Session object. Carries map of authentication info in order to create a new resolver as needed.
      Overrides:
      authenticate in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      authenticationInfo - A map of further credential information which may be used by the implementation to parameterize how the resource resolver is created.
      Returns:
      A context data object according to the authenticationInfo.
      Throws:
      LoginException - If an error occurs authenticating with the provided credential data.
      See Also:
    • logout

      public void logout(@Nullable @Nullable org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState state)
      Description copied from class: ResourceProvider
      If the provider requires authentication, this method is called with the state of the user returned by ResourceProvider.authenticate(Map) once the resource resolver is closed.
      Overrides:
      logout in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      state - The provider state returned by ResourceProvider.authenticate(Map).
    • isLive

      public boolean isLive(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx)
      Description copied from class: ResourceProvider
      Returns true if this resource provider has not been closed yet and can still be used.

      This method will never throw an exception even after the resource provider has been closed

      This method is only called for resource providers which have a state and require authentication.

      Overrides:
      isLive in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      Returns:
      true if the resource provider has not been closed yet and is still active.. Once the resource provider has been closed or is not active anymore, this method returns false.
    • getResource

      @Nullable public @Nullable Resource getResource(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull String path, @NotNull @NotNull ResourceContext rCtx, @Nullable @Nullable Resource parent)
      Description copied from class: ResourceProvider
      Returns a resource from this resource provider or null if the resource provider cannot find it. The path must have the ResourceProvider.PROPERTY_ROOT strings as its prefix. The resource provider must not return cached instances for a resource as the resource resolver will update the resource meta data of the resource at the end of the resolution process and this meta data might be different depending on the full path of resource resolution passed into the resource resolver.
      Specified by:
      getResource in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      path - The full path of the resource.
      rCtx - Additional information for resolving the resource
      parent - Optional parent resource
      Returns:
      null If this provider does not have a resource for the path.
    • listChildren

      @Nullable public @Nullable Iterator<Resource> listChildren(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull Resource parent)
      Description copied from class: ResourceProvider
      Returns an Iterator of Resource objects loaded from the children of the given Resource. The returned Resource instances are attached to the same ResourceResolver as the given parent resource.

      This method may be called for resource providers whose root path list contains a path such that the resource path is a prefix of the list entry. This allows for the enumeration of deeply nested provided resources for which no actual parent hierarchy exists.

      The returned iterator may in turn contain resources which do not actually exist but are required to traverse the resource tree. Such resources SHOULD be SyntheticResource objects whose resource type MUST be set to ResourceProvider.RESOURCE_TYPE_SYNTHETIC. As with ResourceProvider.getResource(ResolveContext, String, ResourceContext, Resource) the returned Resource objects must not be cached objects.

      Specified by:
      listChildren in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      parent - The Resource whose children are requested.
      Returns:
      An Iterator of Resource objects or null if the resource provider has no children for the given resource.
    • getParent

      @Nullable public @Nullable Resource getParent(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull Resource child)
      Description copied from class: ResourceProvider
      Returns the parent resource from this resource provider or null if the resource provider cannot find it. The resource provider must not return cached instances for a resource as the resource resolver will update the resource meta data of the resource at the end of the resolution process and this meta data might be different depending on the full path of resource resolution passed into the resource resolver.
      Overrides:
      getParent in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      child - The child resource.
      Returns:
      null if this provider does not have a resource for the parent.
    • getAttributeNames

      @NotNull public @NotNull Collection<String> getAttributeNames(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx)
      Description copied from class: ResourceProvider
      Returns a collection of attribute names whose value can be retrieved calling the ResourceProvider.getAttribute(ResolveContext, String) method.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_ATTRIBUTABLE to the value true.

      Overrides:
      getAttributeNames in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      Returns:
      A collection of attribute names or null
    • getAttribute

      @Nullable public @Nullable Object getAttribute(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull String name)
      Description copied from class: ResourceProvider
      Returns the value of the given resource provider attribute or null if the attribute is not set or not visible (as e.g. security sensitive attributes).

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_ATTRIBUTABLE to the value true.

      Overrides:
      getAttribute in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      name - The name of the attribute to access
      Returns:
      The value of the attribute or null if the attribute is not set or not accessible.
    • create

      @NotNull public @NotNull Resource create(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @Nullable @Nullable String path, @Nullable @Nullable Map<String,Object> properties) throws PersistenceException
      Description copied from class: ResourceProvider
      Create a new resource at the given path. The new resource is put into the transient space of this provider until ResourceProvider.commit(ResolveContext) is called.

      A resource provider must value ResourceResolver.PROPERTY_RESOURCE_TYPE to set the resource type of a resource.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      create in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      path - The resource path.
      properties - Optional properties
      Returns:
      The new resource.
      Throws:
      PersistenceException - If anything fails
    • getNodeType

      @Nullable protected static @Nullable String getNodeType(@Nullable @Nullable Map<String,Object> properties, @NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx)
    • orderBefore

      public boolean orderBefore(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull Resource parent, @NotNull @NotNull String name, @Nullable @Nullable String followingSiblingName) throws PersistenceException
      Description copied from class: ResourceProvider
      Orders the child resources returned by ResourceProvider.listChildren(ResolveContext, Resource) so that a given resource is listed before the given sibling resource. The changes are transient until ResourceProvider.commit(ResolveContext) is called..
      Overrides:
      orderBefore in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      parent - the parent resource containing the child resources to order.
      name - the name of the child resource in parent to order. Must be an existing child name.
      followingSiblingName - the name of the resource child in parent which should come after the reordered resource. If null is given the resource is ordered as last among all sibling resources.
      Returns:
      true in case the order of the child resources in parent has been changed, false if the given resource were already in the desired order.
      Throws:
      PersistenceException - If the operation fails in the underlying resource provider, e.g. in case the parent resource does not support orderable children.
      See Also:
    • delete

      public void delete(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull Resource resource) throws PersistenceException
      Description copied from class: ResourceProvider
      Delete the resource at the given path. This change is kept in the transient space of this provider until ResourceProvider.commit(ResolveContext) is called.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      delete in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      resource - The resource to delete.
      Throws:
      PersistenceException - If anything fails
    • revert

      public void revert(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx)
      Description copied from class: ResourceProvider
      Revert all transient changes: create, delete and updates.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      revert in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
    • commit

      public void commit(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx) throws PersistenceException
      Description copied from class: ResourceProvider
      Commit all transient changes: create, delete and updates

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      commit in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      Throws:
      PersistenceException - If anything fails
    • hasChanges

      public boolean hasChanges(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx)
      Description copied from class: ResourceProvider
      Are there any transient changes?

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      hasChanges in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      Returns:
      true if there are pending changes.
    • refresh

      public void refresh(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx)
      Description copied from class: ResourceProvider
      The provider is updated to reflect the latest state. Resources which have changes pending are not discarded. ResourceProvider.revert(ResolveContext) can be called to discard changes.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_REFRESHABLE to the value true.

      Overrides:
      refresh in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
    • adaptTo

      @Nullable public <AdapterType> AdapterType adaptTo(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull Class<AdapterType> type)
      Description copied from class: ResourceProvider
      Adapts the provider to another type.

      Please not that it is explicitly left as an implementation detail whether each call to this method with the same type yields the same object or a new object on each call.

      Implementations of this method should document their adapted types as well as their behavior with respect to returning newly created or not instance on each call.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_ADAPTABLE to the value true.

      Overrides:
      adaptTo in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Type Parameters:
      AdapterType - The generic type to which this resource is adapted to.
      Parameters:
      ctx - The ResolveContext.
      type - The generic type to which this resource is adapted to.
      Returns:
      The adapter target or null if the provider cannot be adapt to the requested type.
    • copy

      public boolean copy(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull String srcAbsPath, @NotNull @NotNull String destAbsPath)
      Description copied from class: ResourceProvider
      This method copies the subgraph rooted at, and including, the resource at srcAbsPath to the new location at destAbsPath and adds it as a child node of the resource at destAbsPath.

      Both resources are resources from this provider and the full tree is provided by this provider as well.

      The resource at destAbsPath needs to exist, if not a PersistenceException is thrown. If a child resource with the same name already exists at destAbsPath a PersistenceException is thrown.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      copy in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      srcAbsPath - the path of the resource to be copied.
      destAbsPath - the location to which the resource at srcAbsPath is to be copied.
      Returns:
      true if the provider can perform the copy
    • move

      public boolean move(@NotNull @NotNull ResolveContext<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> ctx, @NotNull @NotNull String srcAbsPath, @NotNull @NotNull String destAbsPath) throws PersistenceException
      Description copied from class: ResourceProvider
      This method moves the subgraph rooted at, and including, the resource at srcAbsPath to the new location at destAbsPath and adds it as a child node of the resource at destAbsPath.

      Both resources are resources from this provider and the full tree is provided by this provider as well.

      The resource at destAbsPath needs to exist, if not a PersistenceException is thrown. If a child resource with the same name already exists at destAbsPath a PersistenceException is thrown.

      This method is only called if the provider supports this and indicates it by setting the ResourceProvider.PROPERTY_MODIFIABLE to the value true.

      Overrides:
      move in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Parameters:
      ctx - The ResolveContext.
      srcAbsPath - the path of the resource to be copied.
      destAbsPath - the location to which the resource at srcAbsPath is to be moved.
      Returns:
      true if the provider can perform the move
      Throws:
      PersistenceException - If an error occurs.
    • getQueryLanguageProvider

      @Nullable public @Nullable QueryLanguageProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState> getQueryLanguageProvider()
      Description copied from class: ResourceProvider
      Get the optional query language provider. If the provider supports this kind of query, it must return a query provider implementation if the provider is active. It should not return a query provider if it is not active. This method is called for each query, therefore the provider implementation might cache the provider object.
      Overrides:
      getQueryLanguageProvider in class ResourceProvider<org.apache.sling.jcr.resource.internal.helper.jcr.JcrProviderState>
      Returns:
      A query language provider if this resource provider supports this type of querying.