org.apache.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 "org.apache.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.CustomConfigService:

 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> 


Nested Class Summary
static class ConfigService.AutoBinding
          The page auto binding mode.
 
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"].
 ConfigService.AutoBinding getAutoBindingMode()
          Return the page auto binding mode.
 String getCharset()
          Return the Click application charset or null if not defined.
 Class<? extends Page> 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 application log service.
 MessagesMapService getMessagesMapService()
          Return the application messages map service.
 Class<? extends Page> getNotFoundPageClass()
          Return the page not found Page Class.
 Class<? extends Page> getPageClass(String path)
          Return the page Class for the given path.
 List<Class<? extends Page>> getPageClassList()
          Return the list of configured page classes.
 Field getPageField(Class<? extends Page> pageClass, String fieldName)
          Return the bindable field of the given name for the pageClass, or null if not defined.
 Field[] getPageFieldArray(Class<? extends Page> pageClass)
          Return an array bindable for the given page class.
 Map<String,Field> getPageFields(Class<? extends Page> pageClass)
          Return Map of bindable fields for the given page class.
 Map<String,Object> getPageHeaders(String path)
          Return the headers of the page for the given path.
 List<PageInterceptor> getPageInterceptors()
          Return the list of configured PageInterceptors instances.
 String getPagePath(Class<? extends Page> pageClass)
          Return the path for the given page Class.
 ResourceService getResourceService()
          Return the application resource service.
 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 isProductionMode()
          Return true if the application is in "production" mode.
 boolean isProfileMode()
          Return true if the application is in "profile" mode.
 boolean isTemplate(String path)
          Return true if the given resource is a Page class template, false otherwise.
 void onDestroy()
          Destroy the ConfigurationService.
 void onInit(ServletContext servletContext)
          Initialize the ConfigurationService with the given application servlet context.
 

Field Detail

MODE_TRACE

static final String MODE_TRACE
The trace application mode.

See Also:
Constant Field Values

MODE_DEBUG

static final String MODE_DEBUG
The debug application mode.

See Also:
Constant Field Values

MODE_DEVELOPMENT

static final String MODE_DEVELOPMENT
The development application mode.

See Also:
Constant Field Values

MODE_PROFILE

static final String MODE_PROFILE
The profile application mode.

See Also:
Constant Field Values

MODE_PRODUCTION

static final String MODE_PRODUCTION
The profile application mode.

See Also:
Constant Field Values

ERROR_PATH

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

See Also:
Constant Field Values

NOT_FOUND_PATH

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

See Also:
Constant Field Values

CONTEXT_NAME

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. The value of this constant is "org.apache.click.service.ConfigService".

See Also:
Constant Field Values
Method Detail

onInit

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

void onDestroy()
Destroy the ConfigurationService. This method will also invoke the onDestroy() methods on the FileUploadService, TemplateService, ResourceService and the LogService in that order.


getFileUploadService

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

getLogService

LogService getLogService()
Return the application log service.

Returns:
the application log service.

getResourceService

ResourceService getResourceService()
Return the application resource service.

Returns:
the application resource service.

getTemplateService

TemplateService getTemplateService()
Return the application templating service.

Returns:
the application templating service

getMessagesMapService

MessagesMapService getMessagesMapService()
Return the application messages map service.

Returns:
the application messages Map service

getApplicationMode

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

Returns:
the application mode value

getCharset

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

Returns:
the application charset value

getErrorPageClass

Class<? extends Page> getErrorPageClass()
Return the error handling page Page Class.

Returns:
the error handling page Page Class

createFormat

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

Returns:
a new format object instance

isJspPage

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

isTemplate

boolean isTemplate(String path)
Return true if the given resource is a Page class template, false otherwise.

Below is an example showing how to map .htm and .jsp files as Page class templates.

 public class XmlConfigService implements ConfigService {

     ...

     public boolean isTemplate(String path) {
         if (path.endsWith(".htm") || path.endsWith(".jsp")) {
             return true;
         }
         return false;
     }

     ...
 } 

Parameters:
path - the path to check if it is a Page class template or not
Returns:
true if the resource is a Page class template, false otherwise

getAutoBindingMode

ConfigService.AutoBinding getAutoBindingMode()
Return the page auto binding mode. If the mode is "PUBLIC" any public Page fields will be auto bound, if the mode is "ANNOTATION" any Page field with the "Bindable" annotation will be auto bound and if the mode is "NONE" no Page fields will be auto bound.

Returns:
the Page field auto binding mode { PUBLIC, ANNOTATION, NONE }

isProductionMode

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

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

isProfileMode

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

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

getLocale

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

Returns:
the application locale value

getPagePath

String getPagePath(Class<? extends Page> 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

Class<? extends Page> getPageClass(String path)
Return the page Class for the given path. The path must start with a "/".

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

List<Class<? extends Page>> getPageClassList()
Return the list of configured page classes.

Returns:
the list of configured page classes

getPageFields

Map<String,Field> getPageFields(Class<? extends Page> pageClass)
Return Map of bindable fields for the given page class.

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

getPageField

Field getPageField(Class<? extends Page> pageClass,
                   String fieldName)
Return the bindable 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 bindable field of the pageClass with the given name or null

getPageHeaders

Map<String,Object> 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

getPageFieldArray

Field[] getPageFieldArray(Class<? extends Page> pageClass)
Return an array bindable for the given page class.

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

getPageInterceptors

List<PageInterceptor> getPageInterceptors()
Return the list of configured PageInterceptors instances.

Returns:
the list of configured PageInterceptors instances

getNotFoundPageClass

Class<? extends Page> getNotFoundPageClass()
Return the page not found Page Class.

Returns:
the page not found Page Class

getServletContext

ServletContext getServletContext()
Return the application servlet context.

Returns:
the application servlet context