Package sunlabs.brazil.handler
Class ReflectHandler
- java.lang.Object
-
- sunlabs.brazil.handler.ReflectHandler
-
- All Implemented Interfaces:
Handler
public class ReflectHandler extends java.lang.Object implements Handler
Handler for reflecting query data back to the client. This is the example handler to demonstrate how a typical handler is witten. If query data is present, it is formatted into an HTML table, and displayed to the user.- Version:
- 2.1, 02/10/01
- Author:
- Stephen Uhler
-
-
Constructor Summary
Constructors Constructor Description ReflectHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
formatTable(java.util.Dictionary data, java.lang.String caption)
Turn a hash table into html format.boolean
init(Server server, java.lang.String prefix)
Initialize the handler.boolean
respond(Request request)
Dispatch and handle the request.
-
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
Initialize the handler. Handler objects are created by the server using newInstance(). The init method is called first, and exactly one for each instance, and may be used for one-time initializations. This handler doesn't require any.- Specified by:
init
in interfaceHandler
- Parameters:
server
- A reference to the server.prefix
- A string identifying this instance of the handler. It is used by theChainHandler
to provide the prefix to be prepended onto each property intended for this handler.- Returns:
- true Only if the handler is successfully initialized.
-
respond
public boolean respond(Request request) throws java.io.IOException
Dispatch and handle the request. This version justs reflects the HTTP header information. It is commonly placed downstream of theCgiHandler
to allow HTML forms to be tested before the cgi script is written.- Specified by:
respond
in interfaceHandler
- Parameters:
request
- The request object contains all of the information about the request, as well as methods to manipulate it. Although multiple threads may call this method connurrently, each will have its own request object.- Returns:
true
if the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()
orRequest.sendError
.- Throws:
java.io.IOException
- if there was an I/O error while sending the response to the client. Typically, in that case, theServer
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 aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.
-
formatTable
public static java.lang.String formatTable(java.util.Dictionary data, java.lang.String caption)
Turn a hash table into html format. This is a static method so it may be used in other handlers.- Parameters:
table
- The table to format- Returns:
- The html fragment
-
-