Klasse TurbineTemplateService
- Alle implementierten Schnittstellen:
Initable
,Service
,TemplateService
# Register the VelocityService for the "vm" extension. services.VelocityService.template.extension=vm # Default Java class for rendering a Page in this service # (must be found on the class path (org.apache.turbine.modules.page.VelocityPage)) services.VelocityService.default.page = VelocityPage # Default Java class for rendering a Screen in this service # (must be found on the class path (org.apache.turbine.modules.screen.VelocityScreen)) services.VelocityService.default.screen=VelocityScreen # Default Java class for rendering a Layout in this service # (must be found on the class path (org.apache.turbine.modules.layout.VelocityOnlyLayout)) services.VelocityService.default.layout = VelocityOnlyLayout # Default Java class for rendering a Navigation in this service # (must be found on the class path (org.apache.turbine.modules.navigation.VelocityNavigation)) services.VelocityService.default.navigation=VelocityNavigation # Default Template Name to be used as Layout. If nothing else is # found, return this as the default name for a layout services.VelocityService.default.layout.template = Default.vmIf you want to render a template, a search path is used to find a Java class which might provide information for the context of this template. If you request e.g. the template screen
about,directions,Driving.vmthen the following class names are searched (on the module search path):
1. about.directions.Driving <- direct matching the template to the class name 2. about.directions.Default <- matching the package, class name is Default 3. about.Default <- stepping up in the package hierarchy, looking for Default 4. Default <- Class called "Default" without package 5. VelocityScreen <- The class configured by the Service (VelocityService) toAnd if you have the following module packages configured:
module.packages = org.apache.turbine.modules, com.mycorp.modulesthen the class loader will look for
org.apache.turbine.modules.screens.about.directions.Driving com.mycorp.modules.screens.about.directions.Driving org.apache.turbine.modules.screens.about.directions.Default com.mycorp.modules.screens.about.directions.Default org.apache.turbine.modules.screens.about.Default com.mycorp.modules.screens.about.Default org.apache.turbine.modules.screens.Default com.mycorp.modules.screens.Default org.apache.turbine.modules.screens.VelocityScreen com.mycorp.modules.screens.VelocityScreenMost of the times, you don't have any backing Java class for a template screen, so the first match will be org.apache.turbine.modules.screens.VelocityScreen which then renders your screen.
Please note, that your Screen Template (Driving.vm) must exist! If it does not exist, the Template Service will report an error.
Once the screen is found, the template service will look for the Layout and Navigation templates of your Screen. Here, the template service looks for matching template names!
Consider our example:
about,directions,Driving.vm (Screen Name)Now the template service will look for the following Navigation and Layout templates:
1. about,directions,Driving.vm <- exact match 2. about,directions,Default.vm <- package match, Default name 3. about,Default.vm <- stepping up in the hierarchy 4. Default.vm <- The name configured as default.layout.template in the Velocity service.And now Hennings' two golden rules for using templates:
Many examples and docs from older Turbine code show template pathes with a slashes. Repeat after me: "TEMPLATE NAMES NEVER CONTAIN SLASHES!"
Many examples and docs from older Turbine code show templates that start with "/". This is not only a violation of the rule above but actively breaks things like loading templates from a jar with the velocity jar loader. Repeat after me: "TEMPLATE NAMES ARE NOT PATHES. THEY'RE NOT ABSOLUTE AND HAVE NO LEADING /".
If you now wonder how a template name is mapped to a file name: This is scope of the templating engine. Velocity e.g. has this wonderful option to load templates from jar archives. There is no single file but you tell velocity "get about,directions,Driving.vm" and it returns the rendered template. This is not the job of the Templating Service but of the Template rendering services like VelocityService.
- Version:
- $Id$
- Autor:
- John D. McNally, Dave Bryson, Jason van Zyl, Daniel Rall, Ilkka Priha, Henning P. Schmiedehausen
-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final int
Represents Layout Objectsstatic final int
Represents Layout Template Objectsstatic final String
Represents Layout Template Objectsstatic final int
Represents Navigation Objectsstatic final int
Represents Navigation Template Objectsstatic final String
Represents Navigation Template Objectsprotected static final String
Veraltet.Use TemplateService.DEFAULT_EXTENSION_VALUE.static final int
Represents Page Objectsstatic final int
Represents Screen Objectsstatic final int
Represents Screen Template Objectsstatic final String
Represents Screen Template Objectsstatic final int
Number of different Template Types that we know ofVon Klasse geerbte Felder org.apache.turbine.services.BaseService
configuration, name, serviceBroker
Von Klasse geerbte Felder org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
Von Schnittstelle geerbte Felder org.apache.turbine.services.Service
SERVICE_NAME
Von Schnittstelle geerbte Felder org.apache.turbine.services.template.TemplateService
DEFAULT_EXTENSION_KEY, DEFAULT_EXTENSION_VALUE, DEFAULT_NAME, DEFAULT_TEMPLATE_KEY, DEFAULT_TEMPLATE_VALUE, EXTENSION_SEPARATOR, SERVICE_NAME, TEMPLATE_PARTS_SEPARATOR
-
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungGet the default template name extension specified in the template service properties.Get the default layout module name of the template engine service corresponding to the default template name extension.getDefaultLayoutName
(String template) Get the default layout module name of the template engine service corresponding to the template name extension of the named template.getDefaultLayoutName
(PipelineData pipelineData) Find the default layout module name for the given request.Get the default layout template name of the template engine service corresponding to the default template name extension.getDefaultLayoutTemplateName
(String template) Get the default layout template name of the template engine service corresponding to the template name extension of the named template.Get the default navigation module name of the template engine service corresponding to the default template name extension.getDefaultNavigationName
(String template) Get the default navigation module name of the template engine service corresponding to the template name extension of the named template.Get the default page module name of the template engine service corresponding to the default template name extension.getDefaultPageName
(String template) Get the default page module name of the template engine service corresponding to the template name extension of the named template.getDefaultPageName
(PipelineData pipelineData) Find the default page module name for the given request.Get the default screen module name of the template engine service corresponding to the default template name extension.getDefaultScreenName
(String template) Get the default screen module name of the template engine service corresponding to the template name extension of the named template.Returns the Default Template Name with the Default Extension.getExtension
(String template) Return Extension for a supplied templategetLayoutName
(String template) Locate and return the name of the layout module to be used with the named layout template.getLayoutTemplateName
(String template) Locate and return the name of the layout template corresponding to the given screen template name parameter.getNavigationName
(String template) Locate and return the name of the navigation module to be used with the named navigation template.getNavigationTemplateName
(String template) Locate and return the name of the navigation template corresponding to the given template name parameter.getScreenName
(String template) Locate and return the name of the screen module to be used with the named screen template.getScreenTemplateName
(String template) Locate and return the name of the screen template corresponding to the given template name parameter.getTemplateEngineService
(String template) TheTemplateEngineService
associated with the specified template's file extension.void
init()
Called the first time the Service is used.boolean
Returns true if the Template Service has caching activatedvoid
Registers the provided template engine for use by theTemplateService
.boolean
templateExists
(String template, String[] templatePaths) Veraltet.Use templateExists from the various Templating EnginesString[]
translateTemplatePaths
(String[] templatePaths) Veraltet.Each template engine service should know how to translate a request onto a file.Von Klasse geerbte Methoden org.apache.turbine.services.TurbineBaseService
init, init, shutdown
Von Klasse geerbte Methoden org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
Von Klasse geerbte Methoden org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
Von Klasse geerbte Methoden java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Von Schnittstelle geerbte Methoden org.apache.turbine.services.Initable
getInit, init, setInitableBroker, shutdown
Von Schnittstelle geerbte Methoden org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
-
Felddetails
-
PAGE_KEY
Represents Page Objects- Siehe auch:
-
SCREEN_KEY
Represents Screen Objects- Siehe auch:
-
LAYOUT_KEY
Represents Layout Objects- Siehe auch:
-
NAVIGATION_KEY
Represents Navigation Objects- Siehe auch:
-
LAYOUT_TEMPLATE_KEY
Represents Layout Template Objects- Siehe auch:
-
LAYOUT_TEMPLATE_NAME
Represents Layout Template Objects- Siehe auch:
-
SCREEN_TEMPLATE_KEY
Represents Screen Template Objects- Siehe auch:
-
SCREEN_TEMPLATE_NAME
Represents Screen Template Objects- Siehe auch:
-
NAVIGATION_TEMPLATE_KEY
Represents Navigation Template Objects- Siehe auch:
-
NAVIGATION_TEMPLATE_NAME
Represents Navigation Template Objects- Siehe auch:
-
TEMPLATE_TYPES
Number of different Template Types that we know of- Siehe auch:
-
NO_FILE_EXT
Veraltet.Use TemplateService.DEFAULT_EXTENSION_VALUE.The default file extension used as a registry key when a template's file extension cannot be determined.- Siehe auch:
-
-
Konstruktordetails
-
TurbineTemplateService
public TurbineTemplateService()C'tor
-
-
Methodendetails
-
init
Called the first time the Service is used.- Angegeben von:
init
in SchnittstelleInitable
- Setzt außer Kraft:
init
in KlasseTurbineBaseService
- Löst aus:
InitializationException
- Something went wrong when setting up the Template Service.
-
isCaching
Returns true if the Template Service has caching activated- Angegeben von:
isCaching
in SchnittstelleTemplateService
- Gibt zurück:
- true if Caching is active.
-
getDefaultExtension
Get the default template name extension specified in the template service properties. If no extension is defined, return the empty string.- Angegeben von:
getDefaultExtension
in SchnittstelleTemplateService
- Gibt zurück:
- The default extension.
-
getExtension
Return Extension for a supplied template- Angegeben von:
getExtension
in SchnittstelleTemplateService
- Parameter:
template
- The template name- Gibt zurück:
- extension The extension for the supplied template
-
getDefaultTemplate
Returns the Default Template Name with the Default Extension. If the extension is unset, return only the template name- Angegeben von:
getDefaultTemplate
in SchnittstelleTemplateService
- Gibt zurück:
- The default template Name
-
getDefaultPage
Get the default page module name of the template engine service corresponding to the default template name extension.- Angegeben von:
getDefaultPage
in SchnittstelleTemplateService
- Gibt zurück:
- The default page module name.
-
getDefaultScreen
Get the default screen module name of the template engine service corresponding to the default template name extension.- Angegeben von:
getDefaultScreen
in SchnittstelleTemplateService
- Gibt zurück:
- The default screen module name.
-
getDefaultLayout
Get the default layout module name of the template engine service corresponding to the default template name extension.- Angegeben von:
getDefaultLayout
in SchnittstelleTemplateService
- Gibt zurück:
- The default layout module name.
-
getDefaultLayoutTemplate
Get the default layout template name of the template engine service corresponding to the default template name extension.- Angegeben von:
getDefaultLayoutTemplate
in SchnittstelleTemplateService
- Gibt zurück:
- The default layout template name.
-
getDefaultPageName
Get the default page module name of the template engine service corresponding to the template name extension of the named template.- Angegeben von:
getDefaultPageName
in SchnittstelleTemplateService
- Parameter:
template
- The template name.- Gibt zurück:
- The default page module name.
-
getDefaultScreenName
Get the default screen module name of the template engine service corresponding to the template name extension of the named template.- Angegeben von:
getDefaultScreenName
in SchnittstelleTemplateService
- Parameter:
template
- The template name.- Gibt zurück:
- The default screen module name.
-
getDefaultLayoutName
Get the default layout module name of the template engine service corresponding to the template name extension of the named template.- Angegeben von:
getDefaultLayoutName
in SchnittstelleTemplateService
- Parameter:
template
- The template name.- Gibt zurück:
- The default layout module name.
-
getDefaultLayoutTemplateName
Get the default layout template name of the template engine service corresponding to the template name extension of the named template.- Angegeben von:
getDefaultLayoutTemplateName
in SchnittstelleTemplateService
- Parameter:
template
- The template name.- Gibt zurück:
- The default layout template name.
-
getDefaultPageName
Find the default page module name for the given request.- Angegeben von:
getDefaultPageName
in SchnittstelleTemplateService
- Parameter:
pipelineData
- The encapsulation of the request to retrieve the default page for.- Gibt zurück:
- The default page module name.
-
getDefaultLayoutName
Find the default layout module name for the given request.- Angegeben von:
getDefaultLayoutName
in SchnittstelleTemplateService
- Parameter:
pipelineData
- The encapsulation of the request to retrieve the default layout for.- Gibt zurück:
- The default layout module name.
-
getScreenName
Locate and return the name of the screen module to be used with the named screen template.- Angegeben von:
getScreenName
in SchnittstelleTemplateService
- Parameter:
template
- The screen template name.- Gibt zurück:
- The found screen module name.
- Löst aus:
Exception
- a generic exception.
-
getLayoutName
Locate and return the name of the layout module to be used with the named layout template.- Angegeben von:
getLayoutName
in SchnittstelleTemplateService
- Parameter:
template
- The layout template name.- Gibt zurück:
- The found layout module name.
- Löst aus:
Exception
- a generic exception.
-
getScreenTemplateName
Locate and return the name of the screen template corresponding to the given template name parameter. This might return null if the screen is not found!- Angegeben von:
getScreenTemplateName
in SchnittstelleTemplateService
- Parameter:
template
- The template name parameter.- Gibt zurück:
- The found screen template name.
- Löst aus:
Exception
- a generic exception.
-
getLayoutTemplateName
Locate and return the name of the layout template corresponding to the given screen template name parameter.- Angegeben von:
getLayoutTemplateName
in SchnittstelleTemplateService
- Parameter:
template
- The template name parameter.- Gibt zurück:
- The found screen template name.
- Löst aus:
Exception
- a generic exception.
-
translateTemplatePaths
Veraltet.Each template engine service should know how to translate a request onto a file.Translates the supplied template paths into their Turbine-canonical equivalent (probably absolute paths). This is used if the templating engine (e.g. JSP) does not provide any means to load a page but the page path is passed to the servlet container.- Angegeben von:
translateTemplatePaths
in SchnittstelleTemplateService
- Parameter:
templatePaths
- An array of template paths.- Gibt zurück:
- An array of translated template paths.
-
templateExists
Veraltet.Use templateExists from the various Templating EnginesDelegates to the appropriateTemplateEngineService
to check the existence of the specified template.- Angegeben von:
templateExists
in SchnittstelleTemplateService
- Parameter:
template
- The template to check for the existence of.templatePaths
- The paths to check for the template.- Gibt zurück:
- true if the given template exists
-
registerTemplateEngineService
Registers the provided template engine for use by theTemplateService
.- Angegeben von:
registerTemplateEngineService
in SchnittstelleTemplateService
- Parameter:
service
- TheTemplateEngineService
to register.
-
getTemplateEngineService
TheTemplateEngineService
associated with the specified template's file extension.- Angegeben von:
getTemplateEngineService
in SchnittstelleTemplateService
- Parameter:
template
- The template name.- Gibt zurück:
- The template engine service.
-