simple.http.serve
Class FileEngine

java.lang.Object
  extended by simple.http.serve.FileEngine
All Implemented Interfaces:
ResourceEngine

public class FileEngine
extends java.lang.Object
implements ResourceEngine

The FileEngine is used to produce implementations of the Resource object to represent files on the underlying filesystem. This will produce Resource objects that map on to the suggested URI relative to some given Context. The Context must be given as a root so all requests for Resource's are retrieved relative to that root.

The meaning of HTTP URI in this instance is the request URI from a HTTP/x.x request, as RFC 2616 and RFC 2396 defines it

 
 Request-Line = Method SP Request-URI SP HTTP-Version CRLF

 Request-URI = "*" | absoluteURI | abs_path | authority
 absoluteURI = "http:" "//" host [":" port] [abs_path ["?" query]] 
 abs_path = "/" path_segments         
 path_segments = segment *( "/" segment )
 
So the FileEngine object will accept the request URI that come in the form outlined above. These can include formats like
 
 http://some.host/pub;param=value/bin/index.html?name=value
 http://some.host:8080/index.en_US.html
 some.host:8080/index.html
 /usr/bin;param=value/README.txt
 /usr/bin/compress.tar.gz
 
The FileEngine object will directly take a request URI as defined in RFC 2616 and translate this into a system specific Resource. This keeps the objects semantics simple and explicit, although at the expense of performance.

Author:
Niall Gallagher
See Also:
CacheContext

Field Summary
protected  Context context
          Each FileEngine operates using a context.
 
Constructor Summary
FileEngine()
          Constructor for the FileEngine.
FileEngine(Context context)
          Constructor takes a Context implementation and operates relative to that implementation.
 
Method Summary
 Resource resolve(java.lang.String target)
          This will look for and retrieve the requested resource.
protected  Resource resolve(java.lang.String target, java.io.File file)
          This will look for and retrieve the requested resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected Context context
Each FileEngine operates using a context.

Constructor Detail

FileEngine

public FileEngine()
Constructor for the FileEngine. This uses the current working directory to serve the Resource. This will retrieve and represent OS specific resources such as files using Resource implementations. This also keeps a cache of the file contents requested.


FileEngine

public FileEngine(Context context)
Constructor takes a Context implementation and operates relative to that implementation. This will retrieve and represent OS specific resources such as files using Resource implementations. This relies on the provided context to perform caching for this implementation.

Parameters:
context - this is the context the file engine will use
Method Detail

resolve

public Resource resolve(java.lang.String target)
This will look for and retrieve the requested resource. The target given must be in the form of a request URI. This will locate the resource and return the Resource implementation that will handle the target.

Specified by:
resolve in interface ResourceEngine
Parameters:
target - the URI style path that represents the target
Returns:
returns the resource instance to handle the target

resolve

protected Resource resolve(java.lang.String target,
                           java.io.File file)
This will look for and retrieve the requested resource. The target given must be in the form of a request URI. This will locate the resource and return the Resource implementation that will handle the target.

Parameters:
target - the URI style path that represents the target
file - this is the file that represents the resource
Returns:
returns the resource instance to handle the target