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 Details

  • Constructor Details

    • 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:
  • Method Details

    • contains

      public boolean contains(Object value)
      See Also:
    • containsKey

      public boolean containsKey(Object key)
      See Also:
    • containsValue

      public boolean containsValue(Object value)
      See Also:
    • elements

      public Enumeration elements()
      See Also:
    • getProperty

      public String getProperty(String key, String defaultValue)
      See Also:
    • getProperty

      public String getProperty(String key)
      See Also:
    • isEmpty

      public boolean isEmpty()
      See Also:
    • keys

      public Enumeration keys()
      See Also:
    • keySet

      public Set keySet()
      See Also:
    • load

      public void load() throws IOException
      load the properties from the file
      Throws:
      IOException - if an IOException occurs
    • putAll

      public void putAll(Map<String,Object> arg0)
      See Also:
    • 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:
    • 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 pair
      value - the value
      Returns:
      return value like Properties would return
      See Also:
    • 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 pair
      value - the value
      Returns:
      return value like Properties would return
      See Also:
    • 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 IOException
      Stores 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 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(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(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(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(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(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 Color getPropertyAsColor(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 Color getPropertyAsColor(String key, 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 String getPropertiesFile()
      Returns:
      the file name of the properties file handled by this instance