Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

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

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:Main.java

/**
 * (android) read from file/*from ww w . j a  va2 s .  co m*/
 * 
 * @param fileName
 * @return
 */
public static String androidFileload(Context con, String fileName) {
    Properties properties = new Properties();
    try {
        FileInputStream stream = con.openFileInput(fileName);
        properties.load(stream);
    } catch (FileNotFoundException e) {
        return null;
    } catch (IOException e) {
        return null;
    }

    return properties.get(FILE_ENCODING).toString();
}

From source file:com.squid.kraken.v4.auth.KrakenClientConfig.java

private static void load(InputStream in, Properties target) {
    Properties properties = new Properties();
    try {//from   ww  w.j a va2s  .co m
        properties.loadFromXML(in);
        for (Object key : properties.keySet()) {
            Object value = properties.get(key);
            target.put(key, value);
            logger.debug(key + ":" + value);
        }
    } catch (Exception e) {
        logger.warn("Could not load Kraken config file for stream : " + in, e);
    }

}

From source file:com.amalto.core.storage.datasource.DataSourceFactory.java

private static synchronized InputStream readDataSourcesConfiguration() {
    Properties configuration = MDMConfiguration.getConfiguration();
    String dataSourcesLocation = (String) configuration.get(DB_DATASOURCES);
    if (dataSourcesLocation == null) { // DB_DATASOURCES property is mandatory to continue.
        throw new IllegalStateException(DB_DATASOURCES + " is not defined in MDM configuration.");
    }//from  w  ww  .  j a  v a 2s  . co  m
    String dataSourcesFileName = SystemPropertyUtils.resolvePlaceholders(dataSourcesLocation);
    InputStream configurationAsStream = null;
    // 1- Try from file (direct lookup)
    File file = new File(dataSourcesFileName);
    if (file.exists()) {
        LOGGER.info("Reading from datasource file at '" + file.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
        try {
            configurationAsStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException("Unexpected state (file exists but can't create a stream from it).",
                    e);
        }
    }
    // 2- From class path
    if (configurationAsStream == null) {
        List<String> filePaths = Arrays.asList(dataSourcesFileName);
        Iterator<String> iterator = filePaths.iterator();

        String currentFilePath = StringUtils.EMPTY;
        while (configurationAsStream == null && iterator.hasNext()) {
            currentFilePath = iterator.next();
            configurationAsStream = Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream(currentFilePath);
        }
        if (configurationAsStream != null) {
            LOGGER.info("Reading from datasource file at '" + currentFilePath + "'."); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
    // 3- error: configuration was not found
    if (configurationAsStream == null) {
        throw new IllegalStateException(
                "Could not find datasources configuration file '" + dataSourcesFileName + "'.");
    }
    return configurationAsStream;
}

From source file:de.hypoport.ep2.support.configuration.properties.PropertiesLoader.java

private static void logProperties(Set<Object> filter, Properties properties) {
    String propertiesAsText = "";
    for (Object key : filter) {
        propertiesAsText = propertiesAsText + "\n" + key + "=" + properties.get(key);
    }//  w  w  w.ja  v a 2s  .  c  o  m
    LOG.info("Loaded properties: " + propertiesAsText);
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java

/**
 * Initialize the application context, adding the properties configuration file depending on the
 * specified path.// w ww.  j a v a2 s.c  o  m
 *
 * @param propertiesPath the path to the file.
 * @return the resource loaded from the properties file.
 * @throws IOException error opening the properties file.
 */
private static Properties initApplicationContextAndProperties(String propertiesPath) throws IOException {

    Resource resource = new ClassPathResource(propertiesPath);
    if (!resource.exists()) {
        resource = new FileSystemResource(propertiesPath);
    }
    DynamicPropertyPlaceholderConfigurer.setDynamicResource(resource);

    Properties properties = PropertiesLoaderUtils.loadProperties(resource);
    String dbType = (String) properties.get(AW_REPORT_MODEL_DB_TYPE);
    if (dbType != null && dbType.equals(DataBaseType.MONGODB.name())) {
        appCtx = new ClassPathXmlApplicationContext("classpath:kratubackend-mongodb-beans.xml");
    } else {
        appCtx = new ClassPathXmlApplicationContext("classpath:kratubackend-sql-beans.xml");
    }

    return properties;
}

From source file:com.asual.summer.core.util.StringUtils.java

public static String decorate(String str, Properties values) {
    Matcher m = Pattern.compile("\\$\\{[^}]*\\}").matcher(str);
    while (m.find()) {
        String key = m.group().replaceAll("^\\$\\{|\\}$", "");
        Object value = values.get(key);
        if (value != null) {
            str = str.replaceAll("\\$\\{" + key + "\\}", Matcher.quoteReplacement(value.toString()));
        }/* w  w  w.  j av  a  2s . c o m*/
    }
    return str;
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

public static String getKeyspace(final KunderaMetadata kunderaMetadata, String persistenceUnit) {
    PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata.getApplicationMetadata()
            .getPersistenceUnitMetadata(persistenceUnit);
    Properties props = persistenceUnitMetadata.getProperties();
    String keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE);
    return keyspace;
}

From source file:com.weaverplatform.nifi.CreateIndividualTest.java

@BeforeClass
public static void beforeClass() throws IOException {

    // Define property file for NiFi
    Properties props = System.getProperties();
    props.setProperty("nifi.properties.file.path", Resources.getResource("nifi.properties").getPath());

    // Read test properties
    Properties testProperties = new Properties();
    testProperties.load(Resources.getResource("test.properties").openStream());
    WEAVER_URL = testProperties.get("weaver.url").toString();
    WEAVER_DATASET = testProperties.get("weaver.global.dataset").toString();

    // Set Nifi Weaver properties
    NiFiProperties.getInstance().put(WeaverProperties.URL, WEAVER_URL);
    NiFiProperties.getInstance().put(WeaverProperties.DATASET, WEAVER_DATASET);
}

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()} to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be {@code null})
 * @param map the target Map to merge the properties into
 *//*from  w ww  .ja va 2s  .  c  o m*/
@SuppressWarnings("unchecked")
public static <K, V> void mergePropertiesIntoMap(Properties props, Map<K, V> 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.get(key);
            if (value == null) {
                // Allow for defaults fallback or potentially overridden accessor...
                value = props.getProperty(key);
            }
            map.put((K) key, (V) value);
        }
    }
}

From source file:de.snertlab.xdccBee.ui.Application.java

private static String readVersionNrFromProperties() {
    try {/*  w  w  w .  j  av a2 s  . c om*/
        Properties prop = loadVersionProperties();
        String version = ""; //$NON-NLS-1$
        String major = (String) prop.get("build.major.number"); //$NON-NLS-1$
        String minor = (String) prop.get("build.minor.number"); //$NON-NLS-1$
        String patch = (String) prop.get("build.patch.number"); //$NON-NLS-1$
        String revision = (String) prop.get("build.revision.number"); //$NON-NLS-1$

        version = "Version " + major + "." + minor + "." + patch + " Build(" + revision + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        return version;
    } catch (Exception e) {
        logger.info("no version file found");
        return "NO_VERSION_FILE";
    }
}