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
FelderModifizierer und TypFeldBeschreibungstatic final intRepresents Layout Objectsstatic final intRepresents Layout Template Objectsstatic final StringRepresents Layout Template Objectsstatic final intRepresents Navigation Objectsstatic final intRepresents Navigation Template Objectsstatic final StringRepresents Navigation Template Objectsprotected static final StringVeraltet.Use TemplateService.DEFAULT_EXTENSION_VALUE.static final intRepresents Page Objectsstatic final intRepresents Screen Objectsstatic final intRepresents Screen Template Objectsstatic final StringRepresents Screen Template Objectsstatic final intNumber of different Template Types that we know ofVon Klasse geerbte Felder org.apache.turbine.services.BaseService
configuration, name, serviceBrokerVon Klasse geerbte Felder org.apache.turbine.services.BaseInitable
initableBroker, isInitializedVon Schnittstelle geerbte Felder org.apache.turbine.services.Service
SERVICE_NAMEVon 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
Konstruktoren -
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) TheTemplateEngineServiceassociated with the specified template's file extension.voidinit()Called the first time the Service is used.booleanReturns true if the Template Service has caching activatedvoidRegisters the provided template engine for use by theTemplateService.booleantemplateExists(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, shutdownVon Klasse geerbte Methoden org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBrokerVon Klasse geerbte Methoden org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBrokerVon Klasse geerbte Methoden java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitVon Schnittstelle geerbte Methoden org.apache.turbine.services.Initable
getInit, init, setInitableBroker, shutdownVon 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:
initin SchnittstelleInitable- Setzt außer Kraft:
initin 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:
isCachingin 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:
getDefaultExtensionin SchnittstelleTemplateService- Gibt zurück:
- The default extension.
-
getExtension
Return Extension for a supplied template- Angegeben von:
getExtensionin 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:
getDefaultTemplatein 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:
getDefaultPagein 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:
getDefaultScreenin 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:
getDefaultLayoutin 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:
getDefaultLayoutTemplatein 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:
getDefaultPageNamein 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:
getDefaultScreenNamein 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:
getDefaultLayoutNamein 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:
getDefaultLayoutTemplateNamein 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:
getDefaultPageNamein 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:
getDefaultLayoutNamein 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:
getScreenNamein 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:
getLayoutNamein 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:
getScreenTemplateNamein 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:
getLayoutTemplateNamein 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:
translateTemplatePathsin 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 appropriateTemplateEngineServiceto check the existence of the specified template.- Angegeben von:
templateExistsin 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:
registerTemplateEngineServicein SchnittstelleTemplateService- Parameter:
service- TheTemplateEngineServiceto register.
-
getTemplateEngineService
TheTemplateEngineServiceassociated with the specified template's file extension.- Angegeben von:
getTemplateEngineServicein SchnittstelleTemplateService- Parameter:
template- The template name.- Gibt zurück:
- The template engine service.
-