Package org.openjump.io
Class PropertiesHandler
- java.lang.Object
-
- org.openjump.io.PropertiesHandler
-
- All Implemented Interfaces:
HandlerToMakeYourLifeEasier
public class PropertiesHandler extends 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
Fields Modifier and Type Field Description protected Propertiespropertiesprotected StringpropertiesFilestatic StringpropertiesFileEnding
-
Constructor Summary
Constructors Constructor Description PropertiesHandler(String propertiesFileName)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(Object value)booleancontainsKey(Object key)booleancontainsValue(Object value)Enumerationelements()Map<String,Object>getAll()get all properties as Map object (e.g.StringgetPropertiesFile()StringgetProperty(String key)StringgetProperty(String key, String defaultValue)booleangetPropertyAsBoolean(String key)Gets the property value with the keykeyand parses it to anbooleanif possible.booleangetPropertyAsBoolean(String key, boolean defaultValue)Gets the property value with the keykeyand parses it to anbooleanif possible.ColorgetPropertyAsColor(String key)Gets the property value with the keykeyand parses it to aColorif possible.ColorgetPropertyAsColor(String key, Color defaultValue)Gets the property value with the keykeyand parses it to aColorif possible.doublegetPropertyAsDouble(String key)Gets the property value with the keykeyand parses it to adoubleif possible.doublegetPropertyAsDouble(String key, double defaultValue)Gets the property value with the keykeyand parses it to adoubleif possible.intgetPropertyAsInt(String key)Gets the property value with the keykeyand parses it to anintif possible.intgetPropertyAsInt(String key, int defaultValue)Gets the property value with the keykeyand parses it to anintif possible.booleanisEmpty()Enumerationkeys()SetkeySet()voidload()load the properties from the filevoidputAll(Map<String,Object> arg0)Objectremove(Object arg0)ObjectsetProperty(String key, Color value)Sets a property key-value pair, replaces a pair with the same key!ObjectsetProperty(String key, String value)Sets a property key-value pair, replaces a pair with the same key!voidstore()Stores the current properties map to the file.voidstore(String comments)Stores the current properties map to the file.
-
-
-
Field Detail
-
propertiesFile
protected String propertiesFile
-
properties
protected Properties properties
-
propertiesFileEnding
public static final String propertiesFileEnding
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PropertiesHandler
public PropertiesHandler(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(Object value)
- See Also:
Properties
-
containsKey
public boolean containsKey(Object key)
- See Also:
Properties
-
containsValue
public boolean containsValue(Object value)
- See Also:
Properties
-
elements
public Enumeration elements()
- See Also:
Properties
-
getProperty
public String getProperty(String key, String defaultValue)
- See Also:
Properties
-
getProperty
public String getProperty(String key)
- See Also:
Properties
-
isEmpty
public boolean isEmpty()
- See Also:
Properties
-
keys
public Enumeration keys()
- See Also:
Properties
-
keySet
public Set keySet()
- See Also:
Properties
-
load
public void load() throws IOExceptionload the properties from the file- Throws:
IOException- if an IOException occurs
-
putAll
public void putAll(Map<String,Object> arg0)
- See Also:
Properties
-
getAll
public Map<String,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 Object remove(Object arg0)
- See Also:
Properties
-
setProperty
public Object setProperty(String key, String value)
Sets a property key-value pair, replaces a pair with the same key!- Parameters:
key- the key for the pairvalue- the value- Returns:
- return value like Properties would return
- See Also:
Properties
-
setProperty
public Object setProperty(String key, Color value)
Sets a property key-value pair, replaces a pair with the same key!- Parameters:
key- the key for the pairvalue- the value- Returns:
- return value like Properties would return
- See Also:
Properties
-
store
public void store(String comments) throws IOException
Stores the current properties map to the file.- Parameters:
comments- comments that will appear in the first lines of the file- Throws:
IOException- if an IOException occurs
-
store
public void store() throws IOExceptionStores the current properties map to the file.- Throws:
IOException- if an IOException occurs
-
getPropertyAsInt
public int getPropertyAsInt(String key)
Gets the property value with the keykeyand parses it to anintif 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(String key, int defaultValue)
Gets the property value with the keykeyand parses it to anintif 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 ofdefaultValue- value to be filled in, if the given key wasn't found- Returns:
- the value of the property
-
getPropertyAsBoolean
public boolean getPropertyAsBoolean(String key)
Gets the property value with the keykeyand parses it to anbooleanif 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(String key, boolean defaultValue)
Gets the property value with the keykeyand parses it to anbooleanif 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 ofdefaultValue- value to be filled in, if the given key wasn't found- Returns:
- the value of the property
-
getPropertyAsDouble
public double getPropertyAsDouble(String key)
Gets the property value with the keykeyand parses it to adoubleif 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(String key, double defaultValue)
Gets the property value with the keykeyand parses it to adoubleif 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 ofdefaultValue- value to be filled in, if the given key wasn't found- Returns:
- the value of the property
-
getPropertyAsColor
public Color getPropertyAsColor(String key)
Gets the property value with the keykeyand parses it to aColorif 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 Color getPropertyAsColor(String key, Color defaultValue)
Gets the property value with the keykeyand parses it to aColorif 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 ofdefaultValue- value to be filled in, if the given key wasn't found- Returns:
- the value of the property
-
getPropertiesFile
public String getPropertiesFile()
- Returns:
- the file name of the properties file handled by this instance
-
-