org.alltimeflashdreamer.mailwebform
Class AbstractMailWebFormServlet

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

abstract class AbstractMailWebFormServlet
extends HttpServlet
implements MailWebFormConstants

Title: AbstractMailWebFormServlet
Description: The abstract superclass for MailWebForm's servlets collects fields and methods used by each of the extending classes.

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

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
(package private) AbstractMailWebFormServlet()
           
 
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.
abstract  void doPost(HttpServletRequest request, HttpServletResponse response)
          This method is declared only, to make sure that extending classes override, i.e. implement it.
(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

AbstractMailWebFormServlet

AbstractMailWebFormServlet()
Method Detail

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)

doPost

public abstract void doPost(HttpServletRequest request,
                            HttpServletResponse response)
                     throws ServletException,
                            IOException
This method is declared only, to make sure that extending classes override, i.e. implement it.

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