net.sf.click.service
Interface ConfigService

All Known Implementing Classes:
XmlConfigService

public interface ConfigService

Provides a Click application configuration service interface.

A single application ConfigService instance is created by the ClickServlet at startup. Once the ConfigService has been initialized it is stored in the ServletContext using the key "net.sf.click.service.ConfigService".

Configuration

The default ConfigService is XmlConfigService.

However it is possible to specify a different implementation.

For example you can subclass XmlConfigService and override methods such as onInit(javax.servlet.ServletContext) to alter initialization behavior.

For Click to recognize your custom service class you must set the context initialization parameter, config-service-class in your web.xml file.

Below is an example of a custom service class com.mycorp.service.CustomConfigSerivce:

 package com.mycorp.service;

 public class CustomConfigService extends XmlConfigService {

     public CustomConfigService() {
     }

     public void onInit(ServletContext servletContext) throws Exception {
         // Add your logic here
         ...

         // Call super to resume initialization
         super.onInit(servletContext);
     }
 }
 
Please note that the custom ConfigService implementation must have a no-argument constructor so Click can instantiate the service.

Also define the new service in your web.xml as follows:

 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">

 ...

     <context-param>
         <param-name>config-service-class</param-name>
         <param-value>com.mycorp.service.CustomConfigSerivce</param-value>
     </context-param>

 ...

 </web-app> 

Author:
Malcolm Edgar

Field Summary
static String CONTEXT_NAME
          The servlet context attribute name.
static String ERROR_PATH
          The error page file path:   "/click/error.htm".
static String MODE_DEBUG
          The debug application mode.
static String MODE_DEVELOPMENT
          The development application mode.
static String MODE_PRODUCTION
          The profile application mode.
static String MODE_PROFILE
          The profile application mode.
static String MODE_TRACE
          The trace application mode.
static String NOT_FOUND_PATH
          The page not found file path:   "/click/not-found.htm".
 
Method Summary
 Format createFormat()
          Create and return a new format object instance.
 String getApplicationMode()
          Return the Click application mode value:   ["production", "profile", "development", "debug", "trace"].
 String getCharset()
          Return the Click application charset or null if not defined.
 Class getErrorPageClass()
          Return the error handling page Page Class.
 FileUploadService getFileUploadService()
          Return the application file upload service, which is used to parse multi-part file upload post requests.
 Locale getLocale()
          Return the Click application locale or null if not defined.
 LogService getLogService()
          Return the Click application log service.
 Class getNotFoundPageClass()
          Return the page not found Page Class.
 Class getPageClass(String path)
          Return the page Class for the given path.
 List getPageClassList()
          Return the list of configured page classes.
 Field getPageField(Class pageClass, String fieldName)
          Return the public field of the given name for the pageClass, or null if not defined.
 Field[] getPageFieldArray(Class pageClass)
          Return an array public fields for the given page class.
 Map getPageFields(Class pageClass)
          Return Map of public fields for the given page class.
 Map getPageHeaders(String path)
          Return the headers of the page for the given path.
 String getPagePath(Class pageClass)
          Return the path for the given page Class.
 ServletContext getServletContext()
          Return the application servlet context.
 TemplateService getTemplateService()
          Return the application templating service.
 boolean isJspPage(String path)
          Return true if JSP exists for the given ".htm" path.
 boolean isPagesAutoBinding()
          Return true if auto binding is enabled.
 boolean isProductionMode()
          Return true if the application is in "production" mode.
 boolean isProfileMode()
          Return true if the application is in "profile" mode.
 void onDestroy()
          Destroy the ConfigurationService.
 void onInit(ServletContext servletContext)
          Initialize the ConfigurationService with the given application servlet context.
 

Field Detail

MODE_TRACE

public static final String MODE_TRACE
The trace application mode.

See Also:
Constant Field Values

MODE_DEBUG

public static final String MODE_DEBUG
The debug application mode.

See Also:
Constant Field Values

MODE_DEVELOPMENT

public static final String MODE_DEVELOPMENT
The development application mode.

See Also:
Constant Field Values

MODE_PROFILE

public static final String MODE_PROFILE
The profile application mode.

See Also:
Constant Field Values

MODE_PRODUCTION

public static final String MODE_PRODUCTION
The profile application mode.

