org.olat.core.defaults.dispatcher
Class StaticMediaDispatcher

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

public class StaticMediaDispatcher
extends LogDelegator
implements Dispatcher

Description:

A dispatcher that delivers raw static files without any servlet intervention or security checks directly from the webapp/static directory.

The URL contains the web app version ID to make sure browsers always fetch the newest version after a new release to prevent browser caching issues.

This should only be used to deliver basic files from the body.html and some other static resource. When developing modules, put all your static files like js libraries or other resource into the _static resources folder and include them using the JSAndCSSComponent.java or get the URL to those resources from th ClassPathStaticDispatcher.java

Initial Date: 16.05.2007

Author:
Florian Gnaegi, frentix GmbH, http://www.frentix.com

Field Summary
static java.lang.String NOVERSION
           
static java.lang.String STATIC_DIR_NAME
           
 
Constructor Summary
StaticMediaDispatcher(java.lang.String mapperPathFromConfig)
          Constructor
 
Method Summary
static java.lang.String createStaticURIFor(java.lang.String URI)
          Create a static URI for this relative URI.
static java.lang.String createStaticURIFor(java.lang.String URI, boolean addVersionID)
          Create a static URI for this relative URI.
 void execute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String uriPrefix)
           
static java.lang.String getStaticMapperPath()
           
static java.lang.String normalizePath(java.lang.String path)
          Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path
static void renderStaticURI(StringOutput target, java.lang.String URI)
          Note: use only rarely - all non-generic js libs and css classes should be included using JsAndCssComponent, and all images should be referenced with the css background-image capability.
static void renderStaticURI(StringOutput target, java.lang.String URI, boolean addVersionID)
          Render a static URL to resource.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATIC_DIR_NAME

public static java.lang.String STATIC_DIR_NAME

NOVERSION

public static java.lang.String NOVERSION
Constructor Detail

StaticMediaDispatcher

public StaticMediaDispatcher(java.lang.String mapperPathFromConfig)
Constructor

Parameters:
mapperPathFromConfig -
Method Detail

execute

public void execute(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response,
                    java.lang.String uriPrefix)
Specified by:
execute in interface Dispatcher
See Also:
Dispatcher.execute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)

normalizePath

public static java.lang.String normalizePath(java.lang.String path)
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path

".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the current context (i.e. too many ".." path elements are present), return null instead.

Parameters:
path - Path to be normalized
Returns:
the normalized path

renderStaticURI

public static void renderStaticURI(StringOutput target,
                                   java.lang.String URI)
Note: use only rarely - all non-generic js libs and css classes should be included using JsAndCssComponent, and all images should be referenced with the css background-image capability.
renders a uri which is mounted to the webapp/static/ directory of your web application.

This method will add a version ID to the path that guarantees that the browser fetches the file again when you release a new version of your application.

Parameters:
target -
URI - e.g. img/specialimagenotpossiblewithcss.jpg

renderStaticURI

public static void renderStaticURI(StringOutput target,
                                   java.lang.String URI,
                                   boolean addVersionID)
Render a static URL to resource. This is only used in special cases, in most scenarios you should use the JSAndCssComponent

Parameters:
target - The output target
URI - e.g. img/specialimagenotpossiblewithcss.jpg
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

createStaticURIFor

public static java.lang.String createStaticURIFor(java.lang.String URI)
Create a static URI for this relative URI. Helper method in case no String output is available.

This method will add a version ID to the path that guarantees that the browser fetches the file again when you release a new version of your application.

Parameters:
URI - e.g. img/specialimagenotpossiblewithcss.jpg
Returns:

createStaticURIFor

public static java.lang.String createStaticURIFor(java.lang.String URI,
                                                  boolean addVersionID)
Create a static URI for this relative URI. Helper method in case no String output is available.

Parameters:
URI - e.g. img/specialimagenotpossiblewithcss.jpg
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:

getStaticMapperPath

public static java.lang.String getStaticMapperPath()