org.apache.jetspeed.locator
Class JetspeedTemplateLocator

java.lang.Object
  extended by org.apache.jetspeed.locator.JetspeedTemplateLocator
All Implemented Interfaces:
org.apache.jetspeed.locator.TemplateLocator

public class JetspeedTemplateLocator
extends Object
implements org.apache.jetspeed.locator.TemplateLocator

Jetspeed's default implementation of a template locator.

Version:
$Id: JetspeedTemplateLocator.java 587334 2007-10-23 00:30:49Z taylor $
Author:
David Sean Taylor

Field Summary
private  String appRoot
          Root of the application running this locator
private  String defaultLocatorType
          the default locator type
private  Class locatorClass
          the TemplateLocator class is factory created
private static org.apache.commons.logging.Log log
           
private static String PATH_SEPARATOR
           
private  List roots
          the template root directories, all application root relative
private  Class templateClass
          the Template class is factory created
private  Map templateMap
          template name cache used to speed up searches for templates
private  boolean useNameCache
          use the name cache when looking up a template
 
Constructor Summary
private JetspeedTemplateLocator()
           
  JetspeedTemplateLocator(List roots, List omClasses, String defaultLocatorType, String appRoot)
          Assemble with list resource directory roots and OM classes and a defaultLocatorType.
  JetspeedTemplateLocator(List roots, String appRoot)
          Minimal assembly with a list of resource directory roots.
  JetspeedTemplateLocator(List roots, String defaultLocatorType, String appRoot)
          Construct with a root list and a default locator type.
 
Method Summary
 org.apache.jetspeed.locator.LocatorDescriptor createFromString(String path)
           
 org.apache.jetspeed.locator.LocatorDescriptor createLocatorDescriptor(String type)
           
private  org.apache.jetspeed.locator.TemplateDescriptor createTemplate()
           
private  org.apache.jetspeed.locator.TemplateDescriptor createTemplateFromPath(String path, String name, String realPath, String relativePath)
          Given a path, name and realPath creates a new template object
private  void loadNameCache(String path, String name)
          Loads the template name cache map to accelerate template searches.
 org.apache.jetspeed.locator.TemplateDescriptor locateTemplate(org.apache.jetspeed.locator.LocatorDescriptor locator)
           
private  org.apache.jetspeed.locator.TemplateDescriptor locateTemplate(org.apache.jetspeed.locator.LocatorDescriptor locator, String root, boolean useCache)
          General template location algorithm.
 Iterator query(org.apache.jetspeed.locator.LocatorDescriptor locator)
           
 void start()
           
 void stop()
           
 boolean templateExists(String templateKey)
           
 boolean templateExists(String templateKey, boolean useCache)
          Checks for the existence of a template resource given a key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

PATH_SEPARATOR

private static final String PATH_SEPARATOR
See Also:
Constant Field Values

roots

private List roots
the template root directories, all application root relative


appRoot

private String appRoot
Root of the application running this locator


templateClass

private Class templateClass
the Template class is factory created


locatorClass

private Class locatorClass
the TemplateLocator class is factory created


defaultLocatorType

private String defaultLocatorType
the default locator type


templateMap

private Map templateMap
template name cache used to speed up searches for templates


useNameCache

private boolean useNameCache
use the name cache when looking up a template

Constructor Detail

JetspeedTemplateLocator

private JetspeedTemplateLocator()

JetspeedTemplateLocator

public JetspeedTemplateLocator(List roots,
                               String appRoot)
                        throws FileNotFoundException
Minimal assembly with a list of resource directory roots.

Parameters:
roots - A list of resource root directories where templates are located.
appRoot - Root from where this application runs
Throws:
FileNotFoundException

JetspeedTemplateLocator

public JetspeedTemplateLocator(List roots,
                               String defaultLocatorType,
                               String appRoot)
                        throws FileNotFoundException
Construct with a root list and a default locator type.

Parameters:
roots - A list of resource root directories where templates are located.
defaultLocatorType - Under root directories, subdirectories represent locator types. A locator type represents a classification of templates. Any value is allowed. Use locator types to group templates together.
Throws:
FileNotFoundException

JetspeedTemplateLocator

public JetspeedTemplateLocator(List roots,
                               List omClasses,
                               String defaultLocatorType,
                               String appRoot)
                        throws FileNotFoundException
Assemble with list resource directory roots and OM classes and a defaultLocatorType.

Parameters:
roots - A list of resource root directories where templates are located.
omClasses - Template replacable object model implementations for Template and TemplateLocator. Required order, with second optional: [ Template, TemplateLocator implementations.
defaultLocatorType - Under root directories, subdirectories represent locator types. A locator type represents a classification of templates. Any value is allowed. Use locator types to group templates together.
Throws:
FileNotFoundException
Method Detail

locateTemplate

public org.apache.jetspeed.locator.TemplateDescriptor locateTemplate(org.apache.jetspeed.locator.LocatorDescriptor locator)
Specified by:
locateTemplate in interface org.apache.jetspeed.locator.TemplateLocator

locateTemplate

private org.apache.jetspeed.locator.TemplateDescriptor locateTemplate(org.apache.jetspeed.locator.LocatorDescriptor locator,
                                                                      String root,
                                                                      boolean useCache)
General template location algorithm. Starts with the most specific resource, including mediatype + nls specification, and fallsback to least specific.

Parameters:
locator - The template locator
root - The root directory to search
Returns:
TemplateDescriptor the exact path to the template, or null if not found.

templateExists

public boolean templateExists(String templateKey,
                              boolean useCache)
Checks for the existence of a template resource given a key. The key are absolute paths to the templates, and are cached in a template cache for performance.

Parameters:
key - The absolute path to the template resource.
Returns:
True when the template is found, otherwise false.

templateExists

public boolean templateExists(String templateKey)

createFromString

public org.apache.jetspeed.locator.LocatorDescriptor createFromString(String path)
                                                               throws org.apache.jetspeed.locator.TemplateLocatorException
Specified by:
createFromString in interface org.apache.jetspeed.locator.TemplateLocator
Throws:
org.apache.jetspeed.locator.TemplateLocatorException

createTemplateFromPath

private org.apache.jetspeed.locator.TemplateDescriptor createTemplateFromPath(String path,
                                                                              String name,
                                                                              String realPath,
                                                                              String relativePath)
Given a path, name and realPath creates a new template object

Parameters:
path - the relative path to the template
name - the template name
realPath - the real path on the file system
Returns:
newly created TemplateDescriptor

createLocatorDescriptor

public org.apache.jetspeed.locator.LocatorDescriptor createLocatorDescriptor(String type)
                                                                      throws org.apache.jetspeed.locator.TemplateLocatorException
Specified by:
createLocatorDescriptor in interface org.apache.jetspeed.locator.TemplateLocator
Throws:
org.apache.jetspeed.locator.TemplateLocatorException

createTemplate

private org.apache.jetspeed.locator.TemplateDescriptor createTemplate()

start

public void start()

stop

public void stop()

query

public Iterator query(org.apache.jetspeed.locator.LocatorDescriptor locator)
Specified by:
query in interface org.apache.jetspeed.locator.TemplateLocator

loadNameCache

private void loadNameCache(String path,
                           String name)
Loads the template name cache map to accelerate template searches.

Parameters:
path - The template
name - just the name of the resource


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.