org.openjump.io
Class PropertiesHandler

java.lang.Object
  extended by org.openjump.io.PropertiesHandler
All Implemented Interfaces:
HandlerToMakeYourLifeEasier

public class PropertiesHandler
extends java.lang.Object
implements HandlerToMakeYourLifeEasier

Class that enables easy access for reading and writing properties files.

Version:
$Rev: 1559 $
Author:
Ole Rahn

FH Osnabrück - University of Applied Sciences Osnabrück,
Project: PIROL (2005),
Subproject: Daten- und Wissensmanagement

Field Summary
protected  java.util.Properties properties
           
protected  java.lang.String propertiesFile
           
static java.lang.String propertiesFileEnding
           
 
Constructor Summary
PropertiesHandler(java.lang.String propertiesFileName)
          Constructor
 
Method Summary
 boolean contains(java.lang.Object value)
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Enumeration elements()
           
 java.util.Map<java.lang.String,java.lang.Object> getAll()
          get all properties as Map object (e.g. to feed into an other map...)
 java.lang.String getPropertiesFile()
           
 java.lang.String getProperty(java.lang.String key)
           
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
           
 boolean getPropertyAsBoolean(java.lang.String key)
          Gets the property value with the key key and parses it to an boolean if possible.
 boolean getPropertyAsBoolean(java.lang.String key, boolean defaultValue)
          Gets the property value with the key key and parses it to an boolean if possible.
 java.awt.Color getPropertyAsColor(java.lang.String key)
          Gets the property value with the key key and parses it to a Color if possible.
 java.awt.Color getPropertyAsColor(java.lang.String key, java.awt.Color defaultValue)
          Gets the property value with the key key and parses it to a Color if possible.
 double getPropertyAsDouble(java.lang.String key)
          Gets the property value with the key key and parses it to a double if possible.
 double getPropertyAsDouble(java.lang.String key, double defaultValue)
          Gets the property value with the key key and parses it to a double if possible.
 int getPropertyAsInt(java.lang.String key)
          Gets the property value with the key key and parses it to an int if possible.
 int getPropertyAsInt(java.lang.String key, int defaultValue)
          Gets the property value with the key key and parses it to an int if possible.
 boolean isEmpty()
           
 java.util.Enumeration keys()
           
 java.util.Set keySet()
           
 void load()
          load the properties from the file
 void putAll(java.util.Map<java.lang.String,java.lang.Object> arg0)
           
 java.lang.Object remove(java.lang.Object arg0)
           
 java.lang.Object setProperty(java.lang.String key, java.awt.Color value)
          Sets a property key-value pair, replaces a pair with the same key!
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          Sets a property key-value pair, replaces a pair with the same key!
 void store()
          Stores the current properties map to the file.
 void store(java.lang.String comments)
          Stores the current properties map to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertiesFile

protected java.lang.String propertiesFile

properties

protected java.util.Properties properties

propertiesFileEnding

public static final java.lang.String propertiesFileEnding
See Also:
Constant Field Values
Constructor Detail

PropertiesHandler

public PropertiesHandler(java.lang.String propertiesFileName)
Constructor

Parameters:
propertiesFileName - the file name (with out path!) of the properties file, that is to be read or written. It will automatically be placed in the config directory.
See Also:
PirolPlugInSettings.configDirectory()
Method Detail

contains

public boolean contains(java.lang.Object value)
See Also:
Properties

containsKey

public boolean containsKey(java.lang.Object key)
See Also:
Properties

containsValue

public boolean containsValue(java.lang.Object value)
See Also:
Properties

elements

public java.util.Enumeration elements()
See Also:
Properties

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
See Also:
Properties

getProperty

public java.lang.String getProperty(java.lang.String key)
See Also:
Properties

isEmpty

public boolean isEmpty()
See Also:
Properties

keys

public java.util.Enumeration keys()
See Also:
Properties

keySet

public java.util.Set keySet()
See Also:
Properties

load

public void load()
          throws java.io.IOException
load the properties from the file

Throws:
java.io.IOException

