simtools.ui
Class UserProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by simtools.ui.UserProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class UserProperties
extends java.util.Properties

This class returns a user preferences as saved at previous use of the tool

Author:
N. Brodu, C. Cazenave, A. Reglat
See Also:
Serialized Form

Nested Class Summary
protected static class UserProperties.Info
          The information class
 
Field Summary
protected  java.io.File _file
          The file to read and write properties to
protected  java.util.LinkedList _infoList
          List of informations to write sorted properties in file.
protected  java.lang.String _productName
          The product name to apply properties to
protected  boolean _propertiesLoadedFromFile
           
protected static char[] hexDigit
          A table of hex digits
protected static java.lang.String keyValueSeparators
           
protected static java.lang.String specialSaveChars
           
protected static java.lang.String strictKeyValueSeparators
           
protected static java.lang.String whiteSpaceChars
           
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
UserProperties(java.io.File propertyFile)
          Contructor UserProperties
Summary:
The constructor of the class UserProperties.
UserProperties(java.lang.String productName)
          Creates user properties without reading values from the file.
UserProperties(java.lang.String productName, boolean useSystemDefaultValues)
          Creates user properties without reading values from the file.
 
Method Summary
 void addComment(java.lang.String comment)
          Add a comment at the end of the properties sequence.
 void addNewLine()
          Add a new empty line at the end of the properties sequence.
protected  boolean continueLine(java.lang.String line)
           
 boolean getBoolean(java.lang.String name, boolean value)
          Gets a boolean
 byte getByte(java.lang.String name, byte value)
          Gets a byte
 double getDouble(java.lang.String name, double value)
          Gets a double
 java.io.File getFile()
           
 float getFloat(java.lang.String name, float value)
          Gets a float
 int getInt(java.lang.String name, int value)
          Gets an int
 long getLong(java.lang.String name, long value)
          Gets a long
 java.lang.String getProperty(java.lang.String key)
          Method getProperty
Summary:
Use this method to get a property.
 short getShort(java.lang.String name, short value)
          Gets a short
 java.lang.String getString(java.lang.String name, java.lang.String value)
          Gets a string
 void load(java.io.InputStream inStream)
          Reads a property sequence from the input stream.
protected  java.lang.String loadConvert(java.lang.String theString)
           
 void read()
          Reads properties from the file defined in the constructor.
 void read2()
          Reads properties from the file defined in the constructor.
protected  java.lang.String saveConvert(java.lang.String theString, boolean escapeSpace)
           
 void setBoolean(java.lang.String name, boolean value)
          Sets a boolean
 void setByte(java.lang.String name, byte value)
          Sets a byte
 void setDouble(java.lang.String name, double value)
          Sets a double
 void setFloat(java.lang.String name, float value)
          Sets a float
 void setInt(java.lang.String name, int value)
          Sets an int
 void setLong(java.lang.String name, long value)
          Sets a long
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          Calls the Hashtable method put.
 void setShort(java.lang.String name, short value)
          Sets a short
 void setString(java.lang.String name, java.lang.String value)
          Sets a string
 void store(java.io.OutputStream out, java.lang.String header)
          Writes a property sequence in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method.
protected static char toHex(int nibble)
          Convert a nibble to a hex character
 void write()
          Writes properties to the file defined in the constructor.
 void write2()
          Writes properties to the file defined in the constructor.
 
Methods inherited from class java.util.Properties
getProperty, list, list, load, loadFromXML, propertyNames, save, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_file

protected java.io.File _file
The file to read and write properties to


_productName

protected java.lang.String _productName
The product name to apply properties to


_infoList

protected java.util.LinkedList _infoList
List of informations to write sorted properties in file.


_propertiesLoadedFromFile

protected boolean _propertiesLoadedFromFile

keyValueSeparators

protected static final java.lang.String keyValueSeparators
See Also:
Constant Field Values

strictKeyValueSeparators

protected static final java.lang.String strictKeyValueSeparators
See Also:
Constant Field Values

specialSaveChars

protected static final java.lang.String specialSaveChars
See Also:
Constant Field Values

whiteSpaceChars

protected static final java.lang.String whiteSpaceChars
See Also:
Constant Field Values

hexDigit

protected static final char[] hexDigit
A table of hex digits

Constructor Detail

UserProperties

public UserProperties(java.lang.String productName)
Creates user properties without reading values from the file. If system property productName + ".home" is set then look for properties file into this directory, else merely use the user home directory. Unlike the Properties class, there is no property list for default values.

Parameters:
productName - the product name

UserProperties

public UserProperties(java.lang.String productName,
                      boolean useSystemDefaultValues)
Creates user properties without reading values from the file. If system property productName + ".home" is set then look for properties file into this directory, else merely use the user home directory. Unlike the Properties class, there is no property list for default values.

Parameters:
productName - the product name
useSystemDefaultValues - true to use system properties defined with -Dproperty=value at launch time. These default values are used only when a property is not defined in user property file.

UserProperties

