org.restlet
Class Directory

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Finder
              extended by org.restlet.Directory

public class Directory
extends Finder

Finder mapping a directory of local resources. Those resources have representations accessed by the file system or the class loaders.
An automatic content negotiation mechanism (similar to the one in Apache HTTP server) is used to select the best representation of a resource based on the available variants and on the client capabilities and preferences.
The directory can be used in read-only or modifiable mode. In the latter case, you just need to set the "modifiable" property to true. The currently supported methods are PUT and DELETE.

Author:
Jerome Louvel (contact@noelios.com)
See Also:
Tutorial: Serving static files

Constructor Summary
Directory(Context context, LocalReference rootLocalReference)
          Constructor.
Directory(Context context, String rootUri)
          Constructor.
 
Method Summary
 Resource findTarget(Request request, Response response)
          Finds the target Resource if available.
 String getIndexName()
          Returns the index name, without extensions.
 Representation getIndexRepresentation(Variant variant, ReferenceList indexContent)
          Returns an actual index representation for a given variant.
 List<Variant> getIndexVariants(ReferenceList indexContent)
          Returns the variant representations of a directory index.
 Reference getRootRef()
          Returns the root URI.
 boolean isDeeplyAccessible()
          Indicates if the subdirectories are deeply accessible (true by default).
 boolean isListingAllowed()
          Indicates if the display of directory listings is allowed when no index file is found.
 boolean isModifiable()
          Indicates if modifications to local resources (most likely files) are allowed.
 boolean isNegotiateContent()
          Indicates if the best content is automatically negotiated.
 void setDeeplyAccessible(boolean deeplyAccessible)
          Indicates if the subdirectories are deeply accessible (true by default).
 void setIndexName(String indexName)
          Sets the index name, without extensions.
 void setListingAllowed(boolean listingAllowed)
          Indicates if the display of directory listings is allowed when no index file is found.
 void setModifiable(boolean modifiable)
          Indicates if modifications to local resources are allowed.
 void setNegotiateContent(boolean negotiateContent)
          Indicates if the best content is automatically negotiated.
 
Methods inherited from class org.restlet.Finder
createResource, getTargetClass, handle
 
Methods inherited from class org.restlet.Restlet
getContext, getLogger, init, isStarted, isStopped, setContext, start, stop
 
Methods inherited from class org.restlet.Uniform
delete, delete, get, get, handle, head, head, options, options, post, post, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Directory

public Directory(Context context,
                 LocalReference rootLocalReference)
Constructor.

Parameters:
context - The context.
rootLocalReference - The root URI.

Directory

public Directory(Context context,
                 String rootUri)
Constructor.

Parameters:
context - The context.
rootUri - The absolute root URI.

If you serve files from the file system, use file:// URIs and make sure that you register a FILE connector with your parent Component. On Windows, make sure that you add enough slash characters at the beginning, for example: file:///c:/dir/file

If you serve files from a class loader, use clap:// URIs and make sure that you register a CLAP connector with your parent Component.

Method Detail

findTarget

public Resource findTarget(Request request,
                           Response response)
Finds the target Resource if available.

Overrides:
findTarget in class Finder
Parameters:
request - The request to filter.
response - The response to filter.
Returns:
The target resource if available or null.

getIndexName

public String getIndexName()
Returns the index name, without extensions. Returns "index" by default.

Returns:
The index name.

getIndexRepresentation

public Representation getIndexRepresentation(Variant variant,
                                             ReferenceList indexContent)
Returns an actual index representation for a given variant.

Parameters:
variant - The selected variant.
indexContent - The directory index to represent.
Returns:
The actual index representation.

getIndexVariants

public List<Variant> getIndexVariants(ReferenceList indexContent)
Returns the variant representations of a directory index. This method can be subclassed in order to provide alternative representations. By default it returns a simple HTML document and a textual URI list as variants.

Parameters:
indexContent - The list of references contained in the directory index.
Returns:
The variant representations of a directory.

getRootRef

public Reference getRootRef()
Returns the root URI.

Returns:
The root URI.

isDeeplyAccessible

public boolean isDeeplyAccessible()
Indicates if the subdirectories are deeply accessible (true by default).

Returns:
True if the subdirectories are deeply accessible.

isListingAllowed

public boolean isListingAllowed()
Indicates if the display of directory listings is allowed when no index file is found.

Returns:
True if the display of directory listings is allowed when no index file is found.

isModifiable

public boolean isModifiable()
Indicates if modifications to local resources (most likely files) are allowed. Returns false by default.

Returns:
True if modifications to local resources are allowed.

isNegotiateContent

public boolean isNegotiateContent()
Indicates if the best content is automatically negotiated. Default value is true.

Returns:
True if the best content is automatically negotiated.

setDeeplyAccessible

public void setDeeplyAccessible(boolean deeplyAccessible)
Indicates if the subdirectories are deeply accessible (true by default).

Parameters:
deeplyAccessible - True if the subdirectories are deeply accessible.

setIndexName

public void setIndexName(String indexName)
Sets the index name, without extensions.

Parameters:
indexName - The index name.

setListingAllowed

public void setListingAllowed(boolean listingAllowed)
Indicates if the display of directory listings is allowed when no index file is found.

Parameters:
listingAllowed - True if the display of directory listings is allowed when no index file is found.

setModifiable

public void setModifiable(boolean modifiable)
Indicates if modifications to local resources are allowed.

Parameters:
modifiable - True if modifications to local resources are allowed.

setNegotiateContent

public void setNegotiateContent(boolean negotiateContent)
Indicates if the best content is automatically negotiated. Default value is true.

Parameters:
negotiateContent - True if the best content is automatically negotiated.


Copyright © 2005-2007 Noelios Technologies.