edu.mssm.crover.scentral
Class ServletCentral

java.lang.Object
  |
  +--edu.mssm.crover.scentral.ServletCentral
All Implemented Interfaces:
SimpleMailer

public class ServletCentral
extends java.lang.Object
implements SimpleMailer

Central location where the servlets can find the services they need in order to work in a smoother way inside the web server. This class provides services as a enhanced log system, a url repository that allows to move the URLs allocated to specific documents without recompiling the servlets that generate documents that reference them. ServletCentral also provides the basis for document templates (header of the pages, footer, containers to group related materials on the page). It gives access to a user directory that contains user records and allow authentified sessions. It provides a access to the PersistenceScheme implementation.

See Also:
URLRepository, UserDirectory, PersistenceScheme

Field Summary
static java.lang.String footerBackgroundColor
           
static java.lang.String GUEST_LOGIN
          Returned by the login prompt form as the value of the GUEST_REQUEST_SUBMIT_NAME attribute when the user pressed the guest login submit button.
static java.lang.String GUEST_REQUEST_SUBMIT_NAME
          Name of the submit button for the guest login action.
static java.lang.String LOGIN_NAME
          Name of the login input field for the login.
static java.lang.String PASSWORD_NAME
          Name of the login input field for the password.
static java.lang.String REGISTERED_SUBMIT_NAME
          Name of the submit button for the registered login action.
static java.lang.String RELATIVE_REDIRECT_URL
          The dest parameter for SessionLogin
static java.lang.String SERVICE_MANAGER_VALUE
           
static java.lang.String USER_SESSION_VALUE
           
 
Method Summary
 void appendServiceFooter(java.lang.String webservice, UserSession us, org.apache.ecs.html.Body body)
          Append a service dependant footer to the body.
 org.apache.ecs.html.TD createBodyCell(org.apache.ecs.Element body)
           
 org.apache.ecs.html.TD createBodyCell(org.apache.ecs.Element body, boolean wrap)
           
 org.apache.ecs.html.TD createTitleCell(java.lang.String title)
           
 org.apache.ecs.html.TD createTitleCell(java.lang.String title, boolean wrap)
           
 void destroy()
          Free ressources used by this service.
 org.apache.ecs.html.Body getBody(org.apache.ecs.Document doc)
          Returns body of a document with background and link colors set
 java.sql.Connection getConnection()
          Obtain a connection from the pool.
 org.apache.ecs.Document getDefaultDocument(javax.servlet.http.HttpSession session, java.lang.String title)
          Returns a document with a title.
 org.apache.ecs.Element getDefaultFooter()
          Returns the footer of a document.
 org.apache.ecs.Element getDefaultFooter(java.lang.String info1, java.lang.String authors)
          Returns the footer of a document.
 org.apache.ecs.Element getDefaultFooter(java.lang.String info1, java.lang.String info2, java.lang.String authors)
          Returns the footer of a document.
 org.apache.ecs.xml.XMLDocument getDefaultXmlDocument(javax.servlet.http.HttpSession session, java.lang.String title)
          Deprecated.  
 org.apache.ecs.Element getEditorContainer(java.lang.String title, org.apache.ecs.Element content)
           
 org.apache.ecs.Element getEditorContainer(java.lang.String title, org.apache.ecs.Element content, java.lang.String width)
          Returns a pretty container.
 org.apache.ecs.Element getEditorContainer(java.lang.String title, org.apache.ecs.Element content, java.lang.String width, boolean wrap)
          Returns a pretty container.
 org.apache.ecs.html.Head getHead(javax.servlet.http.HttpSession session, java.lang.String title)
          Deprecated. Use getDefaultDocument instead
static ServletCentral getInstance()
          Must not be used in cases when the session might be expired! In such cases the getInstance(String requestURI) must be used!
