com.faunos.util.net.http.file
Class FileResponseFactory

java.lang.Object
  extended by com.faunos.util.net.http.AbstractResponseFactory
      extended by com.faunos.util.net.http.file.FileResponseFactory
All Implemented Interfaces:
ResponseFactory, Closeable

public class FileResponseFactory
extends AbstractResponseFactory
implements Closeable

A ResponseFactory for serving ordinary files.

Author:
Babak Farhang

Field Summary
protected static MimeMap DEFAULT_MIME_MAP
          Default mime map used to set Content-Type HTTP header.
protected  FileFilter filter
           
protected  MimeMap mimeMap
          Used to set the "Content-Type" HTTP header.
static DirectoryFileDefaulter NOOP_DEFAULTER
          A no-op directory-file defaulter.
protected  File root
           
protected  String uriMountPoint
           
 
Constructor Summary
protected FileResponseFactory(String uriMountPoint, File root, MimeMap mimeMap, FileFilter filter, ResponseFactoryConfig config)
           
 
Method Summary
 void close()
          Removes this instance from its associated configuration.
static FileResponseFactory getInstance(ResponseFactoryConfig config, String uriMountPoint)
          Returns the instance configured at the specified uriMountPoint, if any.
static FileResponseFactory newInstance(ResponseFactoryConfig config, String uriMountPoint, File root)
          Creates a new instance configured at the specified URI mount point, with the given root directory.
static FileResponseFactory newInstance(ResponseFactoryConfig config, String uriMountPoint, File root, MimeMap mimeMap, FileFilter filter)
          Creates a new instance configured at the specified URI mount point, with the given root directory.
protected  Stagelet prepareDirectoryResponse(RequestHeader request, StageletStack stack, File dir)
          Returns the response when the request resolves to a file system directory.
protected  Stagelet prepareResponseImpl(RequestHeader request, StageletStack stack)
          Returns the factory-specific (i.e.
 void setDirectroyFileDefaulter(DirectoryFileDefaulter def)
          Sets the file defaulter, for directory response resolution.
 
Methods inherited from class com.faunos.util.net.http.AbstractResponseFactory
badRequest, getResponse, notFound, urlDecode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIME_MAP

protected static final MimeMap DEFAULT_MIME_MAP
Default mime map used to set Content-Type HTTP header. This is file-extension-based.

See Also:
ExtensionMimeMap

NOOP_DEFAULTER

public static final DirectoryFileDefaulter NOOP_DEFAULTER
A no-op directory-file defaulter.


uriMountPoint

protected final String uriMountPoint

root

protected final File root

filter

protected final FileFilter filter

mimeMap

protected final MimeMap mimeMap
Used to set the "Content-Type" HTTP header.

Constructor Detail

FileResponseFactory

protected FileResponseFactory(String uriMountPoint,
                              File root,
                              MimeMap mimeMap,
                              FileFilter filter,
                              ResponseFactoryConfig config)
Method Detail

getInstance

public static FileResponseFactory getInstance(ResponseFactoryConfig config,
                                              String uriMountPoint)
Returns the instance configured at the specified uriMountPoint, if any. If some other type of ResponseFactory is configured at that uriMountPoint, then an exception is thrown.

Parameters:
config - the configuration object, e.g. one exposed by the container (Caroon).
uriMountPoint - the URI mount point. This is the root of HTTP URIs that the factory responds to.
See Also:
close(), newInstance(ResponseFactoryConfig, String, File), newInstance(ResponseFactoryConfig, String, File, MimeMap, FileFilter)

newInstance

public static FileResponseFactory newInstance(ResponseFactoryConfig config,
                                              String uriMountPoint,
                                              File root)
Creates a new instance configured at the specified URI mount point, with the given root directory. The Content-Type HTTP header is determined using file-extension heuristics.

Parameters:
config - the configuration object, e.g. one exposed by the container (Caroon).
uriMountPoint - the URI mount point. This is the root of HTTP URIs that this factory will respond to. It must begin and end in a forward slash ('/')/
root - the root directory that uriMountPoint will resolve to
See Also:
getInstance(ResponseFactoryConfig, String), close()

newInstance

public static FileResponseFactory newInstance(ResponseFactoryConfig config,
                                              String uriMountPoint,
                                              File root,
                                              MimeMap mimeMap,
                                              FileFilter filter)
Creates a new instance configured at the specified URI mount point, with the given root directory.

Parameters:
config - the configuration object, e.g. one exposed by the container (Caroon).
uriMountPoint - the URI mount point. This is the root of HTTP URIs that this factory will respond to. It must begin and end in a forward slash ('/')/
root - the root directory that uriMountPoint will resolve to
mimeMap - the mapping instance used to determine what the HTTP Content-Type header will be set to
filter - an option file filter. May be null
See Also:
getInstance(ResponseFactoryConfig, String), close()

setDirectroyFileDefaulter

public void setDirectroyFileDefaulter(DirectoryFileDefaulter def)
Sets the file defaulter, for directory response resolution.


close

public void close()
Removes this instance from its associated configuration.

Specified by:
close in interface Closeable
See Also:
ResponseFactoryConfig.removeMapping(String)

prepareResponseImpl

protected Stagelet prepareResponseImpl(RequestHeader request,
                                       StageletStack stack)
Description copied from class: AbstractResponseFactory
Returns the factory-specific (i.e. app-specific) stagelet. The returned instance will not be in the PROCESSING state.

Specified by:
prepareResponseImpl in class AbstractResponseFactory

prepareDirectoryResponse

protected Stagelet prepareDirectoryResponse(RequestHeader request,
                                            StageletStack stack,
                                            File dir)
                                     throws IOException
Returns the response when the request resolves to a file system directory.

Throws:
IOException


SourceForge.net Logo