putAll

public void putAll(java.util.Map<java.lang.String,java.lang.Object> arg0)
See Also:
Properties

getAll

public java.util.Map<java.lang.String,java.lang.Object> getAll()
get all properties as Map object (e.g. to feed into an other map...)

Returns:
a map containing all the properties

remove

public java.lang.Object remove(java.lang.Object arg0)
See Also:
Properties

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Sets a property key-value pair, replaces a pair with the same key!

Parameters:
key - the key for the pair
value - the value
Returns:
return value like Properties would return
See Also:
Properties

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.awt.Color value)
Sets a property key-value pair, replaces a pair with the same key!

Parameters:
key - the key for the pair
value - the value
Returns:
return value like Properties would return
See Also:
Properties

store

public void store(java.lang.String comments)
           throws java.io.IOException
Stores the current properties map to the file.

Parameters:
comments - comments that will appear in the first lines of the file
Throws:
java.io.IOException

store

public void store()
           throws java.io.IOException
Stores the current properties map to the file.

Throws:
java.io.IOException

getPropertyAsInt

public int getPropertyAsInt(java.lang.String key)
Gets the property value with the key key and parses it to an int if possible. An exception will be thrown, if this key is not found within the properties and if the value could not be parsed as desired.

Parameters:
key - the key to get the value of
Returns:
the value of the property

getPropertyAsInt

public int getPropertyAsInt(java.lang.String key,
                            int defaultValue)
Gets the property value with the key key and parses it to an int if possible. If this key is not found within the properties the given default-Value will be returned. An exception will be thrown, if the value is existent, but could not be parsed as desired.

Parameters:
key - the key to get the value of
defaultValue - value to be filled in, if the given key wasn't found
Returns:
the value of the property

getPropertyAsBoolean

public boolean getPropertyAsBoolean(java.lang.String key)
Gets the property value with the key key and parses it to an boolean if possible. An exception will be thrown, if this key is not found within the properties and if the value could not be parsed as desired.

Parameters:
key - the key to get the value of
Returns:
the value of the property

getPropertyAsBoolean

public boolean getPropertyAsBoolean(java.lang.String key,
                                    boolean defaultValue)
Gets the property value with the key key and parses it to an boolean if possible. If this key is not found within the properties the given default-Value will be returned. An exception will be thrown, if the value is existent, but could not be parsed as desired.

Parameters:
key - the key to get the value of
defaultValue - value to be filled in, if the given key wasn't found
Returns:
the value of the property

getPropertyAsDouble

public double getPropertyAsDouble(java.lang.String key)
Gets the property value with the key key and parses it to a double if possible. An exception will be thrown, if this key is not found within the properties and if the value could not be parsed as desired.

Parameters:
key - the key to get the value of
Returns:
the value of the property

getPropertyAsDouble

public double getPropertyAsDouble(java.lang.String key,
                                  double defaultValue)
Gets the property value with the key key and parses it to a double if possible. If this key is not found within the properties the given default-Value will be returned. An exception will be thrown, if the value is existent, but could not be parsed as desired.

Parameters:
key - the key to get the value of
defaultValue - value to be filled in, if the given key wasn't found
Returns:
the value of the property

getPropertyAsColor

public java.awt.Color getPropertyAsColor(java.lang.String key)
Gets the property value with the key key and parses it to a Color if possible. An exception will be thrown, if this key is not found within the properties and if the value could not be parsed as desired.

Parameters:
key - the key to get the value of
Returns:
the value of the property

getPropertyAsColor

public java.awt.Color getPropertyAsColor(java.lang.String key,
                                         java.awt.Color defaultValue)
Gets the property value with the key key and parses it to a Color if possible. If this key is not found within the properties the given default-Value will be returned. An exception will be thrown, if the value is existent, but could not be parsed as desired.

Parameters:
key - the key to get the value of
defaultValue - value to be filled in, if the given key wasn't found
Returns:
the value of the property

getPropertiesFile

public java.lang.String getPropertiesFile()
Returns:
the file name of the properties file handled by this instance