Package org.restlet.engine.local
Class DirectoryServerResource
java.lang.Object
org.restlet.resource.Resource
org.restlet.resource.ServerResource
org.restlet.engine.local.DirectoryServerResource
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondelete()Deletes the resource and all its representations.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.Returns the local base name of the file.protected RestletReturns a client dispatcher.Returns the parent directory handler.protected ReferenceListIf the resource is a directory, this returns its content.Returns the context's directory URI (file, clap URI).protected ResponsegetRepresentation(String resourceUri, MediaType acceptedMediaType) Returns a representation of the resource at the target URI.Returns the context's target URI (file, clap URI).Returns a modifiable list of exposed variants for the current request method.getVariants(Method method) Returns the list of variants for the given method.handle()Handles any call to this resource.booleanIndicates if the target resource is a directory.booleanIndicates if the target resource is a file.voidPrevent the client from accessing resources in upper directoriesput(Representation entity) Creates or updates a resource with the given representation as new state to be stored.voidsetTargetUri(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, 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, updateDimensionsMethods 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
-
Constructor Details
-
DirectoryServerResource
public DirectoryServerResource()
-
-
Method Details
-
delete
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:
-
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. 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:
-
get
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:
-
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
Returns a client dispatcher.- Returns:
- A client dispatcher.
-
getDirectory
Returns the parent directory handler.- Returns:
- The parent directory handler.
-
getDirectoryContent
If the resource is a directory, this returns its content.- Returns:
- The directory content.
-
getDirectoryUri
Returns the context's directory URI (file, clap URI).- Returns:
- The context's directory URI (file, clap URI).
-
getRepresentation
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
Returns the context's target URI (file, clap URI).- Returns:
- The context's target URI (file, clap URI).
-
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
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.
-
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.
-
preventUpperDirectoryAccess
public void preventUpperDirectoryAccess()Prevent the client from accessing resources in upper directories -
put
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:
-
setTargetUri
Sets the context's target URI (file, clap URI).- Parameters:
targetUri- The context's target URI.
-