org.locomotive.steam
Class CachedPageLoader

java.lang.Object
  |
  +--org.locomotive.steam.CachedPageLoader

public class CachedPageLoader
extends java.lang.Object

The CachedPageLoader evalutes templates from the filesystem or passed in as a string according to the rules of the LOCO Template Language. Templates are compiled the first time they are evaluated, then the compiled version is cached and used for subsequent re-evaluation. See the documentation for the template language for the details of its usage.


Constructor Summary
CachedPageLoader(Log slog, int id)
          Contructs a CachedPageLoader with the specified debugging log/identifier for internal logging.
 
Method Summary
protected static org.locomotive.steam.MixedExpr cachedTemplateExpr(java.lang.String filename)
          This method will get a template expression tree either from the cache or from a file.
protected static org.locomotive.steam.MixedExpr cachedTemplateExpr(java.lang.String filename, boolean evaluate)
          This method will get a template expression tree either from the cache or from a file.
static void clearTemplateCache()
          This static method can be called to flush the template cache.
 java.lang.String evalString(java.lang.String string_to_eval, java.util.Hashtable subs, boolean allow_load_cmds)
          Evaluate the following string.
 java.lang.String evalTemplate(java.lang.String t_path, java.util.Hashtable subs)
          Evaluate the given filename, relative to the given template root with the given substitution environment.
static void initialize(java.lang.String templ_root, int check_freq, int initial_bufsize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedPageLoader

public CachedPageLoader(Log slog,
                        int id)
Contructs a CachedPageLoader with the specified debugging log/identifier for internal logging.
Parameters:
slog - a destination log. May be null, in which case the CPL will not log
id - a unique id to be used in the output log. ignored if slog is null;
Method Detail

initialize

public static void initialize(java.lang.String templ_root,
                              int check_freq,
                              int initial_bufsize)

evalTemplate

public java.lang.String evalTemplate(java.lang.String t_path,
                                     java.util.Hashtable subs)
Evaluate the given filename, relative to the given template root with the given substitution environment. The enviroment is read write, and can contain name/values set during the evaluation process
Parameters:
t_path - the path to the template, relative to the template_root passed in via initialize()
subs - The environment (in/out)

evalString

public java.lang.String evalString(java.lang.String string_to_eval,
                                   java.util.Hashtable subs,
                                   boolean allow_load_cmds)
Evaluate the following string. Does NOT insert it into the cache.
Parameters:
string_to_eval - The string to evaluate.
subs - The environment (in/out)
allow_load_cmds - Whether or not to allow LOAD commands to load in templates from files (using the template_root passed in via initialize())

cachedTemplateExpr

protected static org.locomotive.steam.MixedExpr cachedTemplateExpr(java.lang.String filename)
This method will get a template expression tree either from the cache or from a file. If it is not in the cache, it will parse the file and store the new template expression tree into the cache. If it is in the cache, then it will nevertheless check whether the template file has changed. However, for efficiency purposes, it will not check every time; it will do so only every N times, where N = "check_template_freq".

If the file does not exist, or there were other problems, then it will return a tree with a single empty node which evaluates to "".


cachedTemplateExpr

protected static org.locomotive.steam.MixedExpr cachedTemplateExpr(java.lang.String filename,
                                                                   boolean evaluate)
This method will get a template expression tree either from the cache or from a file. If it is not in the cache, it will parse the file and store the new template expression tree into the cache. If it is in the cache, then it will nevertheless check whether the template file has changed. However, for efficiency purposes, it will not check every time; it will do so only every N times, where N = "check_template_freq".

If the file does not exist, or there were other problems, then it will return a tree with a single empty node which evaluates to "".

Parameters:
evaluate - whether or not to evaluate the file and parse it into a template tree

clearTemplateCache

public static void clearTemplateCache()
This static method can be called to flush the template cache. All currently cached compiled templates will be discarded. When a subsequent request for template evaluation is made, the corresponding template is reloaded, compiled, and evaluated, then the compiled version is again stored in the template cache.