public class TurbineTemplateService extends TurbineBaseService implements 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.
Modifier and Type | Field and Description |
---|---|
static int |
LAYOUT_KEY
Represents Layout Objects
|
static int |
LAYOUT_TEMPLATE_KEY
Represents Layout Template Objects
|
static String |
LAYOUT_TEMPLATE_NAME
Represents Layout Template Objects
|
static int |
NAVIGATION_KEY
Represents Navigation Objects
|
static int |
NAVIGATION_TEMPLATE_KEY
Represents Navigation Template Objects
|
static String |
NAVIGATION_TEMPLATE_NAME
Represents Navigation Template Objects
|
protected static String |
NO_FILE_EXT
Deprecated.
Use TemplateService.DEFAULT_EXTENSION_VALUE.
|
static int |
PAGE_KEY
Represents Page Objects
|
static int |
SCREEN_KEY
Represents Screen Objects
|
static int |
SCREEN_TEMPLATE_KEY
Represents Screen Template Objects
|
static String |
SCREEN_TEMPLATE_NAME
Represents Screen Template Objects
|
static int |
TEMPLATE_TYPES
Number of different Template Types that we know of
|
configuration, name, serviceBroker
initableBroker, isInitialized
DEFAULT_EXTENSION_KEY, DEFAULT_EXTENSION_VALUE, DEFAULT_NAME, DEFAULT_TEMPLATE_KEY, DEFAULT_TEMPLATE_VALUE, EXTENSION_SEPARATOR, SERVICE_NAME, TEMPLATE_PARTS_SEPARATOR
Constructor and Description |
---|
TurbineTemplateService()
C'tor
|
Modifier and Type | Method and Description |
---|---|
String |
getDefaultExtension()
Get the default template name extension specified
in the template service properties.
|
String |
getDefaultLayout()
Get the default layout module name of the template engine
service corresponding to the default template name extension.
|
String |
getDefaultLayoutName(PipelineData pipelineData)
Find the default layout module name for the given request.
|
String |
getDefaultLayoutName(String template)
Get the default layout module name of the template engine
service corresponding to the template name extension of
the named template.
|
String |
getDefaultLayoutTemplate()
Get the default layout template name of the template engine
service corresponding to the default template name extension.
|
String |
getDefaultLayoutTemplateName(String template)
Get the default layout template name of the template engine
service corresponding to the template name extension of
the named template.
|
String |
getDefaultNavigation()
Get the default navigation module name of the template engine
service corresponding to the default template name extension.
|
String |
getDefaultNavigationName(String template)
Get the default navigation module name of the template engine
service corresponding to the template name extension of
the named template.
|
String |
getDefaultPage()
Get the default page module name of the template engine
service corresponding to the default template name extension.
|
String |
getDefaultPageName(PipelineData pipelineData)
Find the default page module name for the given request.
|
String |
getDefaultPageName(String template)
Get the default page module name of the template engine
service corresponding to the template name extension of
the named template.
|
String |
getDefaultScreen()
Get the default screen module name of the template engine
service corresponding to the default template name extension.
|
String |
getDefaultScreenName(String template)
Get the default screen module name of the template engine
service corresponding to the template name extension of
the named template.
|
String |
getDefaultTemplate()
Returns the Default Template Name with the Default Extension.
|
String |
getExtension(String template)
Return Extension for a supplied template
|
String |
getLayoutName(String template)
Locate and return the name of the layout module to be used
with the named layout template.
|
String |
getLayoutTemplateName(String template)
Locate and return the name of the layout template corresponding
to the given screen template name parameter.
|
String |
getNavigationName(String template)
Locate and return the name of the navigation module to be used
with the named navigation template.
|
String |
getNavigationTemplateName(String template)
Locate and return the name of the navigation template corresponding
to the given template name parameter.
|
String |
getScreenName(String template)
Locate and return the name of the screen module to be used
with the named screen template.
|
String |
getScreenTemplateName(String template)
Locate and return the name of the screen template corresponding
to the given template name parameter.
|
TemplateEngineService |
getTemplateEngineService(String template)
The
TemplateEngineService
associated with the specified template's file extension. |
void |
init()
Called the first time the Service is used.
|
boolean |
isCaching()
Returns true if the Template Service has caching activated
|
void |
registerTemplateEngineService(TemplateEngineService service)
Registers the provided template engine for use by the
TemplateService . |
boolean |
templateExists(String template,
String[] templatePaths)
Deprecated.
Use templateExists from the various Templating Engines
|
String[] |
translateTemplatePaths(String[] templatePaths)
Deprecated.
Each template engine service should know how to translate
a request onto a file.
|
init, init, shutdown
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
getInit, getInitableBroker, setInit, setInitableBroker
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConfiguration, getName, getProperties, setName, setServiceBroker
getInit, init, setInitableBroker, shutdown
public static final int PAGE_KEY
public static final int SCREEN_KEY
public static final int LAYOUT_KEY
public static final int NAVIGATION_KEY
public static final int LAYOUT_TEMPLATE_KEY
public static final String LAYOUT_TEMPLATE_NAME
public static final int SCREEN_TEMPLATE_KEY
public static final String SCREEN_TEMPLATE_NAME
public static final int NAVIGATION_TEMPLATE_KEY
public static final String NAVIGATION_TEMPLATE_NAME
public static final int TEMPLATE_TYPES
@Deprecated protected static final String NO_FILE_EXT
public TurbineTemplateService()
public void init() throws InitializationException
init
in interface Initable
init
in class TurbineBaseService
InitializationException
- Something went wrong when
setting up the Template Service.public boolean isCaching()
isCaching
in interface TemplateService
public String getDefaultExtension()
getDefaultExtension
in interface TemplateService
public String getExtension(String template)
getExtension
in interface TemplateService
template
- The template namepublic String getDefaultTemplate()
getDefaultTemplate
in interface TemplateService
public String getDefaultPage()
getDefaultPage
in interface TemplateService
public String getDefaultScreen()
getDefaultScreen
in interface TemplateService
public String getDefaultLayout()
getDefaultLayout
in interface TemplateService
public String getDefaultNavigation()
getDefaultNavigation
in interface TemplateService
public String getDefaultLayoutTemplate()
getDefaultLayoutTemplate
in interface TemplateService
public String getDefaultPageName(String template)
getDefaultPageName
in interface TemplateService
template
- The template name.public String getDefaultScreenName(String template)
getDefaultScreenName
in interface TemplateService
template
- The template name.public String getDefaultLayoutName(String template)
getDefaultLayoutName
in interface TemplateService
template
- The template name.public String getDefaultNavigationName(String template)
getDefaultNavigationName
in interface TemplateService
template
- The template name.public String getDefaultLayoutTemplateName(String template)
getDefaultLayoutTemplateName
in interface TemplateService
template
- The template name.public String getDefaultPageName(PipelineData pipelineData)
getDefaultPageName
in interface TemplateService
pipelineData
- The encapsulation of the request to retrieve the
default page for.public String getDefaultLayoutName(PipelineData pipelineData)
getDefaultLayoutName
in interface TemplateService
pipelineData
- The encapsulation of the request to retrieve the
default layout for.public String getScreenName(String template) throws Exception
getScreenName
in interface TemplateService
template
- The screen template name.Exception
- a generic exception.public String getLayoutName(String template) throws Exception
getLayoutName
in interface TemplateService
template
- The layout template name.Exception
- a generic exception.public String getNavigationName(String template) throws Exception
getNavigationName
in interface TemplateService
template
- The navigation template name.Exception
- a generic exception.public String getScreenTemplateName(String template) throws Exception
getScreenTemplateName
in interface TemplateService
template
- The template name parameter.Exception
- a generic exception.public String getLayoutTemplateName(String template) throws Exception
getLayoutTemplateName
in interface TemplateService
template
- The template name parameter.Exception
- a generic exception.public String getNavigationTemplateName(String template) throws Exception
getNavigationTemplateName
in interface TemplateService
template
- The template name parameter.Exception
- a generic exception.@Deprecated public String[] translateTemplatePaths(String[] templatePaths)
translateTemplatePaths
in interface TemplateService
templatePaths
- An array of template paths.@Deprecated public boolean templateExists(String template, String[] templatePaths)
TemplateEngineService
to
check the existence of the specified template.templateExists
in interface TemplateService
template
- The template to check for the existence of.templatePaths
- The paths to check for the template.public void registerTemplateEngineService(TemplateEngineService service)
TemplateService
.registerTemplateEngineService
in interface TemplateService
service
- The TemplateEngineService
to register.public TemplateEngineService getTemplateEngineService(String template)
TemplateEngineService
associated with the specified template's file extension.getTemplateEngineService
in interface TemplateService
template
- The template name.Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.