SMILA (incubation) API documentation

org.eclipse.smila.utils.config
Class ConfigUtils

java.lang.Object
  extended by org.eclipse.smila.utils.config.ConfigUtils

public final class ConfigUtils
extends java.lang.Object

Helper class to load configs from these locations:

The configs are attempted to be loaded in the order of the list above.

The central config folder is determined in this order from the first non-blank location (the last will always succeed!)

  1. a System.property set to ‑Dorg.eclipse.smila.utils.config.root=<path>
  2. an environment variable set to org.eclipse.smila.utils.config.root=<path>
  3. <org.eclipse.core.runtime.Platform.getInstallLocation()>/configuration.


Field Summary
static java.lang.String PROPERTY_CONFIG_ROOT
          The Constant PROPERTY_CONFIG_ROOT.
 
Method Summary
static java.lang.String getConfigContent(java.lang.String bundleName, java.lang.String configPath)
          gets content of an configuration file as a string, assuming UTF-8 as the encoding.
static java.util.List<java.lang.String> getConfigEntries(java.lang.String bundleName, java.lang.String configPath)
          Gets the files.
static java.io.File getConfigFile(java.lang.String bundleName, java.lang.String configPath)
          Gets the config file as denoted by the given arguments, or null if it doesnt exist.
static java.io.File getConfigFilePath(java.lang.String bundleName, java.lang.String configPath)
          Gets the File object denoting the path as defined by the given arguments.
static java.io.File getConfigFolder(java.lang.String bundleName, java.lang.String configPath)
          Deprecated. use the more correctly named getConfigFile(String, String) as this may also return non-directory entries.
static java.util.Properties getConfigProperties(java.lang.String bundleName, java.lang.String configPath)
          Gets the config properties.
static java.io.InputStream getConfigStream(java.lang.String bundleName, java.lang.String configPath)
          Gets the configuration stream.
static java.io.InputStream getConfigStream(java.lang.String bundleName, java.lang.String configPath, java.lang.String defaultConfigPath)
          Gets the configuration stream for the denoted config file.
static java.io.File getConfigurationFolder()
          Gets the root configuration folder as set thru the env var/system propery "org.eclipse.smila.utils.config.root".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_CONFIG_ROOT

public static final java.lang.String PROPERTY_CONFIG_ROOT
The Constant PROPERTY_CONFIG_ROOT.

See Also:
Constant Field Values
Method Detail

getConfigStream

public static java.io.InputStream getConfigStream(java.lang.String bundleName,
                                                  java.lang.String configPath,
                                                  java.lang.String defaultConfigPath)
Gets the configuration stream for the denoted config file. The stream is to be closed by the caller.

Note: While this methods supports the bundle name to be an arbitrary string that is not the name of the bundle for "normal" configs the defaultConfigPath will only work if the given bundle name is actually the name of the bundle.

Parameters:
bundleName - the bundle name
configPath - the path which may be either relative or absolute.
While absolute paths are supported they are strongly discurraged.
defaultConfigPath - the default config path to a resource that is contained in the bundle itself if the configPath doesnt resolve to an existing file.
Throws:
ConfigurationLoadException - if the denoted config file doesnt exist or cannot be opened.

getConfigFolder

@Deprecated
public static java.io.File getConfigFolder(java.lang.String bundleName,
                                                      java.lang.String configPath)
Deprecated. use the more correctly named getConfigFile(String, String) as this may also return non-directory entries.

Gets the configuration folder.

Parameters:
bundleName - the bundle name
configPath - the configuration name
Returns:
the configuration folder

getConfigFile

public static java.io.File getConfigFile(java.lang.String bundleName,
                                         java.lang.String configPath)
Gets the config file as denoted by the given arguments, or null if it doesnt exist.

Parameters:
bundleName - the bundle name
configPath - the config path
Returns:
the config file which may be either a direcory or a file, or null if it doesnt exist.
See Also:
getConfigFilePath(String, String)

getConfigFilePath

public static java.io.File getConfigFilePath(java.lang.String bundleName,
                                             java.lang.String configPath)
Gets the File object denoting the path as defined by the given arguments. Note that the file/folder may not exist.

Parameters:
bundleName - the bundle name
configPath - the config path
Returns:
never null

getConfigStream

public static java.io.InputStream getConfigStream(java.lang.String bundleName,
                                                  java.lang.String configPath)
Gets the configuration stream.

Parameters:
bundleName - the bundle name
configPath - the configuration path
Returns:
the configuration stream

getConfigEntries

public static java.util.List<java.lang.String> getConfigEntries(java.lang.String bundleName,
                                                                java.lang.String configPath)
Gets the files.

Parameters:
bundleName - the bundle name
configPath - the config name
Returns:
the configuration stream

getConfigurationFolder

public static java.io.File getConfigurationFolder()
Gets the root configuration folder as set thru the env var/system propery "org.eclipse.smila.utils.config.root".

Returns:
the cONFIGURATION_FOLDER

getConfigProperties

public static java.util.Properties getConfigProperties(java.lang.String bundleName,
                                                       java.lang.String configPath)
                                                throws java.io.IOException
Gets the config properties.

Throws:
java.io.IOException
See Also:
#getConfigStream(String, String)} as it is called.

getConfigContent

public static java.lang.String getConfigContent(java.lang.String bundleName,
                                                java.lang.String configPath)
                                         throws java.io.IOException
gets content of an configuration file as a string, assuming UTF-8 as the encoding.

Throws:
java.io.IOException
See Also:
#getConfigStream(String, String)} as it is called.

SMILA (incubation) API documentation