org.alltimeflashdreamer.mailwebform
Class AdminServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byorg.alltimeflashdreamer.mailwebform.AbstractMailWebFormServlet
              extended byorg.alltimeflashdreamer.mailwebform.AdminServlet
All Implemented Interfaces:
MailWebFormConstants, Serializable, Servlet, ServletConfig

public class AdminServlet
extends AbstractMailWebFormServlet

Title: AdminServlet
Description: This is the controller servlet of the admin tool which allows the administrator of the current MailWebForm installation to configure the registered providers "on-line", i.e. using the browser. These settings could be edited in the mailwebform.properties file manually, but because the file resides on the serlvet runner's host machine and the application is malfunctioning in case the file isn't edited properly, it's much easier and safer to use this servlet.
The admin tool has several different sites/views: The login screen, the main window and the edit provider settings screen. The tasks of these sites are:

Restrictions on the provider settings are as follows:

Version:
0.9
Author:
Copyright (c) 2001-2004 Florian Steinsiepe, Adrian Zaugg
See Also:
Serialized Form

Field Summary
(package private)  GlobalProperties globalProperties
          Properties instance storing the values read from the global properties file
(package private)  MailFormProviderList mailFormProviders
          the list of known providers of a mailwebform hosted by this servlet, including the "system" provider
 
Fields inherited from interface org.alltimeflashdreamer.mailwebform.MailWebFormConstants
ADMIN, ADMINSERVLET, APPNAME, COOKIENAME, CURRENTUSER, ERROR_URL, FILESEPARATOR, JSPBEAN, MAILFORMPROVIDER, MAILFORMPROVIDERLIST, MAILWEBFORM, MAILWEBFORMSERVLET, NEWLINE, PARAM_ADD, PARAM_APPLYGLOBAL, PARAM_APPLYINDIVIDUAL, PARAM_CANCEL, PARAM_CHANGE_CREDENTIALS, PARAM_CONFIGFILE, PARAM_CREDENTIALS_ADMIN, PARAM_EDIT, PARAM_ERRORURL, PARAM_FROMEMAIL, PARAM_FROMNAME, PARAM_LOGIN, PARAM_LOGOUT, PARAM_OVERWRITE, PARAM_PASSWORD, PARAM_PASSWORD_PROVIDER, PARAM_PROVIDER, PARAM_PROVIDERDIRECTORY, PARAM_REMOVE, PARAM_SMTPHOST, PARAM_SMTPPORT, PARAM_SPAMURL, PARAM_STORE, PARAM_SUBJECT, PARAM_SUCCESSURL, PARAM_TEMPLATE, PARAM_TEXT, PARAM_TOADDRESS, PARAM_TONAME, PARAM_USERNAME, PASSWORD, PASSWORDFILE, PLACEHOLDER_END, PLACEHOLDER_START, PROPERTY_CONFIGDIR, PROPERTY_SUFFIX, PROVIDERDIRECTORY, RESOURCENAME, SITE_CHANGE_CREDENTIALS, SITE_DEFAULTFORM, SITE_EDIT, SITE_ERROR, SITE_FOOTER, SITE_HEADER, SITE_LOGIN, SITE_MAIN, SITE_PROVIDER, SMTP_ALLOWOVERWRITE, SMTP_HOST, SMTP_PORT, SPAMERROR_URL, SUCCESS_URL, SYSTEMPROVIDER, TEMPLATE, TEMPLATE_SUFFIX, TOADDRESS, TONAME, USERNAME
 
Constructor Summary
AdminServlet()
           
 
Method Summary
 void destroy()
          Cleans up pointers and closes resources.
 void doGet(HttpServletRequest request, HttpServletResponse response)
          Since this servlet makes no distinction between a GET and a POST, pass the GET requests over to the doPost method.
 void doPost(HttpServletRequest request, HttpServletResponse response)
          This method can be called from different contexts, i.e. with different request parameters.
(package private) static String getConfigDirProperty()
          Reads the system property defining the app's config directory.
(package private)  File getCredentialsFile()
          Returns the abstract File instance pointing to the user credentials file.
(package private)  String getParameterIgnoreCase(HttpServletRequest request, String sKey)
          Searches the list of parameter names case-insensitively for the given key and returns the first value, if found.
(package private)  String[] getParameterValuesIgnoreCase(HttpServletRequest request, String sKey)
          Searches the list of parameter names case-insensitively for the given key and returns the value list, if found.
