org.apache.turbine.services.template
Class TurbineTemplateService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.TurbineBaseService
                    |
                    +--org.apache.turbine.services.template.TurbineTemplateService
All Implemented Interfaces:
Initable, Service, TemplateService

public class TurbineTemplateService
extends TurbineBaseService
implements TemplateService

This service provides a method for mapping templates to their appropriate Screens or Navigations. It also allows templates to define a layout/navigations/screen modularization within the template structure. It also performs caching if turned on in the properties file. Since everything is keyed off the template variable, if data.getParameters().getString("template") returns /about_us/directions/driving.vm, the search for the Screen class is as follows (in order): 1. about_us.directions.Driving 2. about_us.directions.Default 3. about_us.Default 4. Default 5. VelocityScreen If the template variable does not exist, then VelocityScreen will be executed and templates/screens/index.vm will be executed. If index.vm is not found or if the template is invalid or Velocity execution throws an exception of any reason, then templates/screens/error.vm will be executed. For the Layouts and Navigations, the following paths will be searched in the layouts and navigations template subdirectories (in order): 1./about_us/directions/driving.vm 2./about_us/directions/default.vm 3./about_us/default.vm 4./default.vm

Version:
$Id: TurbineTemplateService.java,v 1.4 2002/04/16 22:07:09 kschrader Exp $
Author:
John D. McNally, Dave Bryson, Jason van Zyl, Daniel Rall, Ilkka Priha

Field Summary
protected static int LAYOUT_KEY
           
protected static int LAYOUT_TEMPLATE_KEY
           
protected static int NAVIGATION_KEY
           
protected static java.lang.String NO_FILE_EXT
          The default file extension used as a registry key when a template's file extension cannot be determined.
protected static int PAGE_KEY
          The keys of template objects provided by the service.
protected static int SCREEN_KEY
           
protected static int SCREEN_TEMPLATE_KEY
           
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.template.TemplateService
SERVICE_NAME
 
Constructor Summary
TurbineTemplateService()
           
 
Method Summary
protected  java.lang.String getCachedName(java.lang.String template, int key)
          Get the cached template object name.
 java.lang.String getDefaultExtension()
          Get the default template name extension specified in the template service properties.
 java.lang.String getDefaultLayout()
          Get the default layout module name of the template engine service corresponding to the default template name extension.
 java.lang.String getDefaultLayoutName(RunData data)
          Find the default layout module name for the given request.
 java.lang.String getDefaultLayoutName(java.lang.String template)
          Get the default layout module name of the template engine service corresponding to the template name extension of the named template.
 java.lang.String getDefaultLayoutTemplate()
          Get the default layout template name of the template engine service corresponding to the default template name extension.
 java.lang.String getDefaultLayoutTemplateName(java.lang.String template)
          Get the default layout template name of the template engine service corresponding to the template name extension of the named template.
protected  java.lang.String getDefaultModuleName(java.lang.String template, int key)
          Get the default module name of the template engine service corresponding to the template name extension of the named template.
 java.lang.String getDefaultNavigation()
          Get the default navigation module name of the template engine service corresponding to the default template name extension.
 java.lang.String getDefaultNavigationName(java.lang.String template)
          Get the default navigation module name of the template engine service corresponding to the template name extension of the named template.
 java.lang.String getDefaultPage()
          Get the default page module name of the template engine service corresponding to the default template name extension.
 java.lang.String getDefaultPageName(RunData data)
          Find the default page module name for the given request.
 java.lang.String getDefaultPageName(java.lang.String template)
          Get the default page module name of the template engine service corresponding to the template name extension of the named template.
 java.lang.String getDefaultScreen()
          Get the default screen module name of the template engine service corresponding to the default template name extension.
 java.lang.String getDefaultScreenName(java.lang.String template)
          Get the default screen module name of the template engine service corresponding to the template name extension of the named template.
 java.lang.String getLayoutName(java.lang.String template)
          Locate and return the name of the layout module to be used with the named layout template.
 java.lang.String getLayoutTemplateName(java.lang.String template)
          Locate and return the name of the layout template corresponding to the given screen template name parameter.
 java.lang.String getNavigationName(java.lang.String template)
          Locate and return the name of the navigation module to be used with the named navigation template.
protected  java.lang.String getParsedLayoutTemplateName(java.lang.String template)
          Get the parsed layout template name for the specified template.
protected  java.lang.String getParsedModuleName(java.lang.String template, int key)
          Get the parsed module name for the specified template.
protected  java.lang.String getParsedScreenTemplateName(java.lang.String template)
          Get the parsed screen template name for the specified template.
 java.lang.String getScreenName(java.lang.String template)
          Locate and return the name of the screen module to be used with the named screen template.
 java.lang.String getScreenTemplateName(java.lang.String template)
          Locate and return the name of the screen template corresponding to the given template name parameter.
protected  TemplateEngineService getTemplateEngineService(java.lang.String template)
          The TemplateEngineService associated with the specified template's file extension.
 void init()
          Called the first time the Service is used.
 void registerTemplateEngineService(TemplateEngineService service)
          Registers the provided template engine for use by the TemplateService.
 boolean templateExists(java.lang.String template, java.lang.String[] templatePaths)
          Delegates to the appropriate TemplateEngineService to check the existance of the specified template.
 java.lang.String[] translateTemplatePaths(java.lang.String[] templatePaths)
          Translates the supplied template paths into their Turbine-canonical equivalent (probably absolute paths).
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init, init, shutdown
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker, shutdown
 

Field Detail

NO_FILE_EXT

protected static final java.lang.String NO_FILE_EXT
The default file extension used as a registry key when a template's file extension cannot be determined.

PAGE_KEY

protected static final int PAGE_KEY
The keys of template objects provided by the service.

SCREEN_KEY

protected static final int SCREEN_KEY

LAYOUT_KEY

protected static final int LAYOUT_KEY

NAVIGATION_KEY

protected static final int NAVIGATION_KEY

LAYOUT_TEMPLATE_KEY

protected static final int LAYOUT_TEMPLATE_KEY

SCREEN_TEMPLATE_KEY

protected static final int SCREEN_TEMPLATE_KEY
Constructor Detail

TurbineTemplateService

public TurbineTemplateService()
Method Detail

init

public void init()
          throws InitializationException
Called the first time the Service is used.
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Throws:
InitializationException. -  

getDefaultExtension

public java.lang.String getDefaultExtension()
Get the default template name extension specified in the template service properties.
Specified by:
getDefaultExtension in interface TemplateService
Returns:
The default the extension.

getDefaultPage

public java.lang.String getDefaultPage()
Get the default page module name of the template engine service corresponding to the default template name extension.
Specified by:
getDefaultPage in interface TemplateService
Returns:
The default page module name.

getDefaultScreen

public java.lang.String getDefaultScreen()
Get the default screen module name of the template engine service corresponding to the default template name extension.
Specified by:
getDefaultScreen in interface TemplateService
Returns:
The default screen module name.

getDefaultLayout

public java.lang.String getDefaultLayout()
Get the default layout module name of the template engine service corresponding to the default template name extension.
Specified by:
getDefaultLayout in interface TemplateService
Returns:
The default layout module name.

getDefaultNavigation

public java.lang.String getDefaultNavigation()
Get the default navigation module name of the template engine service corresponding to the default template name extension.
Specified by:
getDefaultNavigation in interface TemplateService
Returns:
The default navigation module name.

getDefaultLayoutTemplate

public java.lang.String getDefaultLayoutTemplate()
Get the default layout template name of the template engine service corresponding to the default template name extension.
Specified by:
getDefaultLayoutTemplate in interface TemplateService
Returns:
The default layout template name.

getDefaultPageName

public java.lang.String getDefaultPageName(java.lang.String template)
Get the default page module name of the template engine service corresponding to the template name extension of the named template.
Specified by:
getDefaultPageName in interface TemplateService
Parameters:
template - The template name.
Returns:
The default page module name.

getDefaultScreenName

public java.lang.String getDefaultScreenName(java.lang.String template)
Get the default screen module name of the template engine service corresponding to the template name extension of the named template.
Specified by:
getDefaultScreenName in interface TemplateService
Parameters:
template - The template name.
Returns:
The default screen module name.

getDefaultLayoutName

public java.lang.String getDefaultLayoutName(java.lang.String template)
Get the default layout module name of the template engine service corresponding to the template name extension of the named template.
Specified by:
getDefaultLayoutName in interface TemplateService
Parameters:
template - The template name.
Returns:
The default layout module name.

getDefaultNavigationName

public java.lang.String getDefaultNavigationName(java.lang.String template)
Get the default navigation module name of the template engine service corresponding to the template name extension of the named template.
Specified by:
getDefaultNavigationName in interface TemplateService
Parameters:
template - The template name.
Returns:
The default navigation module name.

getDefaultLayoutTemplateName

public java.lang.String getDefaultLayoutTemplateName(java.lang.String template)
Get the default layout template name of the template engine service corresponding to the template name extension of the named template.
Specified by:
getDefaultLayoutTemplateName in interface TemplateService
Parameters:
template - The template name.
Returns:
The default layout template name.

getDefaultPageName

public java.lang.String getDefaultPageName(RunData data)
Find the default page module name for the given request.
Specified by:
getDefaultPageName in interface TemplateService
Parameters:
data - The encapsulation of the request to retrieve the default page for.
Returns:
The default page module name.

