org.olat.core.gui.control
Class JSAndCSSAdder

java.lang.Object
  extended by org.olat.core.gui.control.JSAndCSSAdder
Direct Known Subclasses:
JSAndCSSAdderImpl

public abstract class JSAndCSSAdder
extends java.lang.Object

Description:

Initial Date: 04.05.2006

Author:
Felix Jost

Field Summary
static int CSS_INDEX_AFTER_THEME
           
static int CSS_INDEX_BEFORE_THEME
           
static int CSS_INDEX_THEME
           
 
Constructor Summary
JSAndCSSAdder()
           
 
Method Summary
abstract  void addRequiredCSSFile(java.lang.Class baseClass, java.lang.String cssFileName, boolean forceRemove)
          This method will add the CSS file before the theme.
abstract  void addRequiredCSSFile(java.lang.Class baseClass, java.lang.String cssFileName, boolean forceRemove, int cssLoadIndex)
           
abstract  void addRequiredCSSPath(java.lang.String cssPath, boolean forceRemove, int cssLoadIndex)
          used rather rarely, e.g.
abstract  void addRequiredJsFile(java.lang.Class baseClass, java.lang.String jsFileName)
          adds a js file to be served in the html header to the list of required js-files.
abstract  void addRequiredJsFile(java.lang.Class baseClass, java.lang.String jsFileName, java.lang.String fileEncoding)
          adds a js file to be served in the html header to the list of required js-files.
abstract  void addRequiredJsFile(java.lang.Class baseClass, java.lang.String jsFileName, java.lang.String fileEncoding, java.lang.String preAJAXAddJsCode)
          adds a js file to be served in the html header to the list of required js-files.
abstract  void addRequiredRawHeader(java.lang.Class baseClass, java.lang.String rawHeader)
           
abstract  boolean finishAndCheckChange()
           
abstract  java.lang.String getMappedPathFor(java.lang.Class baseClass, java.lang.String fileName)
          Get the mapper path for this class and file name, e.g.
abstract  void requireFullPageRefresh()
          requires that a full page reload takes places.
abstract  void setRequiredRefreshInterval(java.lang.Class baseClass, int refreshIntervall)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CSS_INDEX_BEFORE_THEME

public static final int CSS_INDEX_BEFORE_THEME
See Also:
Constant Field Values

CSS_INDEX_THEME

public static final int CSS_INDEX_THEME
See Also:
Constant Field Values

CSS_INDEX_AFTER_THEME

public static final int CSS_INDEX_AFTER_THEME
See Also:
Constant Field Values
Constructor Detail

JSAndCSSAdder

public JSAndCSSAdder()
Method Detail

addRequiredJsFile

public abstract void addRequiredJsFile(java.lang.Class baseClass,
                                       java.lang.String jsFileName)
adds a js file to be served in the html header to the list of required js-files. e.g. addRequiredJsFile(MyController.class, "js/myscript.js") where the file myscript.js must be under "location of MyController.class"/_static/js

In full page refresh mode, the library will be included to the page header using the standard script tags.

In AJAX mode, the library is will read the file from disk, transfer the content via the AJAX channel and then eval() the content in the window.

In case that your script needs some values to be initialized before the eval() happens, use the other addRequiredJsFile() for this purpose

Parameters:
baseClass -
jsFileName -

addRequiredJsFile

public abstract void addRequiredJsFile(java.lang.Class baseClass,
                                       java.lang.String jsFileName,
                                       java.lang.String fileEncoding)
adds a js file to be served in the html header to the list of required js-files. e.g. addRequiredJsFile(MyController.class, "js/myscript.js") where the file myscript.js must be under "location of MyController.class"/_static/js

In full page refresh mode, the library will be included to the page header using the standard script tags.

In AJAX mode, the library is will read the file from disk, transfer the content via the AJAX channel and then eval() the content in the window. The fileEncoding is used to read the file from disk.

In case that your script needs some values to be initialized before the eval() happens, use the other addRequiredJsFile() for this purpose

Parameters:
baseClass -
jsFileName -
fileEncoding - the encoding of the js file or NULL to use the default encoding (utf-8)

addRequiredJsFile

public abstract void addRequiredJsFile(java.lang.Class baseClass,
                                       java.lang.String jsFileName,
                                       java.lang.String fileEncoding,
                                       java.lang.String preAJAXAddJsCode)
adds a js file to be served in the html header to the list of required js-files. e.g. addRequiredJsFile(MyController.class, "js/myscript.js") where the file myscript.js must be under "location of MyController.class"/_static/js

