Package org.restlet.engine.local
Class DirectoryServerResource
- java.lang.Object
-
- org.restlet.resource.Resource
-
- 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).- See Also:
- Apache mod_negotiation module
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringbaseNameThe local base name of the resource.private VariantbaseVariantThe base variant.private DirectorydirectoryThe parent directory handler.private RestletdirectoryClientDispatcherThe parent directory client dispatcher.private ReferenceListdirectoryContentIf the resource is a directory, this contains its content.private booleandirectoryRedirectionIf the resource is a directory, the non-trailing slash character leads to redirection.private booleandirectoryTargetIndicates if the target resource is a directory.private java.lang.StringdirectoryUriThe context's directory URI (file, clap URI).private RepresentationfileContentIf the resource is a file, this contains its content.private booleanfileTargetIndicates if the target resource is a file.private booleanindexTargetIndicates if the target resource is a directory with an index.private ReferenceoriginalRefThe original target URI, in case of extensions tunneling.private VariantprotoVariantThe prototype variant.private java.lang.StringrelativePartThe resource path relative to the directory URI.private java.lang.StringtargetUriThe context's target URI (file, clap URI).private ReferenceuniqueReferenceThe unique representation of the target URI, if it exists.private java.util.List<Variant>variantsGetThe list of variants for the GET method.
-
Constructor Summary
Constructors Constructor Description DirectoryServerResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Representationdelete()Deletes the resource and all its representations.private ResponsedispatchRequest(Request request)Transmit the given request to the clientDispatcher.
It completes the request's attributes map with the current Directory ("org.restlet.directory" key).private voiddispatchRequest(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).voiddoInit()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 Representationget()Returns a full representation.java.lang.StringgetBaseName()Returns the local base name of the file.protected RestletgetClientDispatcher()Returns a client dispatcher.DirectorygetDirectory()Returns the parent directory handler.protected ReferenceListgetDirectoryContent()If the resource is a directory, this returns its content.java.lang.StringgetDirectoryUri()Returns the context's directory URI (file, clap URI).private ResponsegetRepresentation(java.lang.String resourceUri)Returns a representation of the resource at the target URI.protected ResponsegetRepresentation(java.lang.String resourceUri, MediaType acceptedMediaType)Returns a representation of the resource at the target URI.private java.util.Comparator<Representation>getRepresentationsComparator()Allows to sort the list of representations set by the resource.java.lang.StringgetTargetUri()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.private java.lang.StringgetVariantsBaseReference()private ReferenceListgetVariantsReferences()Returns the references of the representations of the target resource according to the directory handler propertyRepresentationhandle()Handles any call to this resource.booleanisDirectoryTarget()Indicates if the target resource is a directory.booleanisFileTarget()Indicates if the target resource is a file.voidpreventUpperDirectoryAccess()Prevent the client from accessing resources in upper directoriesRepresentationput(Representation entity)Creates or updates a resource with the given representation as new state to be stored.voidsetTargetUri(java.lang.String targetUri)Sets the context's target URI (file, clap URI).private ReferenceListtryToConvertAsReferenceList(Representation entity)-
Methods inherited from class org.restlet.resource.ServerResource
abort, commit, delete, describeVariants, doCatch, doConditionalHandle, doError, doHandle, doHandle, doHandle, doNegotiatedHandle, get, getAnnotation, getAnnotation, getAnnotations, getAttribute, getDescription, getInfo, getInfo, getName, getOnSent, getPreferredVariant, getRole, hasAnnotations, head, head, isAnnotated, isAutoCommitting, isCommitted, isConditional, isExisting, isInRole, isNegotiated, options, options, patch, patch, post, post, put, redirectPermanent, redirectPermanent, redirectSeeOther, redirectSeeOther, redirectTemporary, redirectTemporary, setAllowedMethods, setAnnotated, setAttribute, setAutoCommitting, setChallengeRequests, setCommitted, setConditional, setCookieSettings, setDescription, setDimensions, setExisting, setLocationRef, setLocationRef, setName, 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, toBoolean, toByte, toDouble, toFloat, toInteger, toLong, toObject, toRepresentation, toRepresentation, toRepresentation, toShort, toString
-
-
-
-
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.
-
-
Method Detail
-
delete
public Representation delete() throws ResourceException
Description copied from class:ServerResourceDeletes the resource and all its representations. This method is only invoked if content negotiation has been disabled as indicated by theServerResource.isNegotiated(), otherwise theServerResource.delete(Variant)method is invoked.
The default behavior is to set the response status toStatus.CLIENT_ERROR_METHOD_NOT_ALLOWED.- Overrides:
deletein classServerResource- Returns:
- The optional response entity.
- Throws:
ResourceException- See Also:
- HTTP DELETE method
-
doInit
public void doInit() throws ResourceExceptionThis 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:
doInitin classResource- Throws:
ResourceException- See Also:
Resource.init(Context, Request, Response)
-
tryToConvertAsReferenceList
private ReferenceList tryToConvertAsReferenceList(Representation entity) throws ResourceException
- Throws:
ResourceException
-
get
protected Representation get() throws ResourceException
Description copied from class:ServerResourceReturns a full representation. This method is only invoked if content negotiation has been disabled as indicated by theServerResource.isNegotiated(), otherwise theServerResource.get(Variant)method is invoked.
The default behavior is to set the response status toStatus.CLIENT_ERROR_METHOD_NOT_ALLOWED.- Overrides:
getin classServerResource- 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 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:ServerResourceReturns 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:
getVariantsin classServerResource- 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:
getVariantsin classServerResource- 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
-
handle
public Representation handle()
Description copied from class:ServerResourceHandles any call to this resource. The default implementation check theServerResource.isConditional()andServerResource.isNegotiated()method to determine which one of theServerResource.doConditionalHandle(),ServerResource.doNegotiatedHandle()andServerResource.doHandle()methods should be invoked. It also catches anyResourceExceptionthrown and updates the response status using theServerResource.setStatus(Status, Throwable, String)method.
After handling, if the status is set toStatus.CLIENT_ERROR_METHOD_NOT_ALLOWED, thenServerResource.updateAllowedMethods()is invoked to give the resource a chance to inform the client about the allowed methods.- Overrides:
handlein classServerResource- 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.
-
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
-
put
public Representation put(Representation entity) throws ResourceException
Description copied from class:ServerResourceCreates 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 theServerResource.isNegotiated(), otherwise theServerResource.put(Representation, Variant)method is invoked.
The default behavior is to set the response status toStatus.CLIENT_ERROR_METHOD_NOT_ALLOWED.- Overrides:
putin classServerResource- 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.
-
-