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).
    See Also:
    Apache mod_negotiation module
    • Field Detail

      • variantsGet

        private volatile java.util.List<Variant> variantsGet
        The list of variants for the GET method.
      • baseName

        private volatile java.lang.String baseName
        The local base name of the resource. For example, "foo.en" and "foo.en-GB.html" return "foo".
      • baseVariant

        private volatile Variant baseVariant
        The base variant.
      • directoryClientDispatcher

        private volatile Restlet directoryClientDispatcher
        The parent directory client dispatcher.
      • directory

        private volatile Directory directory
        The parent directory handler.
      • directoryContent

        private volatile ReferenceList directoryContent
        If the resource is a directory, this contains its content.
      • directoryRedirection

        private volatile boolean directoryRedirection
        If the resource is a directory, the non-trailing slash character leads to redirection.
      • directoryTarget

        private volatile boolean directoryTarget
        Indicates if the target resource is a directory.
      • directoryUri

        private volatile java.lang.String directoryUri
        The context's directory URI (file, clap URI).
      • fileContent

        private volatile Representation fileContent
        If the resource is a file, this contains its content.
      • fileTarget

        private volatile boolean fileTarget
        Indicates if the target resource is a file.
      • indexTarget

        private volatile boolean indexTarget
        Indicates if the target resource is a directory with an index.
      • originalRef

        private volatile Reference originalRef
        The original target URI, in case of extensions tunneling.
      • protoVariant

        private volatile Variant protoVariant
        The prototype variant.
      • relativePart

        private volatile java.lang.String relativePart
        The resource path relative to the directory URI.
      • targetUri

        private volatile java.lang.String targetUri
        The context's target URI (file, clap URI).
      • uniqueReference

        private volatile Reference uniqueReference
        The unique representation of the target URI, if it exists.
    • Constructor Detail

      • DirectoryServerResource

        public DirectoryServerResource()
    • Method Detail

      • 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:
        Resource.init(Context, Request, Response)
      • getBaseName

        public java.lang.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 java.lang.String getDirectoryUri()
        Returns the context's directory URI (file, clap URI).
        Returns:
        The context's directory URI (file, clap URI).
      • getRepresentation

        private Response getRepresentation​(java.lang.String resourceUri)
        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.
        Returns:
        A response with the representation if success.
      • getRepresentation

        protected Response getRepresentation​(java.lang.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.
      • getRepresentationsComparator

        private java.util.Comparator<Representation> getRepresentationsComparator()
        Allows to sort the list of representations set by the resource.
        Returns:
        A Comparator instance imposing a sort order of representations or null if no special order is wanted.
      • getTargetUri

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

        public java.util.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 java.util.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.
      • getVariantsBaseReference

        private java.lang.String getVariantsBaseReference()
      • getVariantsReferences

        private ReferenceList getVariantsReferences()
        Returns the references of the representations of the target resource according to the directory handler property
        Returns:
        The list of variants references
      • 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.
      • dispatchRequest

        private Response dispatchRequest​(Request request)
        Transmit the given request to the clientDispatcher.
        It completes the request's attributes map with the current Directory ("org.restlet.directory" key).
        Parameters:
        request - The request to send.
        Returns:
        The response
      • dispatchRequest

        private void dispatchRequest​(Request request,
                                     Response response)
        Transmit the given request to the clientDispatcher.
        It completes the request's attributes map with the current Directory ("org.restlet.directory" key).
        Parameters:
        request - The request to send.
        response - The related response.
      • preventUpperDirectoryAccess

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

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