org.restlet.engine.local
Class DirectoryServerResource

java.lang.Object
  extended by org.restlet.resource.Resource
      extended by org.restlet.resource.UniformResource
          extended by org.restlet.resource.ServerResource
              extended by 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
DirectoryServerResource()
           
 
Method Summary
 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.
 String getBaseName()
          Returns the local base name of the file.
protected  Restlet 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.
 String getDirectoryUri()
          Returns the context's directory URI (file, clap URI).
protected  Response getRepresentation(String resourceUri, MediaType acceptedMediaType)
          Returns a representation of the resource at the target URI.
 String getTargetUri()
          Returns the context's target URI (file, clap URI).
 List<Variant> getVariants()
          Returns a modifiable list of exposed variants for the current request method.
protected  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(String targetUri)
          Sets the context's target URI (file, clap URI).
 
Methods inherited from class org.restlet.resource.ServerResource
abort, commit, delete, describeVariants, doCatch, doConditionalHandle, doError, doHandle, doHandle, doNegotiatedHandle, get, getAttribute, getInfo, getInfo, getOnSent, getPreferredVariant, hasAnnotations, head, head, isAnnotated, isAutoCommitting, isCommitted, isConditional, isExisting, isInRole, isNegotiated, options, options, post, post, put, redirectPermanent, redirectPermanent, redirectSeeOther, redirectSeeOther, redirectTemporary, redirectTemporary, setAllowedMethods, setAnnotated, setAttribute, setAutoCommitting, setChallengeRequests, setCommitted, setConditional, setCookieSettings, setDimensions, setExisting, setLocationRef, setLocationRef, setNegotiated, setOnSent, setProxyChallengeRequests, setServerInfo, setStatus, setStatus, setStatus, setStatus, updateAllowedMethods, updateDimensions
 
Methods inherited from class org.restlet.resource.Resource
doError, doRelease, getAllowedMethods, getApplication, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getConnegService, getContext, getConverterService, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMatrixValue, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getProxyChallengeRequests, getProxyChallengeResponse, getQuery, getQueryValue, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestCacheDirectives, getRequestEntity, getResponse, getResponseAttributes, getResponseCacheDirectives, getResponseEntity, getRootRef, getServerInfo, getStatus, getStatusService, init, isConfidential, isLoggable, release, setApplication, setQueryValue, setRequest, setResponse, toObject, toRepresentation, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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:

The following constraints must be taken into account:

Overrides:
doInit in class Resource
Throws:
ResourceException
See Also:
Resource.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 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.

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(String targetUri)
Sets the context's target URI (file, clap URI).

Parameters:
targetUri - The context's target URI.


Copyright © 2005-2014 Restlet.