|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.ResourceTool
@DefaultKey(value="text") public class ResourceTool
Tool for accessing ResourceBundles and formatting messages therein.
Template example(s): $text.foo -> bar $text.hello.world -> Hello 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:
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.
Nested Class Summary | |
---|---|
class |
ResourceTool.Key
Internal class used to enable an elegant syntax for accessing resources. |
Field Summary | |
---|---|
private java.lang.String[] |
bundles
|
static java.lang.String |
BUNDLES_KEY
|
private boolean |
deprecationSupportMode
|
Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig |
---|
DEFAULT_LOCALE |
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig |
---|
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY |
Constructor Summary | |
---|---|
ResourceTool()
|
Method Summary | |
---|---|
ResourceTool.Key |
bundle(java.lang.String bundle)
|
protected void |
configure(ValueParser parser)
Does the actual configuration. |
ResourceTool.Key |
get(java.lang.Object k)
Accepts objects and uses their string value as the key. |
java.lang.Object |
get(java.lang.Object k,
java.lang.String[] bundles,
java.lang.Object l)
Retrieve a resource for the specified key from the first of the specified bundles in which a matching resource is found. |
java.lang.Object |
get(java.lang.Object k,
java.lang.String baseName,
java.lang.Object l)
Returns the value for the specified key in the ResourceBundle for the specified basename and locale. |
ResourceTool.Key |
get(java.lang.String key)
|
protected java.lang.String |
getDefaultBundle()
|
protected java.util.Locale |
getDefaultLocale()
Deprecated. |
ResourceTool.Key |
insert(java.util.List args)
|
ResourceTool.Key |
insert(java.lang.Object arg)
|
ResourceTool.Key |
insert(java.lang.Object[] args)
|
ResourceTool.Key |
insert(java.lang.Object arg0,
java.lang.Object arg1)
|
ResourceTool.Key |
locale(java.lang.Object locale)
|
java.lang.String |
render(java.lang.Object resource,
java.lang.Object[] args)
Renders the specified resource value and arguments as a String. |
protected void |
setDefaultBundle(java.lang.String bundle)
|
protected void |
setDefaultLocale(java.util.Locale locale)
Deprecated. |
void |
setDeprecationSupportMode(boolean depMode)
Deprecated. |
private java.util.Locale |
toLocale(java.lang.Object obj)
|
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig |
---|
getLocale, setLocale |
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig |
---|
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String BUNDLES_KEY
private java.lang.String[] bundles
private boolean deprecationSupportMode
Constructor Detail |
---|
public ResourceTool()
Method Detail |
---|
protected final void setDefaultBundle(java.lang.String bundle)
protected final java.lang.String getDefaultBundle()
@Deprecated protected final void setDefaultLocale(java.util.Locale locale)
@Deprecated protected final java.util.Locale getDefaultLocale()
@Deprecated public void setDeprecationSupportMode(boolean depMode)
protected void configure(ValueParser parser)
LocaleConfig
configure
in class LocaleConfig
public ResourceTool.Key get(java.lang.Object k)
public ResourceTool.Key get(java.lang.String key)
public ResourceTool.Key bundle(java.lang.String bundle)
public ResourceTool.Key locale(java.lang.Object locale)
public ResourceTool.Key insert(java.lang.Object[] args)
public ResourceTool.Key insert(java.util.List args)
public ResourceTool.Key insert(java.lang.Object arg)
public ResourceTool.Key insert(java.lang.Object arg0, java.lang.Object arg1)
public java.lang.Object get(java.lang.Object k, java.lang.String baseName, java.lang.Object l)
null
is returned.
k
- the key for the requested resourcebaseName
- the base name of the resource bundle to searchl
- the locale to usepublic java.lang.Object get(java.lang.Object k, java.lang.String[] bundles, java.lang.Object l)
null
will be returned.
k
- the key for the requested resourcebundles
- the resource bundles to searchl
- the locale to useprivate java.util.Locale toLocale(java.lang.Object obj)
public java.lang.String render(java.lang.Object resource, java.lang.Object[] args)
MessageFormat
pattern which
is used for formatting along with any specified argument values.
If deprecationSupportMode
is set to true, then this
will return the resource directly when there are no args (as it
did in 1.x versions).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |