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:cl.niclabs.tscrypto.common.utils.Util.java

public static void trimProperties(Properties props) {

    for (String name : props.stringPropertyNames()) {
        props.setProperty(name, props.getProperty(name).trim());
    }// www .  jav a  2s  . co  m

}

From source file:com.amazonaws.kinesis.dataviz.kinesisclient.KinesisApplication.java

/**
 * @param propertiesFile//  ww  w.ja v a  2s.c  o m
 * @throws IOException Thrown when we run into issues reading properties
 */
private static void loadProperties(String propertiesFile) throws IOException {
    FileInputStream inputStream = new FileInputStream(propertiesFile);
    Properties properties = new Properties();
    try {
        properties.load(inputStream);
    } finally {
        inputStream.close();
    }

    String appNameOverride = properties.getProperty(ConfigKeys.APPLICATION_NAME_KEY);
    if (appNameOverride != null) {
        applicationName = appNameOverride;
    }
    LOG.info("Using application name " + applicationName);

    String streamNameOverride = properties.getProperty(ConfigKeys.STREAM_NAME_KEY);
    if (streamNameOverride != null) {
        streamName = streamNameOverride;
    }
    LOG.info("Using stream name " + streamName);

    String kinesisEndpointOverride = properties.getProperty(ConfigKeys.KINESIS_ENDPOINT_KEY);
    if (kinesisEndpointOverride != null) {
        kinesisEndpoint = kinesisEndpointOverride;
    }
    LOG.info("Using Kinesis endpoint " + kinesisEndpoint);

    String initialPositionOverride = properties.getProperty(ConfigKeys.INITIAL_POSITION_IN_STREAM_KEY);
    if (initialPositionOverride != null) {
        initialPositionInStream = InitialPositionInStream.valueOf(initialPositionOverride);
    }
    LOG.info("Using initial position " + initialPositionInStream.toString()
            + " (if a checkpoint is not found).");

    String redisEndpointOverride = properties.getProperty(ConfigKeys.REDIS_ENDPOINT);
    if (redisEndpointOverride != null) {
        redisEndpoint = redisEndpointOverride;
    }
    LOG.info("Using Redis endpoint " + redisEndpoint);

    String redisPortOverride = properties.getProperty(ConfigKeys.REDIS_PORT);
    if (redisPortOverride != null) {
        try {
            redisPort = Integer.parseInt(redisPortOverride);
        } catch (Exception e) {

        }
    }
    LOG.info("Using Redis port " + redisPort);

}

From source file:com.netflix.config.WebApplicationProperties.java

protected static void initApplicationProperties() throws ConfigurationException, MalformedURLException {
    File appPropFile = new File(appConfFolder + "/" + baseConfigFileName + ".properties");
    File appEnvPropOverrideFile = new File(
            appConfFolder + "/" + baseConfigFileName + getEnvironment() + ".properties");

    // TODO awang, how do we add this to archaius default config?
    PropertiesConfiguration appConf = new PropertiesConfiguration(appPropFile);
    // apply env overrides
    PropertiesConfiguration overrideConf = new PropertiesConfiguration(appEnvPropOverrideFile);
    Properties overrideprops = ConfigurationUtils.getProperties(overrideConf);
    for (Object prop : overrideprops.keySet()) {
        appConf.setProperty("" + prop, overrideprops.getProperty("" + prop));
    }//ww  w. jav a 2 s  .  c o m
    String path = appPropFile.toURI().toURL().toString();
    System.setProperty(URLConfigurationSource.CONFIG_URL, path);
    ConfigurationManager.loadPropertiesFromConfiguration(appConf);

}

From source file:com.wavemaker.common.util.SystemUtils.java

public static boolean allPropertiesAreSet(Properties properties, String... propertyNames) {
    for (String s : propertyNames) {
        if (properties.getProperty(s) == null) {
            return false;
        }// ww w .j a  v  a  2 s. c om
    }
    return true;
}

From source file:jongo.config.JongoConfiguration.java

/**
 * From the given properties object, load the the different {@link jongo.config.DatabaseConfiguration}.
 * @param prop an instance of {@link java.util.Properties} with the properties from the file.
 * @return a list of {@link jongo.config.DatabaseConfiguration}
 * @throws StartupException if we're unable to load a {@link jongo.config.DatabaseConfiguration}.
 *///from   w w  w. j  ava2  s  . c o  m
