com.github.fge.msgsimple.bundle
Class PropertiesBundle

java.lang.Object
  extended by com.github.fge.msgsimple.bundle.PropertiesBundle

public final class PropertiesBundle
extends Object

Utility class to instantiate message bundles from Java property files

This is the class you will use if you want to load a legay ResourceBundle (using legacyResourceBundle(String)). However, if you are starting a new bundle, it is recommended to use the other methods.

The generic method is forPath(String, Charset, long, TimeUnit). You can therefore specify the character set and timeout. When no character set is specified, the default is UTF-8, except for legacyResourceBundle(String) which will read property files as ResourceBundle does: in ISO-8859-1.

All constructors have a resourcePath argument; in the same vein as ResourceBundle, the following inputs are allowed:

See Also:
MessageBundle, PropertiesMessageSource, MessageSourceLoader, LoadingMessageSourceProvider

Method Summary
static MessageBundle forPath(String resourcePath)
          Create a message bundle from a set of property files, using the UTF-8 character set
static MessageBundle forPath(String resourcePath, Charset charset, long duration, TimeUnit unit)
          Create a message bundle from a set of property files, with a defined charset and expiry time
static MessageBundle forPath(String resourcePath, long duration, TimeUnit timeUnit)
          Create a message bundle from a set of property files, using the UTF-8 character set, and an expiry delay
static MessageBundle legacyResourceBundle(String resourcePath)
          Create a message bundle mimicking a ResourceBundle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

forPath

public static MessageBundle forPath(String resourcePath)
Create a message bundle from a set of property files, using the UTF-8 character set

Parameters:
resourcePath - the resource path
Returns:
a MessageBundle
Throws:
NullPointerException - resource path is null

forPath

public static MessageBundle forPath(String resourcePath,
                                    long duration,
                                    TimeUnit timeUnit)
Create a message bundle from a set of property files, using the UTF-8 character set, and an expiry delay

Parameters:
resourcePath - the resource path
duration - expiry duration
timeUnit - expiry time unit
Returns:
a MessageBundle
Throws:
NullPointerException - resource path or duration is null
IllegalArgumentException - duration is 0 or less
Since:
0.5
See Also:
LoadingMessageSourceProvider

forPath

public static MessageBundle forPath(String resourcePath,
                                    Charset charset,
                                    long duration,
                                    TimeUnit unit)
Create a message bundle from a set of property files, with a defined charset and expiry time

Parameters:
resourcePath - the resource path
charset - the character set
duration - expiry duration
unit - expiry time unit
Returns:
a MessageBundle
Throws:
NullPointerException - resource path, charset or duration is null
IllegalArgumentException - duration is 0 or less
Since:
0.5
See Also:
LoadingMessageSourceProvider

legacyResourceBundle

public static MessageBundle legacyResourceBundle(String resourcePath)
Create a message bundle mimicking a ResourceBundle

Using this method will provide a MessageBundle with the following characteristics:

This method is only there for legacy reasons. Ultimately, you should choose to use a more modern (ie, UTF-8) message bundle instead.

Parameters:
resourcePath - the resource path
Returns:
the matching bundle
See Also:
PropertiesMessageSource.fromResource(String, Charset)