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: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
 *//*from   www. j  av  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();
            map.put(key, props.getProperty(key));
        }
    }
}

From source file:com.hadoop.compression.lzo.LzoCodec.java

public static String getRevisionHash() {
    try {// w w w .  j  a  v  a2s  .co m
        Properties p = new Properties();
        p.load(LzoCodec.class.getResourceAsStream("/build.properties"));
        return p.getProperty("build_revision");
    } catch (IOException e) {
        LOG.error("Could not find build properties file with revision hash");
        return "UNKNOWN";
    }
}

From source file:com.bt.aloha.batchtest.WeekendBatchTest.java

protected static void addBatchScenarios(BatchTest batchTest) throws Exception {
    Properties properties = new Properties();
    InputStream is = new FileInputStream(SCENARIO_FILE);
    properties.load(is);/*from www. j ava  2  s.c o  m*/
    is.close();
    for (Object scenarioName : properties.keySet()) {
        String name = (String) scenarioName;
        String value = properties.getProperty(name);
        batchTest.addBatchTestScenario(name + "," + value);
    }
}

From source file:de.pawlidi.openaletheia.utils.PropertiesUtils.java

public static DateTime getDateProperty(Properties properties, final String key) {
    if (PropertiesUtils.isEmpty(properties) || StringUtils.isBlank(key)) {
        return null;
    }/*from   w  ww .  j a v  a2s  .  c om*/
    String property = properties.getProperty(key);
    if (StringUtils.isBlank(property)) {
        return null;
    }
    try {
        return Constants.DATE_FORMAT.parseDateTime(property);
    } catch (UnsupportedOperationException e) {
        return null;
    } catch (IllegalArgumentException e) {
        return null;
    }
}

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
 *//*from w ww. ja  va  2s  .c om*/
public static void mergePropertiesIntoMap(Properties props, Map<String, String> 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();
            map.put(key, props.getProperty(key));
        }
    }
}

From source file:bluevia.SendSMS.java

public static void setTwitterStatus(String userEmail, String tweet) {
    if (tweet != null) {
        try {//from  ww  w  . ja v a  2s. co  m
            Properties twitterAccount = Util.getNetworkAccount(userEmail, "TwitterAccount");

            if (twitterAccount != null) {
                String consumer_key = twitterAccount.getProperty("TwitterAccount.consumer_key");
                String consumer_secret = twitterAccount.getProperty("TwitterAccount.consumer_secret");
                String access_key = twitterAccount.getProperty("TwitterAccount.access_key");
                String access_secret = twitterAccount.getProperty("TwitterAccount.access_secret");

                Twitter twitter = new TwitterFactory().getInstance();
                twitter.setOAuthConsumer(consumer_key, consumer_secret);
                twitter.setOAuthAccessToken(new AccessToken(access_key, access_secret));

                StatusUpdate status = new StatusUpdate(tweet);
                twitter.updateStatus(status);
            }
        } catch (TwitterException te) {
            te.printStackTrace();
            log.severe(te.getMessage());
        } catch (Exception e) {
            log.severe(String.format("Error sending SMS: %s", e.getMessage()));
        }
    }
}

From source file:com.intuit.autumn.utils.PropertyFactory.java

/**
 * Property resolve order/*www  . j  a  v a  2  s. c o m*/
 * 1. Environment Variable set at System level
 * 2. Java System Property set by the -D flag at runtime
 * 3. The property File it self
 *
 * @param key          property key
 * @param properties   property collection
 * @param defaultValue default value
 * @return resolved value
 */

public static String getProperty(final String key, final Properties properties, final String defaultValue) {
    String value = getenv(key);

    if (!isEmpty(value)) {
        return value;
    }

    value = System.getProperty(key, properties.getProperty(key));

    return !isEmpty(value) ? value : defaultValue;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.user.MMXUsersResourceTest.java

public static void setupDatabase() throws Exception {
    InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

    Properties testProperties = new Properties();
    testProperties.load(inputStream);//from  w  ww  . ja  v  a  2 s  .co  m

    String host = testProperties.getProperty("db.host");
    String port = testProperties.getProperty("db.port");
    String user = testProperties.getProperty("db.user");
    String password = testProperties.getProperty("db.password");
    String driver = testProperties.getProperty("db.driver");
    String schema = testProperties.getProperty("db.schema");

    String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

    ds = new BasicDataSource();
    ds.setDriverClassName(driver);
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(url);

    DBTestUtil.setBasicDataSource(ds);
    new MockUp<AppDAOImpl>() {
        @Mock
        protected String getEncrypted(String value) {
            return value;
        }
    };
    new MockUp<DefaultOpenfireEncryptor>() {
        @Mock
        public String getDecrypted(String value) {
            return value;
        }

        @Mock
        public String getEncrypted(String value) {
            return value;
        }
    };
    DBTestUtil.setupMockDBUtil();
    MMXUsersResourceTest.appEntity = createRandomApp();
    for (int i = 0; i < 10; i++) {
        userEntityList.add(createRandomUser(appEntity, i));
    }
}

From source file:de.pawlidi.openaletheia.utils.PropertiesUtils.java

/**
 * Return boolean value for given key. The boolean returned represents the
 * value true if the property value is not null and is equal, to the string
 * <code>'true'</code>, <code>'on'</code> or <code>'yes'</code> (case
 * insensitive) will return <code>true</code>. <code>'false'</code>,
 * <code>'off'</code> or <code>'no'</code> (case insensitive) will return
 * <code>false</code>. Otherwise, <code>null</code> is returned.
 * </p>//from   w  w w.  jav  a  2 s  .c  om
 * 
 * @param properties
 * @param key
 * @return
 */
public static Boolean getBooleanProperty(Properties properties, final String key) {
    if (PropertiesUtils.isEmpty(properties) || StringUtils.isBlank(key)) {
        return null;
    }
    final String property = properties.getProperty(key);
    if (property == null) {
        return null;
    }
    return BooleanUtils.toBoolean(property);
}

From source file:org.hyperic.hq.plugin.appha.VSphereUtil.java

public static String getURL(Properties props) {
    return props.getProperty(VSphereCollector.PROP_URL);
}