Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

In this page you can find the example usage for java.util Properties getProperty.

Prototype

public String getProperty(String key) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:com.thoughtworks.go.util.OperatingSystem.java

private static String readFromOsRelease() throws Exception {
    try (FileReader fileReader = new FileReader(new File("/etc/os-release"))) {
        Properties properties = new Properties();
        properties.load(fileReader);/* ww w  .j av  a 2s  . c  om*/
        return unQuote(properties.getProperty("PRETTY_NAME"));
    }
}

From source file:com.jdom.util.PropertiesUtil.java

public static List<String> getPropertyAsList(Properties properties, String key) {
    return Arrays.asList(StringUtils.split(properties.getProperty(key), SEPARATOR));
}

From source file:gov.lanl.util.DBCPUtils.java

/**
 * Set-up a DBCP DataSource from a properties object. Uses a properties 
 * key prefix to identify the properties associated with profile.  If 
 * a database profile has a prefix of djatoka, the props object would 
 * contain the following pairs://  w  w w.  j  a  va 2  s .  c  o m
 * djatoka.url=jdbc:mysql://localhost/djatoka
  * djatoka.driver=com.mysql.jdbc.Driver
  * djatoka.login=root
  * djatoka.pwd=
  * djatoka.maxActive=50
  * djatoka.maxIdle=10
  * @param dbid database profile properties file prefix
  * @param props properties object containing relevant pairs
 */
public static DataSource setupDataSource(String dbid, Properties props) throws Exception {
    String url = props.getProperty(dbid + ".url");
    String driver = props.getProperty(dbid + ".driver");
    String login = props.getProperty(dbid + ".login");
    String pwd = props.getProperty(dbid + ".pwd");
    int maxActive = 50;
    if (props.containsKey(dbid + ".maxActive"))
        maxActive = Integer.parseInt(props.getProperty(dbid + ".maxActive"));
    int maxIdle = 10;
    if (props.containsKey(dbid + ".maxIdle"))
        maxIdle = Integer.parseInt(props.getProperty(dbid + ".maxIdle"));
    log.debug(url + ";" + driver + ";" + login + ";" + pwd + ";" + maxActive + ";" + maxIdle);
    return setupDataSource(url, driver, login, pwd, maxActive, maxIdle);
}

From source file:StringUtils.java

/**
 *  Gets an integer-valued property from a standard Properties
 *  list.  If the value does not exist, or is a non-integer, returns defVal.
 *
 *  @since 2.1.48.//  w  w  w .  ja v a2s . c o m
 *  @param props The property set to look through
 *  @param key   The key to look for
 *  @param defVal If the property is not found or is a non-integer, returns this value.
 *  @return The property value as an integer (or defVal).
 */
public static int getIntegerProperty(Properties props, String key, int defVal) {
    String val = props.getProperty(key);

    return parseIntParameter(val, defVal);
}

From source file:org.springframework.social.openidconnect.api.impl.GAECompatibleClientHttpRequestFactorySelector.java

public static ClientHttpRequestFactory getRequestFactory() {
    Properties properties = System.getProperties();
    String proxyHost = properties.getProperty("http.proxyHost");
    int proxyPort = properties.containsKey("http.proxyPort")
            ? Integer.valueOf(properties.getProperty("http.proxyPort"))
            : 80;//ww  w.  j  a v  a2s  . c  o  m
    if (HTTP_COMPONENTS_AVAILABLE) {
        HttpClientBuilder httpClientBuilder = HttpClients.custom();
        if (proxyHost != null) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpClientBuilder.setProxy(proxy);
        }
        return HttpComponentsClientRequestFactoryCreator.createRequestFactory(httpClientBuilder.build(),
                proxyHost, proxyPort);
    } else {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        if (proxyHost != null) {
            requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
        }
        return requestFactory;
    }
}

From source file:com.ipcglobal.fredimport.util.FredUtils.java

/**
 * Readfix path./*from   w  ww  . j av a 2 s . co  m*/
 *
 * @param propertyName the property name
 * @param properties the properties
 * @return the string
 */
public static String readfixPath(String propertyName, Properties properties) {
    String pathName = properties.getProperty(propertyName).trim();
    if (pathName.endsWith(File.separator))
        return pathName;
    else
        return pathName + File.separator;
}

From source file:com.jdom.util.properties.PropertiesUtil.java

public static List<String> getPropertyAsList(Properties properties, String key) {
    String[] split = StringUtils.split(properties.getProperty(key), SEPARATOR);
    return (split != null && split.length > 0) ? Arrays.asList(split) : new ArrayList<String>();
}

From source file:StringUtils.java

/**
 *  Fetches a String property from the set of Properties.  This differs from
 *  Properties.getProperty() in a couple of key respects: First, property value
 *  is trim()med (so no extra whitespace back and front), and well, that's it.
 *
 *  @param props The Properties to search through
 *  @param key   The property key//from   w  w w. j  a v a 2  s.  co  m
 *  @param defval A default value to return, if the property does not exist.
 *  @return The property value.
 *  @since 2.1.151
 */
public static String getStringProperty(Properties props, String key, String defval) {
    String val = props.getProperty(key);

    if (val == null)
        return defval;

    return val.trim();
}

From source file:com.obidea.semantika.database.connection.ConnectionProviderFactory.java

public static IConnectionProvider createConnectionProvider(Properties properties)
        throws ConfigurationException {
    IConnectionProvider provider;/*from   w w  w  .ja  v  a  2 s  .  c  o m*/
    if (!StringUtils.isEmpty(properties.getProperty(Environment.POOL_MAX_SIZE))) {
        provider = new PooledConnectionProvider();
    } else {
        provider = new JdbcConnectionProvider();
    }
    provider.configure(properties);
    return provider;
}

From source file:StringUtils.java

/**
 *  Gets a boolean property from a standard Properties list.
 *  Returns the default value, in case the key has not been set.
 *  <P>//from   w  w  w  . j a v  a 2 s.co m
 *  The possible values for the property are "true"/"false", "yes"/"no", or
 *  "on"/"off".  Any value not recognized is always defined as "false".
 *
 *  @param props   A list of properties to search.
 *  @param key     The property key.
 *  @param defval  The default value to return.
 *
 *  @return True, if the property "key" was set to "true", "on", or "yes".
 *
 *  @since 2.0.11
 */
public static boolean getBooleanProperty(Properties props, String key, boolean defval) {
    String val = props.getProperty(key);

    if (val == null)
        return defval;

    return isPositive(val);
}