(package private)  File getPropertyFile()
          Returns the abstract File instance pointing to the global properties file.
(package private)  void printOutput(String sText, HttpServletResponse response)
          Prints the given text to the response's output writer, flushes and finally closes it.
(package private)  void readGlobalProperties()
          Reads the settings from the global properties file which must reside in the application classes' root folder.
(package private)  void showErrorScreen(MailWebFormException mwfe, HttpServletRequest request, HttpServletResponse response)
          Wraps the given error message into the JSPBean and redirects the client to the error page.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalProperties

GlobalProperties globalProperties
Properties instance storing the values read from the global properties file


mailFormProviders

MailFormProviderList mailFormProviders
the list of known providers of a mailwebform hosted by this servlet, including the "system" provider

Constructor Detail

AdminServlet

public AdminServlet()
Method Detail

doPost

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
            throws ServletException,
                   IOException
This method can be called from different contexts, i.e. with different request parameters. The servlet then decides which mode is "active" and reacts accordingly.
The possible modes are:

Specified by:
doPost in class AbstractMailWebFormServlet
Parameters:
request - contains the request parameters we need to have
response - contains the client's url to write to
Throws:
ServletException - in case problems occurred within the servlet container
IOException - in case problems occurred accessing a properties file

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws ServletException,
                  IOException
Since this servlet makes no distinction between a GET and a POST, pass the GET requests over to the doPost method.

Parameters:
request - (see description of implementing doPost method)
response - (see description of implementing doPost method)
Throws:
ServletException - (see description of implementing doPost method)
IOException - (see description of implementing doPost method)

readGlobalProperties

void readGlobalProperties()
                    throws MailWebFormException
Reads the settings from the global properties file which must reside in the application classes' root folder. In case this file isn't found, the upcoming exception is wrapped into a ServletException which is thrown, for convenience with each possible caller method.

Throws:
MailWebFormException - wrapped and commented IOException, if one was thrown

getPropertyFile

File getPropertyFile()
               throws MailWebFormException
Returns the abstract File instance pointing to the global properties file. If the file doesn't exist or the servlet runner user can't write to it, an exception is thrown.

Returns:
the global property file wrapper
Throws:
MailWebFormException - if the file is missing or not editable

getCredentialsFile

File getCredentialsFile()
                  throws MailWebFormException
Returns the abstract File instance pointing to the user credentials file.

Returns:
the user credentials file wrapper
Throws:
MailWebFormException - if the system's configdir property isn't set

getConfigDirProperty

static String getConfigDirProperty()
                            throws MailWebFormException
Reads the system property defining the app's config directory. If this property isn't set, an exception is thrown since the app can't work without this directory.

Returns:
the path to the config dir, containing forward slashes only and ending with such a forward slash
Throws:
MailWebFormException - if the property isn't defined

getParameterIgnoreCase

String getParameterIgnoreCase(HttpServletRequest request,
                              String sKey)
Searches the list of parameter names case-insensitively for the given key and returns the first value, if found.

Parameters:
request - what to query for the URL parameters
sKey - the key that shall case-insensitively be searched for
Returns:
the first parameter value, if found, else null

getParameterValuesIgnoreCase

String[] getParameterValuesIgnoreCase(HttpServletRequest request,
                                      String sKey)
Searches the list of parameter names case-insensitively for the given key and returns the value list, if found.

Parameters:
request - what to query for the URL parameters
sKey - the key that shall case-insensitively be searched for
Returns:
the list parameter values, if found, else null

printOutput

void printOutput(String sText,
                 HttpServletResponse response)
           throws IOException
Prints the given text to the response's output writer, flushes and finally closes it.

Parameters:
sText - a text that is wrapped into a very simple HTML page
response - contains the client's url to write to
Throws:
IOException - thrown by the PrintWriter class, if any

showErrorScreen

void showErrorScreen(MailWebFormException mwfe,
                     HttpServletRequest request,
                     HttpServletResponse response)
               throws IOException
Wraps the given error message into the JSPBean and redirects the client to the error page.

Parameters:
mwfe - the application-specific error object that is to be rendered
request - the client's request object
response - used for redirecting the client
Throws:
IOException - thrown by the PrintWriter class, if any

destroy

public void destroy()
Cleans up pointers and closes resources.

Specified by:
destroy in interface Servlet