sunlabs.brazil.handler
Class UrlMapperHandler

java.lang.Object
  |
  +--sunlabs.brazil.handler.UrlMapperHandler
All Implemented Interfaces:
Handler

public class UrlMapperHandler
extends Object
implements Handler

Handler for mapping or redirecting URLs. Matches url's against a regexp pattern. If it matches, the url is either rewritten or redirected.

Properties:

match
The regexp to match a url. May contain constructs of the form ${xxx}, which are replaced by the value of request.props for the key xxx
replace
The url to replace it with. This may contain both regular expression sub-patterns, such as "\1", or variables of the form ${..} which are replaced with the equivalent request properties.
export
If set, use this as a properties prefix, and set request properties for each sub-expression in "match". (E.g. [export]1 [export]2 ...).
redirect
If set, the request is redirected instead of being rewritten
ignoreCase
If set, the case of the expression is ignored.
source
If set, then this string is used instead of the url as the source of the match. Variable substitution using ${xxx} is performed on source, which, if unset, defaults to "${url}". If set, the request properties "url", "host" and "user-agent" are set first. The source property is obtained at init time, but evaluated (for ${...}) at every request.

As an example, the configuration:
prefix.source=${user-agent}!${url}
prefix.match=Lynx.*!(.*)
prefix.replace=/text\\1
could cause all browsers with "Lynx" in their user agent header to the "text" sub-directory.


Constructor Summary
UrlMapperHandler()
           
 
Method Summary
 boolean init(Server server, String prefix)
          Initializes the handler.
 boolean respond(Request request)
          If this request matches the expression, rewrite it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlMapperHandler

public UrlMapperHandler()
Method Detail

init

public boolean init(Server server,
                    String prefix)
Description copied from interface: Handler
Initializes the handler.

Specified by:
init in interface Handler
Parameters:
server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
Returns:
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.

respond

public boolean respond(Request request)
                throws IOException
If this request matches the expression, rewrite it.

Specified by:
respond in interface Handler
Parameters:
request - The Request object that represents the HTTP request.
Returns:
true if the request was handled. A request was handled if a response was supplied to the client, typically by calling Request.sendResponse() or Request.sendError.
Throws:
IOException - if there was an I/O error while sending the response to the client. Typically, in that case, the Server will (try to) send an error message to the client and then close the client's connection.

The IOException should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting a FileNotFoundException due to not being able to open a file). In that case, the Handler's duty is to turn that IOException into a HTTP response indicating, in this case, that a file could not be found.


Version 2.1, Generated 12/30/04
Copyright (c) 2001-2004, Sun Microsystems.