Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.ensembl.util
Class PropertiesUtil

    java.lang.Object
      org.ensembl.util.PropertiesUtil

public class PropertiesUtil
extends java.lang.Object

Convenience class offering methods for easily accessing property files stored as files available via file system or URL. Makes it easy to extract single property values or all of them as a property object.

Constructor Summary
`PropertiesUtil()`

Method Summary
`static boolean` | `booleanValue(java.util.Properties properties, java.lang.String propertyName, boolean defaultValue)`
`static void` | `copyProperty(java.util.Properties src, java.lang.String key, java.util.Properties tgt)` Copy property from src to tgt if not null.
`static void` | `copyProperty(java.util.Properties src, java.lang.String key, java.util.Properties tgt, java.lang.String defaultValue)` Copy property from src to tgt if not null.
`static java.util.Properties` | `createProperties(java.lang.String propertyFile)` Creates property object from propertyFile(s).
`static java.util.Properties` | `createProperties(java.lang.String[] propertyFiles)` Creates property object from propertyFiles.
`static java.util.Properties` | `createProperties(java.net.URL url)` Creates property object from url.
`static java.util.Properties` | `filterOnPrefix(java.lang.String prefix, java.util.Properties in)` Filters the input set of properties only allowing those with keys that begin with _prefix_.
`static java.lang.String` | `getProperty(java.lang.String propertyFile, java.lang.String key)`
`static java.lang.String` | `getProperty(java.net.URL url, java.lang.String key)`
`static java.util.Properties` | `removePrefixFromKeys(java.util.Properties src, java.lang.String prefix)` Removes "prefix\\." from the beginning of all keys in _src_.
`static java.util.Properties` | `removePrefixFromKeys(java.util.Properties src, java.lang.String prefix, java.lang.String separator)` Removes _prefix_+separator from the beginning of all keys in _src_.
`static java.util.Properties` | `stringToProperties(java.lang.String string, java.lang.String separatorRegexp)` Convenience method for creating a properties object from a string.
`static java.net.URL` | `stringToURL(java.lang.String file)` Attempts to convert file location into a URL corresponding to a file in the local filesystem or in the classpath.
`static java.lang.String` | `toString(java.util.Properties p)` Sorts pairs by key name and prints one name = value pair per line.
`static void` | `writeToFile(java.util.Properties props, java.lang.String fileName, java.lang.String pat)` Write some properties to file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PropertiesUtil

    public PropertiesUtil()

Method Detail

### createProperties

    public static java.util.Properties createProperties(java.lang.String[] propertyFiles)

  Creates property object from propertyFiles. Firstly attempts to open each propertyFile as a file, secondly attempts to open it as a resource (available via CLASSPATH).

  Returns:
    property object corresponding to contents of files (empty if can't open files or files are empty).

### createProperties

    public static java.util.Properties createProperties(java.lang.String propertyFile)

  Creates property object from propertyFile(s). Firstly attempts to open property as a file, secondly attempts to open it as a resource (available via CLASSPATH).

  Parameters:
    `propertyFile` - list of 1 or more files separated by commas.
  Returns:
    property object corresponding to file, or null if can't open file.

### stringToURL

    public static java.net.URL stringToURL(java.lang.String file)

  Attempts to convert file location into a URL corresponding to a file in the local filesystem or in the classpath. Simply returns new URL(file) if file is a valid URL already. First looks for a File with that filepath, then looks in the classpath.

  Parameters:
    `file` - file location. e.g. resources/data/file.txt, file:/home/bob/file.txt
  Returns:
    URL corresponding to file if it exists, otherwise null.

### createProperties

    public static java.util.Properties createProperties(java.net.URL url)

  Creates property object from url.

  Returns:
    property object corresponding to file, or null if can't open resource.

### getProperty

    public static java.lang.String getProperty(java.lang.String propertyFile,
                                               java.lang.String key)

  Returns:
    value corresponding to key from file, null if can't open file or key not present.

### getProperty

    public static java.lang.String getProperty(java.net.URL url,
                                               java.lang.String key)

  Returns:
    value corresponding to key from url, null if can't open file or key not present.

### booleanValue

    public static boolean booleanValue(java.util.Properties properties,
                                       java.lang.String propertyName,
                                       boolean defaultValue)

  Returns:
    true if property value is is "true" (case insensitive), false if value is not "true", _default_ if proerty not set.

### toString

    public static java.lang.String toString(java.util.Properties p)

  Sorts pairs by key name and prints one name = value pair per line.

### filterOnPrefix

    public static java.util.Properties filterOnPrefix(java.lang.String prefix,
                                                      java.util.Properties in)

  Filters the input set of properties only allowing those with keys that begin with _prefix_.

  Parameters:
    `prefix` - key prefix to filter on.
    `in` - input properties
  Returns:
    new properties object containing a subset of _in_ matching the condition.

### removePrefixFromKeys

    public static java.util.Properties removePrefixFromKeys(java.util.Properties src,
                                                            java.lang.String prefix)

  Removes "prefix\\." from the beginning of all keys in _src_.

  Parameters:
    `prefix` - prefix to be removed from keys. Should be a regular expression as defined in java.util.regexp.Pattern.
    `src` - input properties
  Returns:
    new properties object that contains all the pairs from _in_ but with the prefix removed from any keys that start with it.
  See Also:
    `removePrefixFromKeys(Properties, String, String)`

### removePrefixFromKeys

    public static java.util.Properties removePrefixFromKeys(java.util.Properties src,
                                                            java.lang.String prefix,
                                                            java.lang.String separator)

  Removes _prefix_+separator from the beginning of all keys in _src_.

  Parameters:
    `src` - input properties
    `prefix` - prefix to be removed from keys. Should be a regular expression as defined in java.util.regexp.Pattern.
    `separator` - separator between prefix and key. Should be a regular expression. * @return new properties object that contains all the pairs from _in_ but with the prefix removed from any keys that start with it.

### copyProperty

    public static void copyProperty(java.util.Properties src,
                                    java.lang.String key,
                                    java.util.Properties tgt)

  Copy property from src to tgt if not null.

  Parameters:
    `src` - source properties.
    `key` - key of property to be copied.
    `tgt` - target properties.

### copyProperty

    public static void copyProperty(java.util.Properties src,
                                    java.lang.String key,
                                    java.util.Properties tgt,
                                    java.lang.String defaultValue)

  Copy property from src to tgt if not null.

  Parameters:
    `src` - source properties.
    `key` - key of property to be copied.
    `tgt` - target properties.
    `defaultValue` - defaultValue for property, used if src.getProperty(key)==null and ignored if null.

### writeToFile

    public static void writeToFile(java.util.Properties props,
                                   java.lang.String fileName,
                                   java.lang.String pat)

  Write some properties to file. Optionally filter on property name.

  Parameters:
    `props` - The properties to write.
    `fileName` - The file to write to.
    `pat` - If not null, only properties whose names match this string will be written.

### stringToProperties

    public static java.util.Properties stringToProperties(java.lang.String string,
                                                          java.lang.String separatorRegexp)

  Convenience method for creating a properties object from a string.

  Parameters:
    `string` - string to be converted into a properties object. Format of string is name=value pairs separated by _separatorRegexp_. Can be null. e.g. "a=1:b=2".
    `separatorRegexp` - separator regular expression, e.g. ":", ";"
  Returns:
    properties object representation of the string or null if _string_ is null.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD