eu.semaine.util
Class SEMAINEUtils

java.lang.Object
  extended by eu.semaine.util.SEMAINEUtils

public class SEMAINEUtils
extends java.lang.Object


Constructor Summary
SEMAINEUtils()
           
 
Method Summary
static java.io.File getConfigFile(java.lang.String configSystemProperty)
          Get a config file as defined in the given system property.
static java.lang.String getReaderAsString(java.io.Reader reader)
           
static java.lang.String getStreamAsString(java.io.InputStream inputStream, java.lang.String encoding)
           
static java.lang.String locale2xmllang(java.util.Locale locale)
          Convert a locale into a string that is conform with XML's xml:lang attribute.
static float parseFloat(java.lang.String valueString, float defaultValue)
          Convert the given string into a float value, if possible.
static java.util.Locale string2locale(java.lang.String localeString)
           
static java.util.Map<java.lang.String,java.lang.String> string2map(java.lang.String s, boolean keysFirst)
          For a given string containing lines of key-value pairs, construct a map of key-value pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SEMAINEUtils

public SEMAINEUtils()
Method Detail

getConfigFile

public static java.io.File getConfigFile(java.lang.String configSystemProperty)
Get a config file as defined in the given system property. If the setting in the system property is a relative path, then this path is interpreted as relative to the location of the system config file.

Parameters:
configSystemProperty - the name of a config setting containing the filename and path of the config file to load, e.g. "semaine.character-config".
Returns:
a file object representing the requested config file, or null if the config file could not be found.

getStreamAsString

public static java.lang.String getStreamAsString(java.io.InputStream inputStream,
                                                 java.lang.String encoding)
                                          throws java.io.IOException
Throws:
java.io.IOException

getReaderAsString

public static java.lang.String getReaderAsString(java.io.Reader reader)
                                          throws java.io.IOException
Throws:
java.io.IOException

string2locale

public static java.util.Locale string2locale(java.lang.String localeString)

locale2xmllang

public static java.lang.String locale2xmllang(java.util.Locale locale)
Convert a locale into a string that is conform with XML's xml:lang attribute. Basically it is language-COUNTRY, e.g. en-US.

Parameters:
locale - a locale, must not be null
Returns:
Throws:
java.lang.IllegalArgumentException - if locale is null

string2map

public static java.util.Map<java.lang.String,java.lang.String> string2map(java.lang.String s,
                                                                          boolean keysFirst)
For a given string containing lines of key-value pairs, construct a map of key-value pairs. This assumes that the String contains whitespace-separated key-value pairs as follows: key1 value1 key2 value2 Leading or trailing whitespace is ignored. If a line contains only a single field, it is treated as a key that maps to the empty string. Empty lines are ignored.

Parameters:
s -
keysFirst - if true, the first item in a line is the key, and the rest is the value; if false, the first item in the line is the value and the rest is the key.
Returns:

parseFloat

public static float parseFloat(java.lang.String valueString,
                               float defaultValue)
Convert the given string into a float value, if possible.

Parameters:
valueString - string to be converted into a float.
defaultValue - value to use if the string cannot be converted into a float.
Returns:
the best approximation that can be made for the float value given in valueString. If valueString cannot be converted into any float, returns defaultValue.