Class Labels
Specify the library property of org.zkoss.util.resource.LabelLoader.class
in zk.xml to provide a customized label loader for debugging purpose. (since 7.0.1)
- Author:
- tomyeh
-
Method Summary
Modifier and TypeMethodDescriptionstatic final StringReturns the label of the specified key based on the current Locale, or null if no found.static final StringReturns the label of the specified key and formats it with the specified argument, or null if not found.static final StringReturns the label of the specified key based on the current Locale, or the default value if no found.static final StringReturns the label of the specified key and formats it with the specified argument, or the default value if not found.static final StringgetRequiredLabel(String key) Returns the label of the specified key based on the current locale.static final StringgetRequiredLabel(String key, Object[] args) Returns the label of the specified key and formats it with the specified argument, or null if not found.Returns the label or a map of labels associated with the key.static final voidregister(LabelLocator locator) Registers a locator which is used to load the Locale-dependent labels from other resource, such as servlet contexts.static final voidregister(LabelLocator2 locator) Registers a locator which is used to load the Locale-dependent labels from other resource, such as database.static final voidreset()Resets all cached labels and next call togetLabel(String)will cause re-loading the Locale dependent files.static final VariableResolversetVariableResolver(VariableResolver resolv) Sets the variable resolver, which is used if an EL expression is specified.
-
Method Details
-
getLabel
Returns the label of the specified key based on the current Locale, or null if no found.The current locale is given by
Locales.getCurrent().- See Also:
-
getLabel
Returns the label of the specified key and formats it with the specified argument, or null if not found.It first uses
getLabel(String)to load the label. Then, it, if not null, invokesMessageFormats.format(java.lang.String, java.lang.Object[], java.util.Locale)to format it.The current locale is given by
Locales.getCurrent().- Since:
- 3.0.6
-
getLabel
Returns the label of the specified key based on the current Locale, or the default value if no found.The current locale is given by
Locales.getCurrent().- Parameters:
defValue- the value being returned if the key is not found- Since:
- 3.6.0
-
getLabel
Returns the label of the specified key and formats it with the specified argument, or the default value if not found.It first uses
getLabel(String, String)to load the label. Then, it, if not null, invokesMessageFormats.format(java.lang.String, java.lang.Object[], java.util.Locale)to format it.The current locale is given by
Locales.getCurrent().- Parameters:
defValue- the value being returned if the key is not found- Since:
- 3.6.0
-
getSegmentedLabels
Returns the label or a map of labels associated with the key. UnlikegetLabel(java.lang.String), if a key of the label contains dot, it will be split into multiple keys and then grouped into map. For example, the following property file will parsed into a couple of maps, andgetSegmentedLabels()returns a map containing a single entry. The entry's key is"a"and the value is another map with two entries"b"and"c". And, the value for"b"is another two-entries map (containing"c"and"d").a.b.c=1 a.b.d=2 a.e=3This method is designed to make labels easier to be accessed in EL expressions.
On the other hand,
getLabel(java.lang.String)does not split them, and you could access them by, say,getLabel("a.b.d").- Since:
- 5.0.7
-
getRequiredLabel
Returns the label of the specified key based on the current locale. UnlikegetLabel(String), it throws an exception if not found.- Throws:
SystemException- if no such label- Since:
- 3.0.6
-
getRequiredLabel
Returns the label of the specified key and formats it with the specified argument, or null if not found. UnlikegetLabel(String, Object[]), it throws an exception if not found.The current locale is given by
Locales.getCurrent().- Throws:
SystemException- if no such label- Since:
- 3.0.6
-
reset
public static final void reset()Resets all cached labels and next call togetLabel(String)will cause re-loading the Locale dependent files. -
setVariableResolver
Sets the variable resolver, which is used if an EL expression is specified.Default: no resolver at all.
- Returns:
- the previous resolver, or null if no resolver.
-
register
Registers a locator which is used to load the Locale-dependent labels from other resource, such as servlet contexts. -
register
Registers a locator which is used to load the Locale-dependent labels from other resource, such as database.- Since:
- 5.0.5
-