类 IncludeTool
- 所有已实现的接口:
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.
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Id$
- 作者:
- Daniel Rall, Nathan Bubna
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明protected static final StringThe key used to search initialization, context, and JVM parameters for the default language to use.protected StringThe two character abbreviation for the request's default language.protected org.apache.velocity.app.VelocityEngine从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigure(ValueParser params) Extracts the default language from the specifiedViewContext, looking first at the Velocity context, then the servlet context, then lastly at the JVM default.protected voidconfigure(ViewToolContext ctx) booleanChecks to see whether a #parse-able template or #include-able resource exists under the specified name/path.booleanChecks to see whether a localized version of the named template exists for the specified language.Callsfind(String, String)using the default 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.Callsfind(String, String)using the language extracted fromlocale.从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
DEFAULT_LANGUAGE_KEY
The key used to search initialization, context, and JVM parameters for the default language to use.- 另请参阅:
-
defaultLanguage
The two character abbreviation for the request's default language. -
engine
protected org.apache.velocity.app.VelocityEngine engine
-
-
构造器详细资料
-
IncludeTool
public IncludeTool()
-
-
方法详细资料
-
configure
Extracts the default language from the specifiedViewContext, 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在类中SafeConfig- 参数:
params- theMapof configuration parameters- 抛出:
IllegalArgumentException- if the param is not a ViewContext
-
configure
-
find
Callsfind(String, String)using the language extracted fromlocale.- 参数:
name- resource filenamelocale- locale- 返回:
- locallized resource filename
- 另请参阅:
-
find
Callsfind(String, String)using the default language.- 参数:
name- resource filename- 返回:
- locallized resource filename
- 另请参阅:
-
find
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.- 返回:
- The localized file name, or
nameif it is not localizable.
-
exists
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 filename- 返回:
- whether resource exists
- 另请参阅:
-
VelocityEngine.resourceExists(java.lang.String)
-
exists
Checks to see whether a localized version of the named template exists for the specified language.- 参数:
name- resource filenamelanguage- asked language- 返回:
- whether resource exists
- 另请参阅:
-