Returns the only instance of ServletCentral available in the system.
static ServletCentral getInstance(javax.servlet.http.HttpServlet client)
          Returns the only instance of ServletCentral available in the system (one per zone).
 java.lang.String getLayoutDir()
          Returns the directory where the XML layouts required by RbDg are stored.
 Log getLog()
          Returns the log system.
 org.apache.ecs.Element getLoginPrompt(javax.servlet.http.HttpServletResponse response, java.lang.String login_label, java.lang.String initial_login, java.lang.String passwd_label, boolean allow_guest_login, boolean allow_login_creation, java.lang.String action, java.lang.String destination)
          Returns an element to present the form that prompts for login.
 org.apache.ecs.html.Table getMetalContainer(java.lang.String title, org.apache.ecs.Element content)
           
 PersistenceScheme getPersistenceScheme(javax.servlet.http.HttpServletRequest request)
          Returns the persistence scheme current implementation.
 UserRecord getRecord(java.lang.String recordID)
          Returns the user record associated with this recordID.
 UserRecord getRecord(java.lang.String userID, java.lang.String password)
          Returns the user record associated with this userID.
 ServiceManager getServiceManager(javax.servlet.http.HttpServletRequest request)
          Returns the ServiceManager associated with this request.
 java.lang.String getTitle(javax.servlet.http.HttpSession session, java.lang.String title)
          Returns a string to insert in the title of a document.
 org.apache.ecs.Element getTitle(java.lang.String title)
          Returns the title of a document.
 URLRepository getURLRepository()
          Returns the URL repository.
 UserDirectory getUserDirectory()
          Returns the current user directory.
 boolean hasServiceManager(javax.servlet.http.HttpServletRequest request)
          Returns whether there is a service manager associated with this request.
 boolean isRegistered(java.lang.String userID, java.lang.String password)
          Checks wether the couple (userID, password) is registered or not.
static boolean isUserLoggedIn(javax.servlet.http.HttpServletRequest request)
          Determines whether the user that makes the request is logged in.
 void log(int level, java.lang.String message)
          Log a message and an exception.
 void log(int level, java.lang.String message, java.lang.Exception e)
          Logs a message and an exception.
static void main(java.lang.String[] args)
          Tests and demonstrates this class behaviour.
 void register(java.lang.String userID, UserRecord record)
           
 void returnConnection(java.sql.Connection con)
          Returns a connection to the pool.
 void sendMail(UserRecord recipient, java.lang.String subject, java.lang.String message)
          Sends an email to the user defined by a user record.
 org.apache.ecs.Element sideBySide(java.lang.String title_left, org.apache.ecs.Element body_left, java.lang.String title_right, org.apache.ecs.Element body_right)
          Layout the two elements side by side.
 org.apache.ecs.Element upAndDown(java.lang.String title_up, org.apache.ecs.Element body_up, java.lang.String title_down, org.apache.ecs.Element body_down)
          Layout the two editor elements up and down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

footerBackgroundColor

public static final java.lang.String footerBackgroundColor
See Also:
Constant Field Values

GUEST_LOGIN

public static final java.lang.String GUEST_LOGIN
Returned by the login prompt form as the value of the GUEST_REQUEST_SUBMIT_NAME attribute when the user pressed the guest login submit button.

See Also:
Constant Field Values

GUEST_REQUEST_SUBMIT_NAME

public static final java.lang.String GUEST_REQUEST_SUBMIT_NAME
Name of the submit button for the guest login action.

See Also:
Constant Field Values

REGISTERED_SUBMIT_NAME

public static final java.lang.String REGISTERED_SUBMIT_NAME
Name of the submit button for the registered login action.

See Also:
Constant Field Values

LOGIN_NAME

public static final java.lang.String LOGIN_NAME
Name of the login input field for the login.

See Also:
Constant Field Values

PASSWORD_NAME

public static final java.lang.String PASSWORD_NAME
Name of the login input field for the password.

See Also:
Constant Field Values

RELATIVE_REDIRECT_URL

public static final java.lang.String RELATIVE_REDIRECT_URL
The dest parameter for SessionLogin

See Also:
Constant Field Values

SERVICE_MANAGER_VALUE

public static final java.lang.String SERVICE_MANAGER_VALUE
See Also:
Constant Field Values

USER_SESSION_VALUE

public static final java.lang.String USER_SESSION_VALUE
See Also:
Constant Field Values
Method Detail

getInstance

public static ServletCentral getInstance()
Must not be used in cases when the session might be expired! In such cases the getInstance(String requestURI) must be used!
Returns the only instance of ServletCentral available in the system. If no instance is available (which may happen in expired sessions), it throws InternalError() with no page message to the user that the session has expired!


getLayoutDir

public java.lang.String getLayoutDir()
Returns the directory where the XML layouts required by RbDg are stored.


getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Obtain a connection from the pool.

java.sql.SQLException

returnConnection

public void returnConnection(java.sql.Connection con)
Returns a connection to the pool.


getInstance

public static ServletCentral getInstance(javax.servlet.http.HttpServlet client)
Returns the only instance of ServletCentral available in the system (one per zone). Only servlets can get access to ServletCentral.

