The Context interface is used to give a view of the
file system to the ResourceEngine . This provides the
information to the ResourceEngine that it needs in
order to serve content to the client browser. This provides the
path translations for the HTTP request URI. This also provides
the Format object that is used to create directory
listings and error messages.
This object essentially provides a mechanism that allows the file
engine to convert the HTTP request URI into OS system paths and
system objects such as the File object. A context
is rooted a a certain directory in the system. This directory is
where the resources are gathered from. For example suppose that
a Context implementation is rooted at the directory
"c:\web\html\" on a DOS system. Now if the target of the browser
was "http://some.host/web/pub/README". The context needs to be
consulted to convert "/web/pub/README" into the real path within
the system. So Context.getRealPath is invoked with
the path "/web/pub/README", which responds with the system path
"c:\web\html\web\pub\README". Also if this was a UNIX system
with the same context rooted at "/home/user/html" then the same
URL would result in "/home/user/html/web/pub/README".
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 Context object must be prepared to 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 Context implementation should be able to
directly take a Request-URI as defined in RFC 2616 and translate
this into a path compatible with the OS specific file system.
This keeps the objects semantics simple and explicit, although
at the expense of performance.
author: Niall Gallagher See Also: simple.util.parse.URIParser See Also: simple.util.parse.PathParser |