getDefaultLayoutName

public java.lang.String getDefaultLayoutName(RunData data)
Find the default layout module name for the given request.
Specified by:
getDefaultLayoutName in interface TemplateService
Parameters:
data - The encapsulation of the request to retrieve the default layout for.
Returns:
The default layout module name.

getScreenName

public java.lang.String getScreenName(java.lang.String template)
                               throws java.lang.Exception
Locate and return the name of the screen module to be used with the named screen template.
Specified by:
getScreenName in interface TemplateService
Parameters:
template - The screen template name.
Returns:
The found screen module name.
Throws:
Exception, - a generic exception.

getLayoutName

public java.lang.String getLayoutName(java.lang.String template)
                               throws java.lang.Exception
Locate and return the name of the layout module to be used with the named layout template.
Specified by:
getLayoutName in interface TemplateService
Parameters:
template - The layout template name.
Returns:
The found layout module name.
Throws:
Exception, - a generic exception.

getNavigationName

public java.lang.String getNavigationName(java.lang.String template)
                                   throws java.lang.Exception
Locate and return the name of the navigation module to be used with the named navigation template.
Specified by:
getNavigationName in interface TemplateService
Parameters:
template - The navigation template name.
Returns:
The found navigation module name.
Throws:
Exception, - a generic exception.

getScreenTemplateName

public java.lang.String getScreenTemplateName(java.lang.String template)
                                       throws java.lang.Exception
Locate and return the name of the screen template corresponding to the given template name parameter.
Specified by:
getScreenTemplateName in interface TemplateService
Parameters:
template - The template name parameter.
Returns:
The found screen template name.
Throws:
Exception, - a generic exception.

getLayoutTemplateName

public java.lang.String getLayoutTemplateName(java.lang.String template)
                                       throws java.lang.Exception
Locate and return the name of the layout template corresponding to the given screen template name parameter.
Specified by:
getLayoutTemplateName in interface TemplateService
Parameters:
template - The template name parameter.
Returns:
The found screen template name.
Throws:
Exception, - a generic exception.

translateTemplatePaths

public java.lang.String[] translateTemplatePaths(java.lang.String[] templatePaths)
Translates the supplied template paths into their Turbine-canonical equivalent (probably absolute paths).
Specified by:
translateTemplatePaths in interface TemplateService
Parameters:
templatePaths - An array of template paths.
Returns:
An array of translated template paths.

templateExists

public boolean templateExists(java.lang.String template,
                              java.lang.String[] templatePaths)
Delegates to the appropriate TemplateEngineService to check the existance of the specified template.
Specified by:
templateExists in interface TemplateService
Parameters:
template - The template to check for the existance of.
templatePaths - The paths to check for the template.

registerTemplateEngineService

public void registerTemplateEngineService(TemplateEngineService service)
Registers the provided template engine for use by the TemplateService.
Specified by:
registerTemplateEngineService in interface TemplateService
Parameters:
service - The TemplateEngineService to register.

getTemplateEngineService

protected TemplateEngineService getTemplateEngineService(java.lang.String template)
The TemplateEngineService associated with the specified template's file extension.
Parameters:
template - The template name.
Returns:
The template engine service.

getDefaultModuleName

protected java.lang.String getDefaultModuleName(java.lang.String template,
                                                int key)
Get the default module name of the template engine service corresponding to the template name extension of the named template.
Parameters:
template - The template name.
key - The module type key.
Returns:
The default page module name.

getCachedName

protected java.lang.String getCachedName(java.lang.String template,
                                         int key)
                                  throws java.lang.Exception
Get the cached template object name. If caching is not in use or the name is not in the cache, try to find the name from the template directories.
Parameters:
template - The template name.
key - The object type key.
Returns:
The cached name.
Throws:
Exception, - a generic exception.

getParsedModuleName

protected java.lang.String getParsedModuleName(java.lang.String template,
                                               int key)
                                        throws java.lang.Exception
Get the parsed module name for the specified template.
Parameters:
template - The template name.
key - The module type key.
Returns:
The parsed module name.
Throws:
Exception, - a generaic exception.

getParsedScreenTemplateName

protected java.lang.String getParsedScreenTemplateName(java.lang.String template)
                                                throws java.lang.Exception
Get the parsed screen template name for the specified template.
Parameters:
template - The template name.
Returns:
The parsed screen template name.
Throws:
Exception, - a generic exception.

getParsedLayoutTemplateName

protected java.lang.String getParsedLayoutTemplateName(java.lang.String template)
                                                throws java.lang.Exception
Get the parsed layout template name for the specified template.
Parameters:
template - The template name.
Returns:
The parsed layout template name.
Throws:
Exception, - a generic exception.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.