|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xnap.commons.i18n.I18nFactory
public class I18nFactory
Factory class that creates and caches I18n instances.
Given a Class
object the factory looks up the resource bundle
responsible for handling message translations. The bundle is returned with an
I18n
object wrapped around it, which provides the translation
methods. The lookup is described at getI18n(Class,String)
.
Use the factory for creating I18n
objects to make sure no
extraneous objects are created.
Field Summary | |
---|---|
static int |
DEFAULT
Use the default configuration. |
static String |
DEFAULT_BASE_NAME
Default name for Message bundles, is "i18n.Messages". |
static int |
FALLBACK
Fall back to a default resource bundle that returns the passed text if no resource bundle can be located. |
static int |
NO_CACHE
Do not cache I18n instance. |
static String |
PROPS_FILENAME
Filename of the properties file that contains the i18n properties, is "i18n.properties". |
static int |
READ_PROPERTIES
Look for files named PROPS_FILENAME to determine the basename. |
Method Summary | |
---|---|
static I18n |
getI18n(Class clazz)
Calls getI18n(clazz, Locale.getDefault()) . |
static I18n |
getI18n(Class clazz,
Locale locale)
Calls getI18n(clazz, locale,
READ_PROPERTIES) . |
static I18n |
getI18n(Class clazz,
Locale locale,
int flags)
Returns the I18n instance responsible for translating messages in the package specified by clazz . |
static I18n |
getI18n(Class clazz,
String bundleName)
Calls getI18n(clazz, bundleName, Locale.getDefault()) . |
static I18n |
getI18n(Class clazz,
String bundleName,
Locale locale)
Calls getI18n(clazz, bundleName, locale, DEFAULT) . |
static I18n |
getI18n(Class clazz,
String bundleName,
Locale locale,
int flags)
Calls getI18n(getPackageName(clazz), bundleName, clazz.getClassLoader(), locale, DEFAULT) . |
static I18n |
getI18n(String path,
String bundleName,
ClassLoader classLoader,
Locale locale,
int flags)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT
public static final int FALLBACK
public static final int READ_PROPERTIES
PROPS_FILENAME
to determine the basename.
public static final int NO_CACHE
I18n
instance.
public static final String DEFAULT_BASE_NAME
public static final String PROPS_FILENAME
Method Detail |
---|
public static I18n getI18n(Class clazz)
getI18n(clazz, Locale.getDefault())
.
public static I18n getI18n(Class clazz, Locale locale)
getI18n(clazz, locale,
READ_PROPERTIES)
.
public static I18n getI18n(Class clazz, Locale locale, int flags)
clazz
.
Lookup works by iterating upwards in the package hierarchy: First the
internal cache is asked for an I18n object for a package, otherwise the
algorithm looks for an i18n.properties
file in the
package. The properties file is queried for a key named
basename
whose value should be the fully qualified
resource/class name of the resource bundle, e.g
org.xnap.commons.i18n.Messages
.
If after the first iteration no I18n instance has been found, a second
search begins by looking for resource bundles having the name
baseName
.
clazz
- the package hierarchy of the clazz and its class loader are
used for resolving and loading the resource bundlebaseName
- the name of the underlying resource bundlelocale
- the locale of the underlying resource bundleflags
- a combination of these configuration flags: FALLBACK
I18n
instance
MissingResourceException
- if no resource bundle was foundpublic static I18n getI18n(Class clazz, String bundleName)
getI18n(clazz, bundleName, Locale.getDefault())
.
public static I18n getI18n(Class clazz, String bundleName, Locale locale)
getI18n(clazz, bundleName, locale, DEFAULT)
.
public static I18n getI18n(Class clazz, String bundleName, Locale locale, int flags)
getI18n(getPackageName(clazz), bundleName, clazz.getClassLoader(), locale, DEFAULT)
.
public static I18n getI18n(String path, String bundleName, ClassLoader classLoader, Locale locale, int flags)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |