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

/**
 * Returns a value associated wither with one or more system properties, or found in the props map
 * @param system_props//from   w  ww .  j av a2  s. c  om
 * @param props         List of properties read from the configuration file
 * @param prop_name     The name of the property, will be removed from props if found
 * @param default_value Used to return a default value if the properties or system properties didn't have the value
 * @return The value, or null if not found
 */
public static String getProperty(String[] system_props, Properties props, String prop_name,
        String default_value) {
    String retval = null;
    if (props != null && prop_name != null) {
        retval = props.getProperty(prop_name);
        props.remove(prop_name);
    }

    String tmp, prop;
    if (retval == null && system_props != null) {
        for (int i = 0; i < system_props.length; i++) {
            prop = system_props[i];
            if (prop != null) {
                try {
                    tmp = System.getProperty(prop);
                    if (tmp != null)
                        return tmp;
                } catch (SecurityException ex) {
                }
            }
        }
    }

    if (retval == null)
        return default_value;
    return retval;
}

From source file:at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils.java

public static void initHibernate(Configuration config, Properties hibernateProperties) {

    String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY));
    if (scm != null) {
        automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1
                || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1;
    }/*from w  w w. jav  a 2  s  .  c o  m*/
    Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\".");
    if (automaticSessionHandling) {
        Logger.info("Hibernate is automatically handling session context management.");
    } else {
        Logger.info(
                "Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling.");
    }
    try {
        //Create the SessionFactory
        Logger.debug("Creating initial StatisicLogger session factory...");

        config.configure("hibernate_statistic.cfg.xml");
        //serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

        sessionFactory = config.buildSessionFactory(serviceRegistry);
        Logger.debug("Initial StatisicLogger session factory successfully created.");

    } catch (Throwable ex) {
        Logger.error("Initial StatisicLogger session factory creation failed: " + ex.getMessage());
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java

public static CobarAdapter getCobarAdapter(String cobarNodeName) throws IOException {
    CobarAdapter cAdapter = new CobarAdapter();
    Properties prop = new Properties();
    prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties"));
    BasicDataSource ds = new BasicDataSource();
    String user = prop.getProperty(cobarNodeName + ".user").trim();
    String password = prop.getProperty(cobarNodeName + ".password").trim();
    String ip = prop.getProperty(cobarNodeName + ".ip").trim();
    int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim());
    int maxActive = -1;
    int minIdle = 0;
    long timeBetweenEvictionRunsMillis = 10 * 60 * 1000;
    int numTestsPerEvictionRun = Integer.MAX_VALUE;
    long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    ds.setUsername(user);//from   w w w.j a  va  2s .  com
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(managerPort).append("/")
            .toString());
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    cAdapter.setDataSource(ds);
    return cAdapter;
}

From source file:com.microsoft.tfs.core.telemetry.TfsTelemetryInstrumentationInfo.java

static void initialize(final InputStream in) {
    // Default to production environment with batch uploading
    isTestEnv = false;/*from  ww w. j  a  va  2s  .  co  m*/
    isDeveloperMode = false;

    if (in != null) {
        try {
            final Properties props = new Properties();
            try {
                props.load(in);
                final String isTestEnvProperty = props
                        .getProperty("telemetry.instrumentation.is_test_environment"); //$NON-NLS-1$
                final String isDeveloperModeProperty = props
                        .getProperty("telemetry.instrumentation.is_developer_mode"); //$NON-NLS-1$

                // Default to production environment, all invalid inputs
                // will be resolved as "false"
                if (!StringUtil.isNullOrEmpty(isTestEnvProperty) && Boolean.parseBoolean(isTestEnvProperty)) {
                    isTestEnv = true;
                    if (!StringUtil.isNullOrEmpty(isDeveloperModeProperty)
                            && Boolean.parseBoolean(isDeveloperModeProperty)) {
                        isDeveloperMode = true;
                    }
                }
            } catch (final IOException e) {
                log.warn(MessageFormat.format("Unable to load property resource {0} with exception {1}", //$NON-NLS-1$
                        TELEMETRY_INSTRUMENTATION_PROPERTIES_RESOURCE, e));
                // suppressing exception
            }
        } finally {
            try {
                in.close();
            } catch (final IOException e) {
                log.warn(MessageFormat.format("Unable to close property resource {0} with exception {1}", //$NON-NLS-1$
                        TELEMETRY_INSTRUMENTATION_PROPERTIES_RESOURCE, e));
                // suppressing exception
            }
        }
    }
}

