com.github.fge.msgsimple.source
Class PropertiesMessageSource

java.lang.Object
  extended by com.github.fge.msgsimple.source.PropertiesMessageSource
All Implemented Interfaces:
MessageSource

public final class PropertiesMessageSource
extends Object
implements MessageSource

A message source built from a properties files

You can load property files from the classpath or from files on your filesystem. You can also specify the character set used to read the file; methods without a character set as an argument use UTF-8.

See Also:
Properties.load(Reader)

Method Summary
static MessageSource fromFile(File file)
          Create a message source from a properties file on the filesystem using UTF-8
static MessageSource fromFile(File file, Charset charset)
          Create a message source from a properties file on the filesystem using the specified charset
static MessageSource fromPath(String path)
          Create a message source from a properties file on the filesystem using the specified encoding
static MessageSource fromPath(String path, Charset charset)
          Create a message source from a properties file on the filesystem using the specified charset
static MessageSource fromResource(String resourcePath)
          Create a message source from a classpath resource using UTF-8
static MessageSource fromResource(String resourcePath, Charset charset)
          Create a message source from a classpath resource using the specified charset
 String getKey(String key)
          Return a message matching a given key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fromResource

public static MessageSource fromResource(String resourcePath)
                                  throws IOException
Create a message source from a classpath resource using UTF-8

Parameters:
resourcePath - the path to the properties file
Returns:
a newly created source
Throws:
NullPointerException - resource path is null
IOException - no such resource, or an I/O error occurred while reading the file

fromResource

public static MessageSource fromResource(String resourcePath,
                                         Charset charset)
                                  throws IOException
Create a message source from a classpath resource using the specified charset

Parameters:
resourcePath - the path to the properties file
charset - the character set to use
Returns:
a newly created source
Throws:
NullPointerException - resource path is null
IOException - no such resource, or an I/O error occurred while reading the file
Since:
0.5

fromFile

public static MessageSource fromFile(File file)
                              throws IOException
Create a message source from a properties file on the filesystem using UTF-8

Parameters:
file - the file to read from
Returns:
a newly created message source
Throws:
NullPointerException - file is null
FileNotFoundException - file does not exist, or cannot access file
IOException - failed to read from file

fromPath

public static MessageSource fromPath(String path)
                              throws IOException
Create a message source from a properties file on the filesystem using the specified encoding

This essentially calls fromFile(File).

Parameters:
path - the file path
Returns:
a newly created message source
Throws:
NullPointerException - path is null
IOException - see fromFile(File)
Since:
0.5

fromFile

public static MessageSource fromFile(File file,
                                     Charset charset)
                              throws IOException
Create a message source from a properties file on the filesystem using the specified charset

Parameters:
file - the file to read from
charset - the character set to use
Returns:
a newly created message source
Throws:
NullPointerException - file is null
FileNotFoundException - file does not exist, or cannot access file
IOException - failed to read from file
Since:
0.5

fromPath

public static MessageSource fromPath(String path,
                                     Charset charset)
                              throws IOException
Create a message source from a properties file on the filesystem using the specified charset

This essentially calls fromFile(File, Charset).

Parameters:
path - the file path
charset - the character set
Returns:
a newly created message source
Throws:
NullPointerException - path is null
IOException - see fromFile(File)
Since:
0.5

getKey

public String getKey(String key)
Description copied from interface: MessageSource
Return a message matching a given key

Note that this method MUST return null if there is no match for the given key.

Note also that it is guaranteed that you will never get a null key.

Specified by:
getKey in interface MessageSource
Parameters:
key - the key
Returns:
see description