Parameters:
client - Could be any servlet which init parameter include scentral.zone (this sets the zone for the URLRepository).

getURLRepository

public URLRepository getURLRepository()
Returns the URL repository. The URL repository is available after getInstance(zone) has been invoked at least once. The first invocation to getInstance() returns a ServletCentral which contains no URLRepository. Calling getURLRepository() on such instance is invalid. In summary, the following is correct:
  • instance=ServletCentral.getInstance()
  • instance.getUserDirectory()
  • instance.log(...)
  • instance=ServletCentral.getInstance(zone)
  • instance.getURLRepository() While the following is not supported:
  • instance=ServletCentral.getInstance()
  • instance.getURLRepository()
  • instance=ServletCentral.getInstance(zone)


  • log

    public void log(int level,
                    java.lang.String message,
                    java.lang.Exception e)
    Logs a message and an exception.

    See Also:
    Log

    log

    public void log(int level,
                    java.lang.String message)
    Log a message and an exception.

    See Also:
    Log

    getLog

    public Log getLog()
    Returns the log system.


    getDefaultFooter

    public org.apache.ecs.Element getDefaultFooter()
    Returns the footer of a document.


    getDefaultFooter

    public org.apache.ecs.Element getDefaultFooter(java.lang.String info1,
                                                   java.lang.String authors)
    Returns the footer of a document.


    getDefaultFooter

    public org.apache.ecs.Element getDefaultFooter(java.lang.String info1,
                                                   java.lang.String info2,
                                                   java.lang.String authors)
    Returns the footer of a document.


    getHead

    public org.apache.ecs.html.Head getHead(javax.servlet.http.HttpSession session,
                                            java.lang.String title)
    Deprecated. Use getDefaultDocument instead

    Returns the head of a document.


    appendServiceFooter

    public void appendServiceFooter(java.lang.String webservice,
                                    UserSession us,
                                    org.apache.ecs.html.Body body)
    Append a service dependant footer to the body.

    Parameters:
    webservice - The classname of the WebService implementation we help now. We use the classname to append the appropriate footer to the body (appropriate footer = footer the content of which depends on the web service we represent here). A number of things can go wrong which are logged.

    getTitle

    public java.lang.String getTitle(javax.servlet.http.HttpSession session,
                                     java.lang.String title)
    Returns a string to insert in the title of a document. This method provides an opportunity to add information in the title of every document built through servlets.


    getDefaultDocument

    public org.apache.ecs.Document getDefaultDocument(javax.servlet.http.HttpSession session,
                                                      java.lang.String title)
    Returns a document with a title.


    getDefaultXmlDocument

    public org.apache.ecs.xml.XMLDocument getDefaultXmlDocument(javax.servlet.http.HttpSession session,
                                                                java.lang.String title)
    Deprecated.  

    Returns an XML document with a title. Experimental, do not use!


    getBody

    public org.apache.ecs.html.Body getBody(org.apache.ecs.Document doc)
    Returns body of a document with background and link colors set


    getMetalContainer

    public org.apache.ecs.html.Table getMetalContainer(java.lang.String title,
                                                       org.apache.ecs.Element content)

    getEditorContainer

    public org.apache.ecs.Element getEditorContainer(java.lang.String title,
                                                     org.apache.ecs.Element content,
                                                     java.lang.String width)
    Returns a pretty container. The cells do not wrap by default.

    See Also:
    getEditorContainer(String title, Element content, String width, boolean wrap)

    getEditorContainer

    public org.apache.ecs.Element getEditorContainer(java.lang.String title,
                                                     org.apache.ecs.Element content,
                                                     java.lang.String width,
                                                     boolean wrap)
    Returns a pretty container.

    Parameters:
    wrap - When false, the cells have the nowrap attribute (text will not be wrapper into these cells, so they will expand their size to match the size of the content).

    getEditorContainer

    public org.apache.ecs.Element getEditorContainer(java.lang.String title,
                                                     org.apache.ecs.Element content)

    getLoginPrompt

    public org.apache.ecs.Element getLoginPrompt(javax.servlet.http.HttpServletResponse response,
                                                 java.lang.String login_label,
                                                 java.lang.String initial_login,
                                                 java.lang.String passwd_label,
                                                 boolean allow_guest_login,
                                                 boolean allow_login_creation,
                                                 java.lang.String action,
                                                 java.lang.String destination)
    Returns an element to present the form that prompts for login. The form provides a way to request guest login or registered login.

    Parameters:
    destination - Relative URL, the dest parameter for the SessionLogin servlet.

    getTitle

    public org.apache.ecs.Element getTitle(java.lang.String title)
    Returns the title of a document.


    sideBySide

    public org.apache.ecs.Element sideBySide(java.lang.String title_left,
                                             org.apache.ecs.Element body_left,
                                             java.lang.String title_right,
                                             org.apache.ecs.Element body_right)
    Layout the two elements side by side. If both titles are null, the title row is skipped.


    upAndDown

    public org.apache.ecs.Element upAndDown(java.lang.String title_up,
                                            org.apache.ecs.Element body_up,
                                            java.lang.String title_down,
                                            org.apache.ecs.Element body_down)
    Layout the two editor elements up and down. Any element (title or body) that is null is skipped.


    createTitleCell

    public org.apache.ecs.html.TD createTitleCell(java.lang.String title)

    createTitleCell

    public org.apache.ecs.html.TD createTitleCell(java.lang.String title,
                                                  boolean wrap)

    createBodyCell

    public org.apache.ecs.html.TD createBodyCell(org.apache.ecs.Element body)

    createBodyCell

    public org.apache.ecs.html.TD createBodyCell(org.apache.ecs.Element body,
                                                 boolean wrap)

    getRecord

    public UserRecord getRecord(java.lang.String userID,
                                java.lang.String password)
    Returns the user record associated with this userID.

    Returns:
    The requested user record or null if no such record has been found.

    getRecord

    public UserRecord getRecord(java.lang.String recordID)
    Returns the user record associated with this recordID.

    Parameters:
    recordID - The ID for a valid record or "guest" to get the guest record.
    Returns:
    The requested user record or null if no such record has been found.

    isRegistered

    public boolean isRegistered(java.lang.String userID,
                                java.lang.String password)
    Checks wether the couple (userID, password) is registered or not.

    Returns:
    True when (userID, password) has been registered, False when (userID, password) is unknown from the system.

    register

    public void register(java.lang.String userID,
                         UserRecord record)
                  throws BadUserID,
                         RegistrationFailure
    BadUserID
    RegistrationFailure

    getUserDirectory

    public UserDirectory getUserDirectory()
    Returns the current user directory. The directory contains information about registered users.


    sendMail

    public void sendMail(UserRecord recipient,
                         java.lang.String subject,
                         java.lang.String message)
    Sends an email to the user defined by a user record. The message is addressed to the email address of the user defined by the record. Problems are logged.

    Specified by:
    sendMail in interface SimpleMailer

    getPersistenceScheme

    public PersistenceScheme getPersistenceScheme(javax.servlet.http.HttpServletRequest request)
    Returns the persistence scheme current implementation. This scheme come from the current WebService implementation, which has to be installed by the client service.


    main

    public static void main(java.lang.String[] args)
    Tests and demonstrates this class behaviour.


    destroy

    public void destroy()
    Free ressources used by this service. This method is called when the servlet engine ClassLoader determined a need to reload the classes.


    isUserLoggedIn

    public static boolean isUserLoggedIn(javax.servlet.http.HttpServletRequest request)
    Determines whether the user that makes the request is logged in. When this method returns true, it is garanteed that
    1. A session exists,
    2. The session contains a value called service_manager that supports the ServiceManager interface. This value can be used to customize the pages built by ServletCentral for a given service. It is also important for the ResourceFile mechanism.
    3. The session contains a value called UserSession that supports the UserSession interface.

    Returns:
    True when the user has logged in, False otherwise.
    See Also:
    #getService

    getServiceManager

    public ServiceManager getServiceManager(javax.servlet.http.HttpServletRequest request)
    Returns the ServiceManager associated with this request. ServletCentral is designed to support several web services. To provide better support, it sometimes needs to know a few information about the service it supports (to kind of personalize the support...). The service manager provides for this feature. A web service that makes use of ServletCentral must provide its information via subclassing WebService. The subclassed instance is then set the current service in the service manager which is stored in the session. This is a bit confused and will be explained in more detail when we will support transitions between several services.

    Returns:
    ServiceManager is always valid. If it cannot be determined, an InternalError is thrown.

    hasServiceManager

    public boolean hasServiceManager(javax.servlet.http.HttpServletRequest request)
    Returns whether there is a service manager associated with this request.

    Returns:
    True when there is a service manager, false otherwise.


    Copyright @ 2003 Mount Sinai School of Medicine. All Rights Reserved.