|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.clazzes.util.aop.i18n.MessagesFactory
public abstract class MessagesFactory
A factory for Messages
, which eases the retrieval of
localized resources.
Field Summary | |
---|---|
static String |
SOURCE_LANGUAGE_PROPERTY
|
Constructor Summary | |
---|---|
MessagesFactory()
|
Method Summary | |
---|---|
protected static ResourceBundle |
loadResources(Locale locale,
ClassLoader cl,
String path)
|
static Messages |
newMessages(Locale locale,
Class<?> forClass)
Return a Messages instance by locale and a resource bundle
to be loaded from a properties file using the class loader and the
class name of the given class. |
static Messages |
newMessages(Locale locale,
ClassLoader classLoader,
String resourcePath)
Construct a Messages instance by locale and a resource bundle
to be loaded from a properties file from the resourcePath from the given class loader. |
static Messages |
newMessages(Locale locale,
PluralRule pr,
Class<?> forClass)
Return a Messages instance by locale, plural rule and a resource
bundle to be loaded from a properties file using the class loader and
the class name of the given class. |
static Messages |
newMessages(Locale locale,
PluralRule pr,
ClassLoader classLoader,
String resourcePath)
Construct a Messages instance by locale, plural rule and a resource bundle
to be loaded from a properties file from the resourcePath from the given class loader. |
static Messages |
newMessages(Locale locale,
PluralRule pr,
ResourceBundle resources)
Construct a Messages instance by locale, plural rule and a resource bundle. |
static Messages |
newMessages(Locale locale,
ResourceBundle resources)
Construct a Messages instance by locale,and a resource bundle. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String SOURCE_LANGUAGE_PROPERTY
Constructor Detail |
---|
public MessagesFactory()
Method Detail |
---|
protected static final ResourceBundle loadResources(Locale locale, ClassLoader cl, String path)
public static Messages newMessages(Locale locale, PluralRule pr, ResourceBundle resources)
Messages
instance by locale, plural rule and a resource bundle.
locale
- The locale to use.pr
- The plural rule to use.resources
- The resource bundle to load messages from.
Messages
instance.public static Messages newMessages(Locale locale, ResourceBundle resources)
Messages
instance by locale,and a resource bundle.
The plural rule is constructed using the default plural rule factory.
locale
- The locale to use.resources
- The resource bundle to load messages from.
Messages
instance.public static Messages newMessages(Locale locale, PluralRule pr, ClassLoader classLoader, String resourcePath)
Messages
instance by locale, plural rule and a resource bundle
to be loaded from a properties file from the resourcePath from the given class loader.
locale
- The locale to use.pr
- The plural rule to use.classLoader
- The class loader to load the resource bundle from.resourcePath
- A resource path specified as a dot-separated class name.
Messages
instance.public static Messages newMessages(Locale locale, ClassLoader classLoader, String resourcePath)
Construct a Messages
instance by locale and a resource bundle
to be loaded from a properties file from the resourcePath from the given class loader.
If the resource could no be found for the given language, the default properties
file without language extension will be loaded and the locale will be set to the
language contained in the "org.clazzes.util.aop.i18n.sourceLanguage" inside the fallback
resources. If no "org.clazzes.util.aop.i18n.sourceLanguage" could be found, the fallback
language is assumed to be Locale.ENGLISH
.
The plural rule is constructed using the default plural rule factory.
locale
- The locale to use.classLoader
- The class loader to load the resource bundle from.resourcePath
- A resource path specified as a dot-separated class name.
Messages
instance.public static Messages newMessages(Locale locale, PluralRule pr, Class<?> forClass)
Messages
instance by locale, plural rule and a resource
bundle to be loaded from a properties file using the class loader and
the class name of the given class.
locale
- The locale to use.pr
- The plural rule to use.forClass
- The class to use as the class loader and path hint.
Messages
instance.public static Messages newMessages(Locale locale, Class<?> forClass)
Return a Messages
instance by locale and a resource bundle
to be loaded from a properties file using the class loader and the
class name of the given class.
The plural rule is constructed using the default plural rule factory.
If the resource could no be found for the given language, the default properties
file without language extension will be loaded and the locale will be set to the
language contained in the "org.clazzes.util.aop.i18n.sourceLanguage" inside the fallback
resources. If no "org.clazzes.util.aop.i18n.sourceLanguage" could be found, the fallback
language is assumed to be Locale.ENGLISH
.
This method offers the most convenient way to load resources in an application by writing an accessor class
package org.my.pkg.i18n; abstract class MyMessages { public static final Messages getMesssages(Locale locale) { return MessagesFactory.newMessages(locale,MyMessages.class); }and placing your resources in files like:
org/my/pkg/i18n/MyMessages.properties org/my/pkg/i18n/MyMessages_de.properties org/my/pkg/i18n/MyMessages_fr.properties ...
locale
- The locale to use.forClass
- The class to use as the class loader and path hint.
Messages
instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |