类 ResourceTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.ResourceTool
- 所有已实现的接口:
Serializable
Tool for accessing ResourceBundles and formatting messages therein.
Template example(s):
$text.foo -> bar
$text.hello.world -> Hello World!
$text.keys -> [foo, hello.world, world]
#set( $otherText = $text.bundle('otherBundle') )
$otherText.foo -> woogie
$otherText.bar -> The args are {0} and {1}.
$otherText.bar.insert(4) -> The args are 4 and {1}.
$otherText.bar.insert(4,true) -> The args are 4 and true.
Toolbox configuration example:
<tools>
<toolbox scope="request">
<tool class="org.apache.velocity.tools.generic.ResourceTool"
bundles="resources,com.foo.moreResources"
locale="en_US"/>
</toolbox>
</tools>
This comes in very handy when internationalizing templates. Note that the default resource bundle baseName is "resources", and the default locale is either:
- the result of HttpServletRequest.getLocale() (if used in request scope of a VelocityView app)
- the configured locale for this tool (as shown above)
- the configured locale for the toolbox this tool is in
- the configured locale for the toolbox factory managing this tool
- the system locale, if none of the above
Also, be aware that very few performance considerations have been made in this initial version. It should do fine, but if you have performance issues, please report them to dev@velocity.apache.org, so we can make improvements.
- 从以下版本开始:
- VelocityTools 1.3
- 版本:
- $Revision$ $Date: 2006-11-27 10:49:37 -0800 (Mon, 27 Nov 2006) $
- 作者:
- Nathan Bubna
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明final classInternal class used to enable an elegant syntax for accessing resources. -
字段概要
字段从类继承的字段 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigure(ValueParser parser) Does the actual configuration.Accepts objects and uses their string value as the key.Retrieve a resource for the specified key from the first of the specified bundles in which a matching resource is found.Returns the value for the specified key in the ResourceBundle for the specified basename and locale.Accepts objects and uses their string value as the key.protected ResourceBundleRetrieves theResourceBundlefor the specified baseName and locale, if such exists.protected final StringgetKeys()Lists available keysReturns aListof the key strings in the specified ResourceBundles.Returns aListof the key strings in the ResourceBundle with the specified baseName and locale.Renders the specified resource value and arguments as a String.protected final voidsetDefaultBundle(String bundle) 从类继承的方法 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocale从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
BUNDLES_KEY
- 另请参阅:
-
-
构造器详细资料
-
ResourceTool
public ResourceTool()
-
-
方法详细资料
-
setDefaultBundle
-
getDefaultBundle
-
configure
从类复制的说明:LocaleConfigDoes the actual configuration. This is protected, so subclasses may share the same ValueParser and call configure at any time, while preventing templates from doing so when configure(Map) is locked.- 覆盖:
configure在类中LocaleConfig- 参数:
parser- configuration values
-
get
Accepts objects and uses their string value as the key.- 参数:
k- key- 返回:
- Key object
-
get
Accepts objects and uses their string value as the key.- 参数:
key- key- 返回:
- Key object
-
getKeys
Lists available keys- 返回:
- keys list
-
bundle
-
locale
-
insert
-
insert
-
insert
-
insert
-
getBundle
Retrieves theResourceBundlefor the specified baseName and locale, if such exists. If the baseName or locale is null or if the locale argument cannot be converted to aLocale, then this will return null.- 参数:
baseName- base nameloc- locale- 返回:
- resource bundle
-
get
Returns the value for the specified key in the ResourceBundle for the specified basename and locale. If no such resource can be found, no errors are thrown andnullis returned.- 参数:
key- the key for the requested resourcebaseName- the base name of the resource bundle to searchloc- the locale to use- 返回:
- value
-
get
Retrieve a resource for the specified key from the first of the specified bundles in which a matching resource is found. If no resource is found, no exception will be thrown andnullwill be returned.- 参数:
k- the key for the requested resourcebundles- the resource bundles to searchl- the locale to use- 返回:
- value
-
getKeys
Returns aListof the key strings in the ResourceBundle with the specified baseName and locale. If the specified prefix is not null, then this will skip any keys that do not begin with that prefix and trim the prefix and any subsequent '.' off of the remaining ones. If the prefix is null, then no filtering or trimming will be done.- 参数:
prefix- the prefix for the requested keysbaseName- the resource bundle base nameloc- the locale to use- 返回:
- keys list
-
getKeys
Returns aListof the key strings in the specified ResourceBundles. If the specified prefix is not null, then this will skip any keys that do not begin with that prefix and trim the prefix and any subsequent '.' off of the remaining ones. If the prefix is null, then no filtering or trimming will be done.- 参数:
prefix- the prefix for the requested keysbundles- the resource bundles to searchloc- the locale to use- 返回:
- keys list
- 另请参阅:
-
render
Renders the specified resource value and arguments as a String. The resource is treated as aMessageFormatpattern which is used for formatting along with any specified argument values.- 参数:
resource- resource objectargs- arguments- 返回:
- formatted string
-