From source file:org.tonguetied.test.common.PersistenceTestBase.java

/**
 * Create and initialize the database connection.
 * /*from w w w . ja va  2  s  .c o  m*/
 * @param properties
 */
protected static void initializeDataSource(Properties properties) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setUrl(properties.getProperty(KEY_JDBC_URL));
    dataSource.setDriverClassName(properties.getProperty(KEY_JDBC_DRIVER));
    dataSource.setUsername(properties.getProperty(KEY_JDBC_USER_NAME));
    dataSource.setPassword(properties.getProperty(KEY_JDBC_PASSWORD));
    //        final DatasourceConnectionProvider provider = new DatasourceConnectionProvider();
    //        provider.configure(properties);
    template = new SimpleJdbcTemplate(dataSource);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.DBTestUtil.java

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

    Properties testProperties = new Properties();
    testProperties.load(inputStream);//from ww w  .j a v  a 2  s .  c  om

    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);
}

From source file:com.roche.iceboar.settings.GlobalSettingsFactory.java

private static String getTargetJavaVersion(String currentJavaVersion, Properties properties) {
    String targetJavaVersion;/*from   w w  w. j av a 2s.  c om*/
    targetJavaVersion = properties.getProperty(JNLP_TARGET_JAVA_VERSION);
    if (targetJavaVersion == null) {
        System.out.println("A property " + JNLP_TARGET_JAVA_VERSION
                + " is not defined. It is set to current Java Version: " + currentJavaVersion);
        targetJavaVersion = currentJavaVersion;
    }
    return targetJavaVersion;
}

From source file:it.cnr.icar.eric.client.xml.registry.util.ProviderProperties.java

protected static String getJaxrHome(Properties properties) {
    String jaxrHome = properties.getProperty(JAXR_HOME_KEY);
    jaxrHome = substituteVariable(jaxrHome, "$user.home", getUserHome());
    jaxrHome = substituteVariable(jaxrHome, "$eric.home", getEricHome(properties));
    //jaxrHome = substituteVariable(jaxrHome, "$eric.home", getEricHome());
    if (jaxrHome == null) {
        throw new RuntimeException("Required property '" + JAXR_HOME_KEY + "' not defined.");
    }/*from w w  w  .  ja  v  a  2s .co m*/
    return jaxrHome;
}

From source file:mitm.common.properties.PropertyUtils.java

/**
 * Returns the property as an int. If propery is not found, or the property is not something that can
 * be represented by an Integer, defaultValue will be returned.
 *///from   w  w w. ja  v a2s.c o  m
public static int getIntegerProperty(Properties properties, String name, int defaultValue) {
    int result = defaultValue;

    Object value = properties.get(name);

    if (value == null) {
        value = properties.getProperty(name);
    }

    if (value instanceof String) {
        result = NumberUtils.toInt((String) value, defaultValue);
    } else if (value instanceof Integer) {
        result = (Integer) value;
    }

    return result;
}

From source file:com.springstudy.utils.PropertiesLoader.java

public static String getDefaultResourcePropertiesByKey(String key) {
    Properties prop;
    try {/* w w w .  j  a va 2s  . c  o m*/
        prop = PropertiesLoaderUtils.loadAllProperties("application.properties");
        return prop.getProperty(key);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}