org.restlet.engine.local

## Class DirectoryServerResource

- java.lang.Object
- - org.restlet.resource.UniformResource
  - - org.restlet.resource.ServerResource
    - - org.restlet.engine.local.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:
  Apache mod_negotiation module

### Constructor Summary

Constructors
Constructor and Description
`DirectoryServerResource()`

### Method Summary

Methods
`Representation` `delete()` Deletes the resource and all its representations.

`void`

`doInit()`
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.

`protected Representation` `get()` Returns a full representation.
`java.lang.String` `getBaseName()` Returns the local base name of the file.
`protected Client` `getClientDispatcher()` Returns a client dispatcher.
`Directory` `getDirectory()` Returns the parent directory handler.
`protected ReferenceList` `getDirectoryContent()` If the resource is a directory, this returns its content.
`java.lang.String` `getDirectoryUri()` Returns the context's directory URI (file, clap URI).
`protected Response` `getRepresentation(java.lang.String resourceUri, MediaType acceptedMediaType)` Returns a representation of the resource at the target URI.
`java.lang.String` `getTargetUri()` Returns the context's target URI (file, clap URI).
`java.util.List<Variant>` `getVariants()` Returns a modifiable list of exposed variants for the current request method.
`protected java.util.List<Variant>` `getVariants(Method method)` Returns the list of variants for the given method.
`Representation` `handle()` Handles any call to this resource.
`boolean` `isDirectoryTarget()` Indicates if the target resource is a directory.
`boolean` `isFileTarget()` Indicates if the target resource is a file.
`Representation` `put(Representation entity)` Creates or updates a resource with the given representation as new state to be stored.
`void` `setTargetUri(java.lang.String targetUri)` Sets the context's target URI (file, clap URI).

### Methods inherited from class org.restlet.resource.ServerResource

`abort, commit, delete, describeVariants, doConditionalHandle, doHandle, doHandle, doNegotiatedHandle, get, getInfo, getInfo, getOnSent, getPreferredVariant, head, head, isAnnotated, isAutoCommitting, isCommitted, isConditional, isExisting, isInRole, isNegotiated, options, options, post, post, put, redirectPermanent, redirectPermanent, redirectSeeOther, redirectSeeOther, redirectTemporary, redirectTemporary, setAllowedMethods, setAnnotated, setAutoCommitting, setChallengeRequests, setCommitted, setConditional, setCookieSettings, setDimensions, setExisting, setLocationRef, setLocationRef, setNegotiated, setOnSent, setServerInfo, setStatus, setStatus, setStatus, setStatus, updateAllowedMethods, updateDimensions`

### Methods inherited from class org.restlet.resource.UniformResource

`doCatch, doRelease, getAllowedMethods, getApplication, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getContext, getConverterService, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getQuery, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestEntity, getResponse, getResponseAttributes, getResponseEntity, getRootRef, getServerInfo, getStatus, getStatusService, init, isConfidential, release, setRequest, setResponse, toObject, toRepresentation`

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

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

### Constructor Detail

#### DirectoryServerResource

    public DirectoryServerResource()

### Method Detail

#### 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:
  HTTP DELETE method

#### 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 `UniformResource`
Throws:
  `ResourceException`
See Also:
  `UniformResource.init(Context, Request, Response)`

#### 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:
  HTTP GET method

#### 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 Client 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

    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.

#### 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.

#### 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.

#### 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.

#### 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:
  HTTP PUT method

#### setTargetUri

    public void setTargetUri(java.lang.String targetUri)

Sets the context's target URI (file, clap URI).

Parameters:
  `targetUri` - The context's target URI.