org.locomotive.loco.handler
Class GenericHandler

java.lang.Object
  |
  +--org.locomotive.loco.handler.GenericHandler
Direct Known Subclasses:
BaseHandler, BugTrackerHandler, CodeGenerator, DiscussionAdminHandler, DiscussionHandler, DisplayPageHandler, GraffitiWallHandler, LoginHandler, LogoutHandler, PersonalPrefHandler, PublisherHandler, RegistrationHandler, UserMgtHandler, UserPrefHandler

public class GenericHandler
extends java.lang.Object
implements Handler

The GenericHandler class is a generic implementation of the Handler interface. There are two alternative ways to use this class:

  1. You can subclass this class to handle all your user requests.
  2. You can create several different subclasses of this class in order to handle different features. Then, you can create a "master" subclass to route to each of these different subclasses, based on the different URLs.
This class comes with many convenience methods, some of which serve only to make the code more readable; feel free to customize them.


Field Summary
protected  boolean already_displayed_page
          whether or not a page has been flushed back to the browser.
protected  java.sql.Connection conn
          The database connection this request can use, if desired.
static int DEBUG
          log level to use for debugging
static int ERROR
          Log level to use for serious errors; e.g.
protected  FormData form_data
          the FormData object that contains any form information from a POST.
protected  java.lang.String handler_uri
          The last part of the url which specifies which Handler to use
protected  HandlerData hd
          The handlerData object containing information for this request.
static int NORMAL
          log level to use for normal activities
protected  Session session
          the session associated with this request.
protected  java.util.Hashtable steam_vars
          the substitutions hashtable to be used when evaluating templates.
protected  java.lang.String[] url_tokens
          the url tokens for this request.
protected  User user
          the user associated with this request.
static int WARNING
          Log level to use for warnings
 
Constructor Summary
GenericHandler()
           
 
Method Summary
 java.lang.String displayPage(java.lang.String document_path, java.util.Hashtable steam_vars)
          loads a Steam document, inserts the values of Steam variables into that document, and then writes the result back to the Web server.
 void displayString(java.lang.String message)
          if you want to send back a single string as the response to the user, you can use this method.
 void handleException(java.lang.Exception exception, java.lang.String short_code)
          this is a convenience method you can use when you catch serious Exceptions for which you want a stack trace and you need to send the user an error code, which can help you debug.
 void handleRequest(HandlerData hd)
          initializes all the local variables.
 boolean init(Log server_log)
          GenericHandler doesn't do anything in the init() method.
 void log(int log_level, java.lang.String log_message)
          writes a message to the locomotive's global server log.
 void logEvent(java.lang.String major, java.lang.String minor, java.lang.String data)
          write one event to the global locomotive event log.
 void sayBadURL()
          simply tells the user that they typed a bad URL, by sending the message: "I'm sorry, I don't understand that URL."
 boolean shutdown(Log server_log)
          GenericHandler doesn't do anything in the shutdown() method, either.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hd

protected HandlerData hd
The handlerData object containing information for this request.

url_tokens

protected java.lang.String[] url_tokens
the url tokens for this request.

handler_uri

protected java.lang.String handler_uri
The last part of the url which specifies which Handler to use

form_data

protected FormData form_data
the FormData object that contains any form information from a POST.

steam_vars

protected java.util.Hashtable steam_vars
the substitutions hashtable to be used when evaluating templates.

user

protected User user
the user associated with this request.

session

protected Session session
the session associated with this request.

conn

protected java.sql.Connection conn
The database connection this request can use, if desired.

already_displayed_page

protected boolean already_displayed_page
whether or not a page has been flushed back to the browser.

ERROR

public static final int ERROR
Log level to use for serious errors; e.g. log(ERROR, "Wait! There's an error!");

WARNING

public static final int WARNING
Log level to use for warnings

NORMAL

public static final int NORMAL
log level to use for normal activities

DEBUG

public static final int DEBUG
log level to use for debugging
Constructor Detail

GenericHandler

public GenericHandler()
Method Detail

handleRequest

public void handleRequest(HandlerData hd)
initializes all the local variables. Whenever you subclass a GenericHandler, be sure to call super.handleRequest(hd) in the first line of your handleRequest() method.
Specified by:
handleRequest in interface Handler

init

public boolean init(Log server_log)
GenericHandler doesn't do anything in the init() method.
Specified by:
init in interface Handler

shutdown

public boolean shutdown(Log server_log)
GenericHandler doesn't do anything in the shutdown() method, either.
Specified by:
shutdown in interface Handler

log

public void log(int log_level,
                java.lang.String log_message)
writes a message to the locomotive's global server log.

handleException

public void handleException(java.lang.Exception exception,
                            java.lang.String short_code)
this is a convenience method you can use when you catch serious Exceptions for which you want a stack trace and you need to send the user an error code, which can help you debug.

logEvent

public void logEvent(java.lang.String major,
                     java.lang.String minor,
                     java.lang.String data)
write one event to the global locomotive event log. (this method is just a wrapper around Loco.logEvent().)

displayString

public void displayString(java.lang.String message)
if you want to send back a single string as the response to the user, you can use this method. (You don't need to put your message within <HTML><BODY>...</BODY></HTML>)

displayPage

public java.lang.String displayPage(java.lang.String document_path,
                                    java.util.Hashtable steam_vars)
loads a Steam document, inserts the values of Steam variables into that document, and then writes the result back to the Web server.

sayBadURL

public void sayBadURL()
simply tells the user that they typed a bad URL, by sending the message: "I'm sorry, I don't understand that URL."