org.olat.core.defaults.dispatcher
Class ClassPathStaticDispatcher

java.lang.Object
  extended by org.olat.core.logging.LogDelegator
      extended by org.olat.core.defaults.dispatcher.ClassPathStaticDispatcher
All Implemented Interfaces:
Dispatcher

public class ClassPathStaticDispatcher
extends LogDelegator
implements Dispatcher

Description:
Allows to register static mappers. Here you can create urls which are valid for all users and can be cached by browsers. The delivered resources must be static files in the _static directory of your code.

In mod-jk mode this static files can be delivered directly from apache or even from another file server

If you need global mappers that provide dynamic content, then you mus use the GlobalMapperRegistry.java

If you need urls that are only accessible for one user, use the MapperRegistry.java

Initial Date: 6.10.2008

Author:
Florian Gnaegi

Constructor Summary
ClassPathStaticDispatcher(boolean copyStaticFilesConfig, java.lang.String dispatcherPath)
          Constructor, only used by spring.
 
Method Summary
 void copyStaticClassPathFiles()
          Helper method to copy all class path static files to the webapp/static/classpath/ directory for direct delivery via apache.
 MediaResource createClassPathStaticFileMediaResourceFor(java.lang.Class baseClass, java.lang.String relPath)
          Create a static class path media resource form a given base class
 MediaResource createClassPathStaticFileMediaResourceFor(java.lang.Package pakkage, java.lang.String relPath)
          Create a static class path media resource form a given package
 void execute(javax.servlet.http.HttpServletRequest hreq, javax.servlet.http.HttpServletResponse hres, java.lang.String pathInfo)
           
static ClassPathStaticDispatcher getInstance()
           
 java.lang.String getMapperBasePath(java.lang.Class clazz)
          Create a path for the _static directory for the given class.
 java.lang.String getMapperBasePath(java.lang.Class clazz, boolean addVersionID)
          Create a path for the _static directory for the given class.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassPathStaticDispatcher

public ClassPathStaticDispatcher(boolean copyStaticFilesConfig,
                                 java.lang.String dispatcherPath)
Constructor, only used by spring. Use getInstance instead!

Parameters:
copyStaticFilesConfig - true: copy static files and deliver via StaticMediaDispatcher; false: don't copy files and deliver from classpath
dispatcherPath - : path where to dispatch files ( e.g. '/classpath/')
Method Detail

getInstance

public static ClassPathStaticDispatcher getInstance()
Returns:
MapperRegistry

getMapperBasePath

public java.lang.String getMapperBasePath(java.lang.Class clazz)
Create a path for the _static directory for the given class. Resources that are in this directory can be addressed relatively to the generated mapper path. The resources can also be stored in a jar file.

Parameters:
globalNameClass - class for the name of the mapper. the name of the mapper is the name of the package name for this class
Returns:
the path under which this mapper will be called, without / at the end, e.g. /olat/classpath/612/org.olat.demo.tabledemo (the 612 here is the versionId to guarantee the uniqueness across releases to trick out buggy css browser caches)

getMapperBasePath

public java.lang.String getMapperBasePath(java.lang.Class clazz,
                                          boolean addVersionID)
Create a path for the _static directory for the given class. Resources that are in this directory can be addressed relatively to the generated mapper path. The resources can also be stored in a jar file.

Parameters:
clazz - The package name of this class is used for the path
addVersionID - true: the build version is added to the URL to force browser reload the resource when releasing a new version; false: don't add version (but allow browsers to cache even when resource has changed). Only use false when really needed
Returns:
the path under which this mapper will be called, without / at the end, e.g. /olat/classpath/612/org.olat.demo.tabledemo (the 612 here is the versionId to guarantee the uniqueness across releases to trick out buggy css browser caches)

execute

public void execute(javax.servlet.http.HttpServletRequest hreq,
                    javax.servlet.http.HttpServletResponse hres,
                    java.lang.String pathInfo)
Specified by:
execute in interface Dispatcher
Parameters:
hreq -
hres -

createClassPathStaticFileMediaResourceFor

public MediaResource createClassPathStaticFileMediaResourceFor(java.lang.Class baseClass,
                                                               java.lang.String relPath)
Create a static class path media resource form a given base class

Parameters:
baseClass -
relPath -
Returns:

createClassPathStaticFileMediaResourceFor

public MediaResource createClassPathStaticFileMediaResourceFor(java.lang.Package pakkage,
                                                               java.lang.String relPath)
Create a static class path media resource form a given package

Parameters:
baseClass -
relPath -
Returns:

copyStaticClassPathFiles

public void copyStaticClassPathFiles()
Helper method to copy all class path static files to the webapp/static/classpath/ directory for direct delivery via apache.

This method should only be called once at startup. To speed up things it checks on the last modified date of the files and copies only new files.