private static List<DatabaseConfiguration> getDatabaseConfigurations(final Properties prop)
        throws StartupException {
    String databaseList = prop.getProperty(p_name_jongo_database_list);
    if (databaseList == null) {
        throw new StartupException("Failed to read list of aliases " + p_name_jongo_database_list, demo);
    }
    final String[] names = databaseList.split(",");
    List<DatabaseConfiguration> databases = new ArrayList<DatabaseConfiguration>(names.length);
    for (String name : names) {
        name = name.trim();
        if (StringUtils.isAlphanumeric(name)) {
            DatabaseConfiguration c = generateDatabaseConfiguration(prop, name);
            databases.add(c);
        } else {
            l.warn("Database name {} is invalid. Continuing without it.", name);
        }
    }
    return databases;
}

From source file:net.certifi.audittablegen.HsqldbDMR.java

/**
 * Generate a Hsqldb DataSource from Properties
 *
 * @param props//from w ww. j  a  va2 s. co  m
 * @return BasicDataSource as DataSource
 */
static DataSource getRunTimeDataSource(Properties props) {

    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUsername(props.getProperty("username"));
    dataSource.setPassword(props.getProperty("password"));
    dataSource.setUrl(props.getProperty("url"));
    dataSource.setMaxActive(10);
    dataSource.setMaxIdle(5);
    dataSource.setInitialSize(5);
    dataSource.setAccessToUnderlyingConnectionAllowed(true);
    dataSource.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");

    return dataSource;
}

From source file:Main.java

/**
 * Merge the given Properties instance into the given Map,
 * copying all properties (key-value pairs) over.
 * <p>Uses <code>Properties.propertyNames()</code> to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be <code>null</code>)
 * @param map the target Map to merge the properties into
 *//* w  w w  .j a v  a  2 s  . co  m*/
@SuppressWarnings("unchecked")
public static void mergePropertiesIntoMap(Properties props, Map map) {
    if (map == null) {
        throw new IllegalArgumentException("Map must not be null");
    }
    if (props != null) {
        for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
            String key = (String) en.nextElement();
            Object value = props.getProperty(key);
            if (value == null) {
                // Potentially a non-String value...
                value = props.get(key);
            }
            map.put(key, value);
        }
    }
}

From source file:com.github.dbourdette.glass.job.util.JobDataMapUtils.java

public static JobDataMap fromProperties(String dataMap) {
    if (StringUtils.isEmpty(dataMap)) {
        return new JobDataMap();
    }// w  w  w  . j  a v a 2 s  .com

    Properties props = new Properties();

    try {
        props.load(new StringReader(dataMap));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    JobDataMap map = new JobDataMap();

    for (Object key : props.keySet()) {
        map.put(key, props.getProperty((String) key));
    }

    return map;
}

From source file:jp.co.opentone.bsol.framework.test.AbstractTestCase.java

@BeforeClass
public static void setupClass() throws IOException {
    Properties p = new Properties();
    try {//from   w  w w .j a  v a 2s .  c o  m
        p.load(AbstractTestCase.class.getResourceAsStream("/mail.properties"));
        wiser = new Wiser();
        wiser.setHostname(p.getProperty("mail.host"));
        wiser.setPort(Integer.valueOf(p.getProperty("mail.port")));

        wiser.start();
    } catch (IOException e) {
        throw e;
    }
}

From source file:com.glaf.core.jdbc.connection.ConnectionProviderFactory.java

public static ConnectionProvider createProvider(Properties properties) {
    if (properties == null || properties.isEmpty()) {
        return null;
    }/*w w w . ja va2s.c  om*/
    String jdbcUrl = properties.getProperty(DBConfiguration.JDBC_URL);
    String cacheKey = DigestUtils.md5Hex(jdbcUrl);
    if (providerCache.get(cacheKey) != null) {
        return providerCache.get(cacheKey);
    }
    ConnectionProvider provider = createProvider(properties, null);
    providerCache.put(cacheKey, provider);
    return provider;
}