In full page refresh mode, the library will be included to the page header using the standard script tags.

In AJAX mode, the library is will first eval() the content of the supplied string evalBeforeDomReplacementJsCode, then read the file from disk, transfere the content via the AJAX channel and then eval() the content in the window.The fileEncoding is used to read the file from disk.

Parameters:
baseClass - The class where the script is localted
jsFileName - The script path, e.g. js/myscript.js
fileEncoding - the encoding of the js file or NULL to use the default encoding (utf-8)
preAJAXAddJsCode - A string containing some values to be eval()-ed right before the script itself is eval()-ed

addRequiredCSSFile

public abstract void addRequiredCSSFile(java.lang.Class baseClass,
                                        java.lang.String cssFileName,
                                        boolean forceRemove,
                                        int cssLoadIndex)
Parameters:
baseClass -
cssFileName -
forceRemove - normally, once added css files will not be removed anymore. However, if your css overrides default settings (e.g. when you have a preview css), this css must be removed as soon as the validate method does not require it anymore. (e.g. when you leave the course edit mode)
cssIndex - position of the css in relation of the position of the theme. Use JSAndCSSAdder.CSS_INDEX_* variables to set this

addRequiredCSSFile

public abstract void addRequiredCSSFile(java.lang.Class baseClass,
                                        java.lang.String cssFileName,
                                        boolean forceRemove)
This method will add the CSS file before the theme. use the other method to change this behaviour

Parameters:
baseClass -
cssFileName -
forceRemove - normally, once added css files will not be removed anymore. However, if your css overrides default settings (e.g. when you have a preview css), this css must be removed as soon as the validate method does not require it anymore. (e.g. when you leave the course edit mode)

addRequiredCSSPath

public abstract void addRequiredCSSPath(java.lang.String cssPath,
                                        boolean forceRemove,
                                        int cssLoadIndex)
used rather rarely, e.g. when you have a css with content which is dynamic (e.g. a custom course css in olat).
Use a Mapper/MapperRegistry to obtain a cssPath
Normally (for fixed css) use

Parameters:
cssPath - the path to the css, e.g. /olat/m/1001/mycss.css
forceRemove - normally, once added css files will not be removed anymore. However, if your css overrides default settings (e.g. when you have a preview css), this css must be removed as soon as the validate method does not require it anymore. (e.g. when you leave the course edit mode)
cssIndex - position of the css in relation of the position of the theme. Use JSAndCSSAdder.CSS_INDEX_* variables to set this
See Also:
addRequiredCSSFile(Class baseClass, String cssFileName, boolean forceRemove);

finishAndCheckChange

public abstract boolean finishAndCheckChange()
Returns:
true if there has been a new (never been added before) (or a deleted css which has been marked as to-be-removed) required css or js file's base since the previous call to this method, false otherwise (no new js or css libs needed)

addRequiredRawHeader

public abstract void addRequiredRawHeader(java.lang.Class baseClass,
                                          java.lang.String rawHeader)
Parameters:
baseClass -
rawHeader -

setRequiredRefreshInterval

public abstract void setRequiredRefreshInterval(java.lang.Class baseClass,
                                                int refreshIntervall)
Parameters:
refreshIntervall - the time in miliseconds after which (in ajax mode) a refresh of the screen is needed. use small times with caution, since it generates server load. after the given time, a poll (comet, push, hanging get for future release) is issued to the server to collect the dirty components and rerender them. when more than one interval is requested in one validation phase (=on one browser window), then the minimum is taken.

requireFullPageRefresh

public abstract void requireFullPageRefresh()
requires that a full page reload takes places. sometimes eval'ing a more complex js lib (such as tiny mce) directly into global context does not work (timing issues?) this should be used only rarely when complex js is executed and has errors in it, since a full page refresh is slower than a ajax call.
when a component is validated (last cycle before rendering), and a full page refresh is required, then a full page request command is sent via JSON to the browser which then executes it using document.location.replace(...). Since this step involves two calls (JSON+reload), this is slower than a normal full page click (aka known as non-ajax mode).


getMappedPathFor

public abstract java.lang.String getMappedPathFor(java.lang.Class baseClass,
                                                  java.lang.String fileName)
Get the mapper path for this class and file name, e.g. to use in a preAJAXAddJsCode call when adding a JS script that needs to load other scripts as well.

Parameters:
baseClass -
fileName - the name of the file or NULL to get the base path.
Returns:
A string that represents the path of the JS file as it is used on a full page refresh. If fileName is null, the base path wihout trailing slash is returned.