List of usage examples for org.apache.commons.configuration PropertiesConfiguration containsKey
public boolean containsKey(String key)
From source file:com.uber.hoodie.DataSourceUtils.java
public static void checkRequiredProperties(PropertiesConfiguration configuration, List<String> checkPropNames) { checkPropNames.stream().forEach(prop -> { if (!configuration.containsKey(prop)) { throw new HoodieNotSupportedException("Required property " + prop + " is missing"); }// w w w .j a v a2s. c o m }); }
From source file:com.xemantic.tadedon.configuration.Configurations.java
public static void merge(PropertiesConfiguration defaultConf, PropertiesConfiguration conf) { LOG.debug("Merging: {} <-> {}", defaultConf.getURL(), conf.getURL()); for (@SuppressWarnings("unchecked") Iterator<String> iterator = defaultConf.getKeys(); iterator.hasNext();) { String key = iterator.next(); if (!conf.containsKey(key)) { copyProperty(key, defaultConf, conf); }//www . j a va2 s . c o m } try { conf.save(); } catch (ConfigurationException e) { throw new RuntimeException("Could no save configuration file: " + conf.getFileName(), e); } }
From source file:fr.inria.atlanmod.neoemf.data.blueprints.option.BlueprintsResourceSaveTest.java
@Test public void testSaveGraphResourceNoOption() throws IOException, ConfigurationException { resource.save(Collections.emptyMap()); File configFile = new File(file() + configFileName); assertThat(configFile).exists(); // "Config file does not exist" PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assertThat(configuration.containsKey(BlueprintsResourceOptions.GRAPH_TYPE)).isTrue(); assertThat(configuration.getString(BlueprintsResourceOptions.GRAPH_TYPE)) .isEqualTo(BlueprintsResourceOptions.GRAPH_TYPE_DEFAULT); assertThat(getKeyCount(configuration)).isEqualTo(3); // "Too much content in the .properties file" }
From source file:fr.inria.atlanmod.neoemf.data.blueprints.option.BlueprintsResourceSaveTest.java
@Test public void testSaveGraphResourceDefaultGraphTypeOption() throws IOException, ConfigurationException { resource.save(BlueprintsOptionsBuilder.newBuilder().asMap()); File configFile = new File(file() + configFileName); assertThat(configFile).exists(); // "Config file does not exist" PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assertThat(configuration.containsKey(BlueprintsResourceOptions.GRAPH_TYPE)).isTrue(); assertThat(configuration.getString(BlueprintsResourceOptions.GRAPH_TYPE)) .isEqualTo(BlueprintsResourceOptions.GRAPH_TYPE_DEFAULT); assertThat(getKeyCount(configuration)).isEqualTo(3); // "Too much content in the .properties file" }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.resources.BlueprintsResourceSaveTest.java
@Test public void testSaveGraphResourceNoOption() throws IOException, ConfigurationException { resource.save(Collections.EMPTY_MAP); File configFile = new File(testFilePath + configFileName); assert configFile.exists() : "Config file does not exist"; PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assert configuration.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); assert configuration.getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE) .equals(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE_DEFAULT); assert getKeyCount(configuration) == 3 : "Too much content in the .properties file"; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.resources.BlueprintsResourceSaveTest.java
@SuppressWarnings("unchecked") @Test//from ww w . j a v a2 s . co m public void testSaveGraphResourceDefaultGraphTypeOption() throws IOException, ConfigurationException { options.put(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE, BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE_DEFAULT); resource.save(options); File configFile = new File(testFilePath + configFileName); assert configFile.exists() : "Config file does not exist"; PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assert configuration.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); assert configuration.getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE) .equals(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE_DEFAULT); assert getKeyCount(configuration) == 3 : "Too much content in the .properties file"; }
From source file:fr.inria.atlanmod.neoemf.data.AbstractPersistenceBackendFactory.java
/** * Creates and saves the NeoEMF configuration. * * @param directory the directory where the configuration must be stored. */// ww w . j av a2s . com protected void processGlobalConfiguration(File directory) throws InvalidDataStoreException { PropertiesConfiguration configuration; Path path = Paths.get(directory.getAbsolutePath()).resolve(CONFIG_FILE); try { configuration = new PropertiesConfiguration(path.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!configuration.containsKey(BACKEND_PROPERTY)) { configuration.setProperty(BACKEND_PROPERTY, getName()); } try { configuration.save(); NeoLogger.debug("Configuration stored at " + path); } catch (ConfigurationException e) { /* * Unable to save configuration. * Supposedly it's a minor error, so we log it without rising an exception. */ NeoLogger.warn(e); } }
From source file:com.mirth.connect.server.controllers.tests.TestUtils.java
public static Properties getSqlProperties() { PropertiesConfiguration mirthProperties = new PropertiesConfiguration(); try {/*from w w w . ja v a 2 s . c o m*/ InputStream is = ResourceUtil.getResourceStream(SqlSession.class, "mirth.properties"); mirthProperties.setDelimiterParsingDisabled(true); mirthProperties.load(is); IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); return null; } Properties donkeyProperties = new Properties(); donkeyProperties.setProperty("database.driver", mirthProperties.getString("database.driver")); donkeyProperties.setProperty("database.url", mirthProperties.getString("database.url")); donkeyProperties.setProperty("database.username", mirthProperties.getString("database.username")); if (mirthProperties.containsKey("database.password")) { donkeyProperties.setProperty("database.password", mirthProperties.getString("database.password")); } return donkeyProperties; }
From source file:fr.inria.atlanmod.neoemf.map.datastore.MapPersistenceBackendFactory.java
@Override public PersistenceBackend createPersistentBackend(File file, Map<?, ?> options) throws InvalidDataStoreException { File dbFile = FileUtils.getFile( NeoMapURI.createNeoMapURI(URI.createFileURI(file.getAbsolutePath()).appendSegment("neoemf.mapdb")) .toFileString());/*from w w w .j a va 2 s . c o m*/ if (!dbFile.getParentFile().exists()) { dbFile.getParentFile().mkdirs(); } PropertiesConfiguration neoConfig = null; Path neoConfigPath = Paths.get(file.getAbsolutePath()).resolve(NEO_CONFIG_FILE); try { neoConfig = new PropertiesConfiguration(neoConfigPath.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!neoConfig.containsKey(BACKEND_PROPERTY)) { neoConfig.setProperty(BACKEND_PROPERTY, MAPDB_BACKEND); } if (neoConfig != null) { try { neoConfig.save(); } catch (ConfigurationException e) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, e); } } Engine mapEngine = DBMaker.newFileDB(dbFile).cacheLRUEnable().mmapFileEnableIfSupported().asyncWriteEnable() .makeEngine(); return new MapPersistenceBackend(mapEngine); }
From source file:net.sf.zekr.engine.audio.RecitationPackConverter.java
public static AudioData convert(File oldRecitationPack) throws IOException, ConfigurationException { PropertiesConfiguration props = ConfigUtils.loadConfig(oldRecitationPack, "UTF-8"); AudioData ad = new AudioData(); ad.id = props.getString("audio.id"); if (StringUtils.isBlank(ad.id)) { logger.debug("audio.id cannot be null or empty"); return null; }/*from w w w. j ava2s .c o m*/ ad.id += "-converted"; ad.version = "0.7.5"; ad.lastUpdate = props.getString("audio.lastUpdate"); ad.quality = "?"; ad.name = props.getString("audio.name"); if (StringUtils.isBlank(ad.id)) { logger.debug("audio.name cannot be null or empty"); return null; } ad.name += " (converted)"; ad.license = props.getString("audio.license"); ad.locale = new Locale(props.getString("audio.language"), props.getString("audio.country")); String fileName = props.getString("audio.fileName"); fileName = StringUtils.replace(fileName, "{SURA}", "%1$03d"); fileName = StringUtils.replace(fileName, "{AYA}", "%2$03d"); String baseUrl = props.getString("audio.baseUrl"); if (StringUtils.isBlank(baseUrl)) { logger.debug("audio.baseUrl cannot be null or empty"); return null; } baseUrl = StringUtils.replace(baseUrl, "%", "%%"); String path; if (props.containsKey("audio.serverUrl")) { ad.type = "online"; String serverUrl = props.getString("audio.serverUrl"); path = serverUrl + "/" + baseUrl + "/"; ad.onlineUrl = path + fileName; if (props.containsKey("audio.prestartFileName")) { ad.onlineAudhubillah = path + props.getString("audio.prestartFileName"); } if (props.containsKey("audio.startFileName")) { ad.onlineBismillah = path + props.getString("audio.startFileName"); } if (props.containsKey("audio.endFileName")) { ad.onlineSadaghallah = path + props.getString("audio.endFileName"); } } else { ad.type = "offline"; baseUrl = StringUtils.replace(baseUrl, "[base]", "<base>"); baseUrl = StringUtils.replace(baseUrl, "[workspace]", "<workspace>"); baseUrl = StringUtils.replace(baseUrl, "[w_b]", "<workspace_base>"); path = baseUrl + "/"; ad.offlineUrl = path + fileName; if (props.containsKey("audio.prestartFileName")) { ad.offlineAudhubillah = path + props.getString("audio.prestartFileName"); } if (props.containsKey("audio.startFileName")) { ad.offlineBismillah = path + props.getString("audio.startFileName"); } if (props.containsKey("audio.endFileName")) { ad.offlineSadaghallah = path + props.getString("audio.endFileName"); } } return ad; }