org.apache.commons.scaffold.http
Class ResourceServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.apache.commons.scaffold.http.ResourceServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ConnectionServlet

public class ResourceServlet
extends javax.servlet.http.HttpServlet

Base servlet for loading application resources.

Author:
Ted Husted, Steve Raeburn
See Also:
Serialized Form

Constructor Summary
ResourceServlet()
           
 
Method Summary
 void destroy()
          Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.
protected  void destroyCustom()
          Release any custom resources created at initialization
protected  void destroyDefault()
          Release any default resources created at initialization
 int getInitInt(String parameter, int defaultValue)
          Check for a parameter and returns a default value if not found, or if the value does not convert to an int.
 Map getInitParameters()
          Return a map of this servlet's initialization parameters.
 String getInitString(String parameter, String defaultValue)
          Check for a parameter and returns a default value if not found.
 Properties getProperties()
          Return the default properties object.
 void init()
          Initialize this servlet by caling three extension points: initLogging initDefault initCustom The main extension point is initCustom The default implementation does nothing.
protected  void initCustom()
          Initialize the custom properties or objects for this application.
protected  void initDefault()
          Initialize the default properties for this application.
 Properties loadProperties(String parameter, String defaultPath, String attribute)
          A utility method for loading a Properties file specified by an initialization parameter.
 void reload()
          Reload the configuration of this controller servlet from our underlying configuration files.
 void setProperties(Properties properties)
          Set the default properties object.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceServlet

public ResourceServlet()
Method Detail

getInitString

public String getInitString(String parameter,
                            String defaultValue)
Check for a parameter and returns a default value if not found.

Parameters:
parameter - The attribute name to look for
defaultValue - The default to return if the parameter is not found
Returns:
The customized value or the default value

getInitInt

public int getInitInt(String parameter,
                      int defaultValue)
Check for a parameter and returns a default value if not found, or if the value does not convert to an int.

Parameters:
parameter - The attribute name to look for
Returns:
The customized value or the default value

getInitParameters

public Map getInitParameters()
Return a map of this servlet's initialization parameters.

Returns:
A map of this servlet's initialization parameters.

setProperties

public void setProperties(Properties properties)
Set the default properties object.


getProperties

public Properties getProperties()
Return the default properties object.

Returns:
The default properties object

loadProperties

public Properties loadProperties(String parameter,
                                 String defaultPath,
                                 String attribute)
                          throws javax.servlet.ServletException
A utility method for loading a Properties file specified by an initialization parameter. The initialization parameter should specify the package and folder for the Properties in system path format (resources/custom.properties).

Parameters:
parameter - The name of the initialization parameter
defaultPath - The path to use if the parameter is not found
attribute - If not null, store in application scope under this attribute name
Throws:
javax.servlet.ServletException

initDefault

protected void initDefault()
                    throws IOException,
                           javax.servlet.ServletException
Initialize the default properties for this application.

Use the default initialization parameter to specify another path. Otherwise ["resources/default.properties"] is used.

If the default properties will not be used or specified, override this method with one that does not try to load the default properties.

Throws:
IOException - if an input/output error is encountered
javax.servlet.ServletException - if we cannot initialize these resources

destroyDefault

protected void destroyDefault()
Release any default resources created at initialization


init

public void init()
          throws javax.servlet.ServletException
Initialize this servlet by caling three extension points: The main extension point is initCustom The default implementation does nothing. The other two methods have reasonable default behaviors that most subclasses could use as-is. This may be called again from reload and should be "re-enterant".

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException - if we cannot configure ourselves correctly

destroy

public void destroy()
Gracefully shut down this controller servlet, releasing any resources that were allocated at initialization.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

initCustom

protected void initCustom()
                   throws IOException,
                          javax.servlet.ServletException
Initialize the custom properties or objects for this application.

Throws:
IOException - if an input/output error is encountered
javax.servlet.ServletException - if we cannot initialize these resources

destroyCustom

protected void destroyCustom()
Release any custom resources created at initialization


reload

public void reload()
            throws IOException,
                   javax.servlet.ServletException
Reload the configuration of this controller servlet from our underlying configuration files.

Throws:
IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet exception occurs


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.