@DefaultKey(value="include") @InvalidScope(value="application") public class IncludeTool extends SafeConfig implements Serializable
Reads the default language out of the ViewToolContext as
org.apache.velocity.tools.view.i18n.defaultLanguage
.
See find(String, String)
, find(String, Locale)
and exists(String)
for usage.
This is the successor to the MultiViewsTool in VelocityTools 1.x. Please note that it does NOT do the actual #include or #parse for you, but is merely to aid in include content negotiation.
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_LANGUAGE_KEY
The key used to search initialization, context, and JVM
parameters for the default language to use.
|
protected String |
defaultLanguage
The two character abbreviation for the request's default
language.
|
protected org.apache.velocity.app.VelocityEngine |
engine |
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
Constructor and Description |
---|
IncludeTool() |
Modifier and Type | Method and Description |
---|---|
protected void |
configure(ValueParser params)
Extracts the default language from the specified
ViewContext , looking first at the Velocity
context, then the servlet context, then lastly at the JVM
default. |
protected void |
configure(ViewToolContext ctx) |
boolean |
exists(String name)
Checks to see whether a #parse-able template or
#include-able resource exists under the specified name/path.
|
boolean |
exists(String name,
String language)
Checks to see whether a localized version of the
named template exists for the specified language.
|
String |
find(String name)
Calls
find(String, String) using the
default language. |
String |
find(String name,
Locale locale)
Calls
find(String, String) using the
language extracted from locale . |
String |
find(String name,
String language)
Finds the a localized version of the requested Velocity
resource (such as a file or template) which is most appropriate
for the locale of the current request.
|
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
protected static final String DEFAULT_LANGUAGE_KEY
protected String defaultLanguage
protected org.apache.velocity.app.VelocityEngine engine
protected void configure(ValueParser params)
ViewContext
, looking first at the Velocity
context, then the servlet context, then lastly at the JVM
default. This "narrow scope to wide scope" pattern makes it
easy to setup language overrides at different levels within
your application.configure
in class SafeConfig
params
- the Map
of configuration parametersIllegalArgumentException
- if the param is not a ViewContextprotected void configure(ViewToolContext ctx)
public String find(String name, Locale locale)
find(String, String)
using the
language extracted from locale
.name
- resource filenamelocale
- localefind(String, String)
public String find(String name)
find(String, String)
using the
default language.name
- resource filenamefind(String, String)
public String find(String name, String language)
Finds the a localized version of the requested Velocity
resource (such as a file or template) which is most appropriate
for the locale of the current request. Use in conjuction with
Apache httpd's MultiViews
, or by itself.
Usage from a template would be something like the following:
#parse( $include.find('header.vm', 'en') )
#include( $include.find('my_page.html', 'en') )
#parse( $include.find('footer.vm', 'en') )
You might also wrap this method using another pull/view tool which does internationalization/localization/content negation for a single point of access.
name
- The unlocalized name of the file to find.language
- The language to find localized context for.name
if it is
not localizable.public boolean exists(String name)
Checks to see whether a #parse-able template or #include-able resource exists under the specified name/path.
Usage from a template would be something like the following:
#if( $include.exists('header.vm') ) #parse( 'header.vm' ) #end
name
- resource filenameVelocityEngine.resourceExists(java.lang.String)
public boolean exists(String name, String language)
name
- resource filenamelanguage
- asked languageexists(String)
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.