public UserProperties(java.io.File propertyFile)
Contructor UserProperties
Summary:
The constructor of the class UserProperties. Creates user properties without reading values from the file. If system property productName + ".home" is set then look for properties file into this directory, else merely use the user home directory. Unlike the Properties class, there is no property list for default values.

Parameters:
propertyFile - The file that contains the properties to be loaded.
Method Detail

getFile

public java.io.File getFile()

read

public void read()
Reads properties from the file defined in the constructor. In case of error, default values will be used


write

public void write()
Writes properties to the file defined in the constructor. In case of error, nothing happens


read2

public void read2()
           throws java.io.FileNotFoundException,
                  java.io.IOException
Reads properties from the file defined in the constructor.

Throws:
java.io.FileNotFoundException
java.io.IOException

getProperty

public java.lang.String getProperty(java.lang.String key)
Method getProperty
Summary:
Use this method to get a property. Use the override order: MasterFiles < local property < System property. Means that: if a property is defined in local and in on of a master property file, the local one will be returned. If defined in local and in system property, system property will be returned. If the property cannot be found, return null. Parameters:

Overrides:
getProperty in class java.util.Properties
Parameters:
key - The key of the property to find, or null if not found.

write2

public void write2()
            throws java.io.FileNotFoundException,
                   java.io.IOException
Writes properties to the file defined in the constructor.

Throws:
java.io.FileNotFoundException
java.io.IOException

getString

public java.lang.String getString(java.lang.String name,
                                  java.lang.String value)
Gets a string

Parameters:
name - property name
value - the default value
Returns:
the value

setString

public void setString(java.lang.String name,
                      java.lang.String value)
Sets a string

Parameters:
name - property name
value - its new value

getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean value)
Gets a boolean

Parameters:
name - property name
value - the default value
Returns:
the value

setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
Sets a boolean

Parameters:
name - property name
value - the default value

getDouble

public double getDouble(java.lang.String name,
                        double value)
Gets a double

Parameters:
name - property name
value - the default value
Returns:
the value

getFloat

public float getFloat(java.lang.String name,
                      float value)
Gets a float

Parameters:
name - property name
value - the default value
Returns:
the value

setDouble

public void setDouble(java.lang.String name,
                      double value)
Sets a double

Parameters:
name - property name
value - its new value

setFloat

public void setFloat(java.lang.String name,
                     float value)
Sets a float

Parameters:
name - property name
value - its new value

getLong

public long getLong(java.lang.String name,
                    long value)
Gets a long

Parameters:
name - property name
value - the default value
Returns:
the value

getInt

public int getInt(java.lang.String name,
                  int value)
Gets an int

Parameters:
name - property name
value - the default value
Returns:
the value

getShort

public short getShort(java.lang.String name,
                      short value)
Gets a short

Parameters:
name - property name
value - the default value
Returns:
the value

getByte

public byte getByte(java.lang.String name,
                    byte value)
Gets a byte

Parameters:
name - property name
value - the default value
Returns:
the value

setLong

public void setLong(java.lang.String name,
                    long value)
Sets a long

Parameters:
name - property name
value - its new value

setInt

public void setInt(java.lang.String name,
                   int value)
Sets an int

Parameters:
name - property name
value - its new value

setShort

public void setShort(java.lang.String name,
                     short value)
Sets a short

Parameters:
name - property name
value - its new value

setByte

public void setByte(java.lang.String name,
                    byte value)
Sets a byte

Parameters:
name - property name
value - its new value

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put.

Overrides:
setProperty in class java.util.Properties
Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

addComment

public void addComment(java.lang.String comment)
Add a comment at the end of the properties sequence. Do nothing if properties file already exists. The comment will appear prefixed by '#' in the properties file.

Parameters:
comment - the comment line

addNewLine

public void addNewLine()
Add a new empty line at the end of the properties sequence. Do nothing if properties file already exists. Useful to separate group of properties.


load

public void load(java.io.InputStream inStream)
          throws java.io.IOException
Reads a property sequence from the input stream. The stream is assumed to be using the ISO 8859-1 character encoding. Comments, property definitions with value, and empty line are recorded, keeping them in order.

Overrides:
load in class java.util.Properties
Parameters:
inStream - the input stream.
Throws:
java.io.IOException - if an error occurred when reading from the input stream.

continueLine

protected boolean continueLine(java.lang.String line)

loadConvert

protected java.lang.String loadConvert(java.lang.String theString)

saveConvert

protected java.lang.String saveConvert(java.lang.String theString,
                                       boolean escapeSpace)

store

public void store(java.io.OutputStream out,
                  java.lang.String header)
           throws java.io.IOException
Writes a property sequence in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method. The stream is written using the ISO 8859-1 character encoding. Comments, property definitions with value, and empty line are written, keeping them in creating order.

Overrides:
store in class java.util.Properties
Parameters:
out - an output stream.
header - Not used in this method
Throws:
java.io.IOException - if writing this property list to the specified output stream throws an IOException.
java.lang.ClassCastException - if this Properties object contains any keys or values that are not Strings.
java.lang.NullPointerException - if out is null.

toHex

protected static char toHex(int nibble)
Convert a nibble to a hex character

Parameters:
nibble - the nibble to convert.