org.apache.click.service
Class ClickResourceService

java.lang.Object
  extended by org.apache.click.service.ClickResourceService
All Implemented Interfaces:
ResourceService

public class ClickResourceService
extends Object
implements ResourceService

Provides a default Click static resource service class. This class will serve static resources contained in the web applications JARs, under the resource path META-INF/resources and which are contained under the WAR file web root.

This service is useful for application servers which do not allow Click to automatically deploy resources to the web root directory.


Field Summary
protected  ConfigService configService
          The application configuration service.
protected  LogService logService
          The application log service.
protected  Map<String,byte[]> resourceCache
          The click resources cache.
 
Constructor Summary
ClickResourceService()
           
 
Method Summary
protected  List<String> getCacheableDirs()
          Return the list of directories that contains cacheable resources.
 boolean isResourceRequest(HttpServletRequest request)
          Return true if the request is for a static resource.
 void onDestroy()
          Destroy the ResourceService.
 void onInit(ServletContext servletContext)
          Initialize the ResourceService with the given application configuration service instance.
 void renderResource(HttpServletRequest request, HttpServletResponse response)
          Render the resource request to the given servlet resource response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resourceCache

protected Map<String,byte[]> resourceCache
The click resources cache.


logService

protected LogService logService
The application log service.


configService

protected ConfigService configService
The application configuration service.

Constructor Detail

ClickResourceService

public ClickResourceService()
Method Detail

onInit

public void onInit(ServletContext servletContext)
            throws IOException
Description copied from interface: ResourceService
Initialize the ResourceService with the given application configuration service instance.

This method is invoked after the ResourceService has been constructed.

Specified by:
onInit in interface ResourceService
Parameters:
servletContext - the application servlet context
Throws:
IOException - if an IO error occurs initializing the service
See Also:
ResourceService.onInit(ServletContext)

onDestroy

public void onDestroy()
Description copied from interface: ResourceService
Destroy the ResourceService.

Specified by:
onDestroy in interface ResourceService
See Also:
ResourceService.onDestroy()

isResourceRequest

public boolean isResourceRequest(HttpServletRequest request)
Description copied from interface: ResourceService
Return true if the request is for a static resource.

Specified by:
isResourceRequest in interface ResourceService
Parameters:
request - the servlet request
Returns:
true if the request is for a static click resource
See Also:
ResourceService.isResourceRequest(HttpServletRequest)

renderResource

public void renderResource(HttpServletRequest request,
                           HttpServletResponse response)
                    throws IOException
Description copied from interface: ResourceService
Render the resource request to the given servlet resource response.

Specified by:
renderResource in interface ResourceService
Parameters:
request - the servlet resource request
response - the servlet response
Throws:
IOException - if an IO error occurs rendering the resource
See Also:
ResourceService.renderResource(HttpServletRequest, HttpServletResponse)

getCacheableDirs

protected List<String> getCacheableDirs()
Return the list of directories that contains cacheable resources.

By default only resource packaged under the "/click" directory will be processed. To serve resources from other directories you need to override this method and return a list of directories to process.

For example:

 public class MyResourceService extends ClickResourceService {

     protected List getCacheableDirs() {
         // Get default dirs which includes /click
         List list = super.getCacheableDirs();

         // Add resources packaged under the folder /clickclick
         list.add("/clickclick");
         // Add resources packaged under the folder /mycorp
         list.add("/mycorp");
     }
 } 
You also need to add a mapping in your web.xml to forward requests for these resources on to Click:
 <-- The default Click *.htm mapping -->
 <servlet-mapping>
   <servlet-name>ClickServlet</servlet-name>
   <url-pattern>*.htm</url-pattern>
 </servlet-mapping>

 <-- Add a mapping to serve all resources under /click directly from
 the JARs. -->
 <servlet-mapping>
   <servlet-name>ClickServlet</servlet-name>
   <url-pattern>/click/*</url-pattern>
 </servlet-mapping>

 <-- Add another mapping to serve all resources under /clickclick
 from the JARs. -->
 <servlet-mapping>
   <servlet-name>ClickServlet</servlet-name>
   <url-pattern>/clickclick/*</url-pattern>
 </servlet-mapping>

 <-- Add a mapping to serve all resources under /mycorp
 from the JARs. -->
 <servlet-mapping>
   <servlet-name>ClickServlet</servlet-name>
   <url-pattern>/mycorp/*</url-pattern>
 </servlet-mapping>
 

Returns:
list of directories that should be cached