Class DirectoryServerResource


public class DirectoryServerResource extends ServerResource
Resource supported by a set of context representations (from file system, class loaders and webapp context). A content negotiation mechanism (similar to Apache HTTP server) is available. It is based on path extensions to detect variants (languages, media types or character sets).
Author:
Jerome Louvel, Thierry Boileau
See Also:
  • Constructor Details

    • DirectoryServerResource

      public DirectoryServerResource()
  • Method Details

    • delete

      public Representation delete() throws ResourceException
      Description copied from class: ServerResource
      Deletes the resource and all its representations. This method is only invoked if content negotiation has been disabled as indicated by the ServerResource.isNegotiated(), otherwise the ServerResource.delete(Variant) method is invoked.

      The default behavior is to set the response status to Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.
      Overrides:
      delete in class ServerResource
      Returns:
      The optional response entity.
      Throws:
      ResourceException
      See Also:
    • doInit

      public void doInit() throws ResourceException
      This initialization method aims at answering the following questions:
      • does this request target a directory?
      • does this request target a directory, with an index file?
      • should this request be redirected (target is a directory with no trailing "/")?
      • does this request target a file?

      The following constraints must be taken into account:
      • the underlying helper may not support content negotiation and be able to return the list of possible variants of the target file (e.g. the CLAP helper).
      • the underlying helper may not support directory listing
      • the extensions tunneling cannot apply on a directory
      • underlying helpers that do not support content negotiation cannot support extensions tunneling
      Overrides:
      doInit in class Resource
      Throws:
      ResourceException
      See Also:
    • get

      protected Representation get() throws ResourceException
      Description copied from class: ServerResource
      Returns a full representation. This method is only invoked if content negotiation has been disabled as indicated by the ServerResource.isNegotiated() , otherwise the ServerResource.get(Variant) method is invoked.

      The default behavior is to set the response status to Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.
      Overrides:
      get in class ServerResource
      Returns:
      The resource's representation.
      Throws:
      ResourceException
      See Also:
    • getBaseName

      public String getBaseName()
      Returns the local base name of the file. For example, "foo.en" and "foo.en-GB.html" return "foo".
      Returns:
      The local name of the file.
    • getClientDispatcher

      protected Restlet getClientDispatcher()
      Returns a client dispatcher.
      Returns:
      A client dispatcher.
    • getDirectory

      public Directory getDirectory()
      Returns the parent directory handler.
      Returns:
      The parent directory handler.
    • getDirectoryContent

      protected ReferenceList getDirectoryContent()
      If the resource is a directory, this returns its content.
      Returns:
      The directory content.
    • getDirectoryUri

      public String getDirectoryUri()
      Returns the context's directory URI (file, clap URI).
      Returns:
      The context's directory URI (file, clap URI).
    • getRepresentation

      protected Response getRepresentation(String resourceUri, MediaType acceptedMediaType)
      Returns a representation of the resource at the target URI. Leverages the client dispatcher of the parent directory's context.
      Parameters:
      resourceUri - The URI of the target resource.
      acceptedMediaType - The accepted media type or null.
      Returns:
      A response with the representation if success.
    • getTargetUri

      public String getTargetUri()
      Returns the context's target URI (file, clap URI).
      Returns:
      The context's target URI (file, clap URI).
    • getVariants

      public List<Variant> getVariants()
      Description copied from class: ServerResource
      Returns a modifiable list of exposed variants for the current request method. You can declare variants manually by updating the result list , by overriding this method. By default, the variants will be provided based on annotated methods.
      Overrides:
      getVariants in class ServerResource
      Returns:
      The modifiable list of variants.
    • getVariants

      protected List<Variant> getVariants(Method method)
      Returns the list of variants for the given method.
      Overrides:
      getVariants in class ServerResource
      Parameters:
      method - The related method.
      Returns:
      The list of variants for the given method.
    • handle

      public Representation handle()
      Description copied from class: ServerResource
      Handles any call to this resource. The default implementation check the ServerResource.isConditional() and ServerResource.isNegotiated() method to determine which one of the ServerResource.doConditionalHandle(), ServerResource.doNegotiatedHandle() and ServerResource.doHandle() methods should be invoked. It also catches any ResourceException thrown and updates the response status using the ServerResource.setStatus(Status, Throwable, String) method.

      After handling, if the status is set to Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, then ServerResource.updateAllowedMethods() is invoked to give the resource a chance to inform the client about the allowed methods.
      Overrides:
      handle in class ServerResource
      Returns:
      The response entity, but this method is still responsible for setting the response entity.
    • isDirectoryTarget

      public boolean isDirectoryTarget()
      Indicates if the target resource is a directory.
      Returns:
      True if the target resource is a directory.
    • isFileTarget

      public boolean isFileTarget()
      Indicates if the target resource is a file.
      Returns:
      True if the target resource is a file.
    • preventUpperDirectoryAccess

      public void preventUpperDirectoryAccess()
      Prevent the client from accessing resources in upper directories
    • put

      public Representation put(Representation entity) throws ResourceException
      Description copied from class: ServerResource
      Creates or updates a resource with the given representation as new state to be stored. This method is only invoked if content negotiation has been disabled as indicated by the ServerResource.isNegotiated(), otherwise the ServerResource.put(Representation, Variant) method is invoked.

      The default behavior is to set the response status to Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.
      Overrides:
      put in class ServerResource
      Parameters:
      entity - The representation to store.
      Returns:
      The optional result entity.
      Throws:
      ResourceException
      See Also:
    • setTargetUri

      public void setTargetUri(String targetUri)
      Sets the context's target URI (file, clap URI).
      Parameters:
      targetUri - The context's target URI.