See Also:
Constant Field Values

ERROR_PATH

public static final String ERROR_PATH
The error page file path:   "/click/error.htm".

See Also:
Constant Field Values

NOT_FOUND_PATH

public static final String NOT_FOUND_PATH
The page not found file path:   "/click/not-found.htm".

See Also:
Constant Field Values

CONTEXT_NAME

public static final String CONTEXT_NAME
The servlet context attribute name. The ClickServlet stores the application ConfigService instance in the ServletContext using this context attribute name.

See Also:
Constant Field Values
Method Detail

onInit

public void onInit(ServletContext servletContext)
            throws Exception
Initialize the ConfigurationService with the given application servlet context.

This method is invoked after the ConfigurationService has been constructed.

Parameters:
servletContext - the application servlet context
Throws:
Exception - if an error occurs initializing the ConfigurationService

onDestroy

public void onDestroy()
Destroy the ConfigurationService. This method will also invoke the onDestory() methods on the FileUploadService and the TemplateService.


getFileUploadService

public FileUploadService getFileUploadService()
Return the application file upload service, which is used to parse multi-part file upload post requests.

Returns:
the application file upload service

getTemplateService

public TemplateService getTemplateService()
Return the application templating service.

Returns:
the application templating service

getApplicationMode

public String getApplicationMode()
Return the Click application mode value:   ["production", "profile", "development", "debug", "trace"].

Returns:
the application mode value

getCharset

public String getCharset()
Return the Click application charset or null if not defined.

Returns:
the application charset value

getErrorPageClass

public Class getErrorPageClass()
Return the error handling page Page Class.

Returns:
the error handling page Page Class

createFormat

public Format createFormat()
Create and return a new format object instance.

Returns:
a new format object instance

isJspPage

public boolean isJspPage(String path)
Return true if JSP exists for the given ".htm" path.

Parameters:
path - the Page ".htm" path
Returns:
true if JSP exists for the given ".htm" path

isPagesAutoBinding

public boolean isPagesAutoBinding()
Return true if auto binding is enabled. Autobinding will automatically bind any request parameters to public fields, add any public controls to the page and add public fields to the page model.

Returns:
true if request parameters should be automatically bound to public page fields

isProductionMode

public boolean isProductionMode()
Return true if the application is in "production" mode.

Returns:
true if the application is in "production" mode

isProfileMode

public boolean isProfileMode()
Return true if the application is in "profile" mode.

Returns:
true if the application is in "profile" mode

getLocale

public Locale getLocale()
Return the Click application locale or null if not defined.

Returns:
the application locale value

getLogService

public LogService getLogService()
Return the Click application log service.

Returns:
the application log service.

getPagePath

public String getPagePath(Class pageClass)
Return the path for the given page Class.

Parameters:
pageClass - the class of the Page to lookup the path for
Returns:
the path for the given page Class
Throws:
IllegalArgumentException - if the Page Class is not configured with a unique path

getPageClass

public Class getPageClass(String path)
Return the page Class for the given path.

Parameters:
path - the page path
Returns:
the page class for the given path
Throws:
IllegalArgumentException - if the Page Class for the path is not found

getPageClassList

public List getPageClassList()
Return the list of configured page classes.

Returns:
the list of configured page classes

getPageFields

public Map getPageFields(Class pageClass)
Return Map of public fields for the given page class.

Parameters:
pageClass - the page class
Returns:
a Map of public fields for the given page class

getPageField

public Field getPageField(Class pageClass,
                          String fieldName)
Return the public field of the given name for the pageClass, or null if not defined.

Parameters:
pageClass - the page class
fieldName - the name of the field
Returns:
the public field of the pageClass with the given name or null

getPageFieldArray

public Field[] getPageFieldArray(Class pageClass)
Return an array public fields for the given page class.

Parameters:
pageClass - the page class
Returns:
an array public fields for the given page class

getPageHeaders

public Map getPageHeaders(String path)
Return the headers of the page for the given path.

Parameters:
path - the path of the page
Returns:
a Map of headers for the given page path

getNotFoundPageClass

public Class getNotFoundPageClass()
Return the page not found Page Class.

Returns:
the page not found Page Class

getServletContext

public ServletContext getServletContext()
Return the application servlet context.

Returns:
the application servlet context