org.cdlib.xtf.servletBase
Class StylesheetCache

Object
  extended by Cache<K,V>
      extended by GeneratingCache
          extended by StylesheetCache

public class StylesheetCache
extends GeneratingCache

This class is used to cache stylesheets so they don't have to be reloaded each time they're used.


Nested Class Summary
private  class StylesheetCache.DepResolver
          While loading a stylesheet, we record all the sub-stylesheets referenced by it, so that we can form a list of all the dependencies.
 
Nested classes/interfaces inherited from class Cache
Cache.ListEntry, Cache.NullIterator
 
Field Summary
private  boolean dependencyChecking
           
private  GeneratingCache dependencyReceiver
           
private  boolean enableProfiling
           
private  TransformerFactory factory
           
 
Fields inherited from class Cache
ageList, keyMap
 
Constructor Summary
StylesheetCache(int maxEntries, int maxTime, boolean dependencyChecking)
          Constructor.
 
Method Summary
 void enableProfiling(boolean flag)
          Enable or disable profiling (only affects stylesheets that are not already cached)
 Templates find(String path)
          Locate the stylesheet for the given filesystem path.
protected  Object generate(Object key)
          Load and parse a stylesheet from the filesystem.
protected  void logAction(String action, Object key, Object value)
          Prints out useful debugging info
 
Methods inherited from class GeneratingCache
addDependency, find
 
Methods inherited from class Cache
cleanup, clear, dependenciesValid, getDependencies, has, lastSet, remove, size
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dependencyChecking

private boolean dependencyChecking

dependencyReceiver

private GeneratingCache dependencyReceiver

enableProfiling

private boolean enableProfiling

factory

private TransformerFactory factory
Constructor Detail

StylesheetCache

public StylesheetCache(int maxEntries,
                       int maxTime,
                       boolean dependencyChecking)
Constructor.

Parameters:
maxEntries - Max # of entries before old ones are flushed
maxTime - Max age (in seconds) before an entry is flushed.
dependencyChecking - Whether to keep track of dependencies and invalidate cache entries when dependents are updated.
Method Detail

find

public Templates find(String path)
               throws Exception
Locate the stylesheet for the given filesystem path. If not cached, then load it.

Parameters:
path - Filesystem path of the stylesheet to load
Returns:
The parsed stylesheet
Throws:
Exception - If the stylesheet could not be loaded.

enableProfiling

public void enableProfiling(boolean flag)
Enable or disable profiling (only affects stylesheets that are not already cached)


generate

protected Object generate(Object key)
                   throws Exception
Load and parse a stylesheet from the filesystem.

Specified by:
generate in class GeneratingCache
Parameters:
key - (String)Filesystem path of the stylesheet to load
Returns:
The parsed stylesheet
Throws:
Exception - If the stylesheet could not be loaded.

logAction

protected void logAction(String action,
                         Object key,
                         Object value)
Prints out useful debugging info

Overrides:
logAction in class Cache
Parameters:
action - What happened ("Added", "Removed", etc.)
key - The key involved in the action
value - The value involved in the action