Package org.restlet.resource
Class Directory
- java.lang.Object
- 
- org.restlet.Restlet
- 
- org.restlet.resource.Finder
- 
- org.restlet.resource.Directory
 
 
 
- 
- All Implemented Interfaces:
- Uniform
 
 public class Directory extends Finder Finder mapping a directory of local resources. Those resources have representations accessed by the file system, the class loaders or other URI accessible protocols. Here is some sample code illustrating how to attach a directory to a router:
 Directory directory = new Directory(getContext(), "file:///user/data/files/"); Router router = new Router(getContext()); router.attach("/static/", directory);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.
 
 When no index is available in a given directory, a representation can be automatically generated by thegetIndexRepresentation(Variant, ReferenceList)method, unless the "listingAllowed" property is turned off. You can even customize the way the index entries are sorted by using thesetComparator(Comparator)method. The default sorting uses the friendly Alphanum algorithm based on David Koelle's original idea, using a different and faster implementation contributed by Rob Heittman.
 
 Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.- Author:
- Jerome Louvel
- See Also:
- User Guide - Serving static files
 
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Comparator<Reference>getComparator()Returns the reference comparator used to sort index pages.java.lang.StringgetIndexName()Returns the index name, without extensions.RepresentationgetIndexRepresentation(Variant variant, ReferenceList indexContent)Returns an actual index representation for a given variant.java.util.List<Variant>getIndexVariants(ReferenceList indexContent)Returns the variant representations of a directory index.ReferencegetRootRef()Returns the root URI from which the relative resource URIs will be looked up.voidhandle(Request request, Response response)Handles a call.booleanisDeeplyAccessible()Indicates if the sub-directories are deeply accessible (true by default).booleanisListingAllowed()Indicates if the display of directory listings is allowed when no index file is found.booleanisModifiable()Indicates if modifications to local resources (most likely files) are allowed.booleanisNegotiatingContent()Indicates if the best content is automatically negotiated.voidsetComparator(java.util.Comparator<Reference> comparator)Sets the reference comparator used to sort index pages.voidsetDeeplyAccessible(boolean deeplyAccessible)Indicates if the sub-directories are deeply accessible (true by default).voidsetIndexName(java.lang.String indexName)Sets the index name, without extensions.voidsetListingAllowed(boolean listingAllowed)Indicates if the display of directory listings is allowed when no index file is found.voidsetModifiable(boolean modifiable)Indicates if modifications to local resources are allowed.voidsetNegotiatingContent(boolean negotiatingContent)Indicates if the best content is automatically negotiated.voidsetRootRef(Reference rootRef)Sets the root URI from which the relative resource URIs will be lookep up.voiduseAlphaComparator()Sets the reference comparator based on classic alphabetical order.voiduseAlphaNumComparator()Sets the reference comparator based on the more friendly "Alphanum Algorithm" created by David Koelle.- 
Methods inherited from class org.restlet.resource.Findercreate, create, createFinder, find, getTargetClass, setTargetClass, toString
 - 
Methods inherited from class org.restlet.RestletcreateFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner, start, stop
 
- 
 
- 
- 
- 
Constructor Detail- 
Directorypublic Directory(Context context, Reference rootLocalReference) Constructor.- Parameters:
- context- The context.
- rootLocalReference- The root URI.
 
 - 
Directorypublic Directory(Context context, java.lang.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- 
getComparatorpublic java.util.Comparator<Reference> getComparator() Returns the reference comparator used to sort index pages. The default implementation used a friendly alphanum sorting.- Returns:
- The reference comparator.
- See Also:
- AlphaNumericComparator
 
 - 
getIndexNamepublic java.lang.String getIndexName() Returns the index name, without extensions. Returns "index" by default.- Returns:
- The index name.
 
 - 
getIndexRepresentationpublic 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.
 
 - 
getIndexVariantspublic java.util.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. Note that a new instance of the list is created for each call.- Parameters:
- indexContent- The list of references contained in the directory index.
- Returns:
- The variant representations of a directory.
 
 - 
getRootRefpublic Reference getRootRef() Returns the root URI from which the relative resource URIs will be looked up.- Returns:
- The root URI.
 
 - 
handlepublic void handle(Request request, Response response) Description copied from class:FinderHandles a call.
 - 
isDeeplyAccessiblepublic boolean isDeeplyAccessible() Indicates if the sub-directories are deeply accessible (true by default).- Returns:
- True if the sub-directories are deeply accessible.
 
 - 
isListingAllowedpublic 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.
 
 - 
isModifiablepublic 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.
 
 - 
isNegotiatingContentpublic boolean isNegotiatingContent() Indicates if the best content is automatically negotiated. Default value is true.- Returns:
- True if the best content is automatically negotiated.
 
 - 
setComparatorpublic void setComparator(java.util.Comparator<Reference> comparator) Sets the reference comparator used to sort index pages.- Parameters:
- comparator- The reference comparator.
 
 - 
setDeeplyAccessiblepublic void setDeeplyAccessible(boolean deeplyAccessible) Indicates if the sub-directories are deeply accessible (true by default).- Parameters:
- deeplyAccessible- True if the sub-directories are deeply accessible.
 
 - 
setIndexNamepublic void setIndexName(java.lang.String indexName) Sets the index name, without extensions.- Parameters:
- indexName- The index name.
 
 - 
setListingAllowedpublic 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.
 
 - 
setModifiablepublic void setModifiable(boolean modifiable) Indicates if modifications to local resources are allowed.- Parameters:
- modifiable- True if modifications to local resources are allowed.
 
 - 
setNegotiatingContentpublic void setNegotiatingContent(boolean negotiatingContent) Indicates if the best content is automatically negotiated. Default value is true.- Parameters:
- negotiatingContent- True if the best content is automatically negotiated.
 
 - 
setRootRefpublic void setRootRef(Reference rootRef) Sets the root URI from which the relative resource URIs will be lookep up.- Parameters:
- rootRef- The root URI.
 
 - 
useAlphaComparatorpublic void useAlphaComparator() Sets the reference comparator based on classic alphabetical order.- See Also:
- setComparator(Comparator)
 
 - 
useAlphaNumComparatorpublic void useAlphaNumComparator() Sets the reference comparator based on the more friendly "Alphanum Algorithm" created by David Koelle. The internal implementation used is based on an optimized public domain implementation provided by Rob Heittman from the Solertium Corporation.
 
- 
 
-