List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration getString
@Override public String getString(final String key)
From source file:com.vmware.loginsightapi.Configuration.java
/** * Builds the Configuration object from the properties file (apache commons * properties file format). <br>//from w w w .ja v a2 s. co m * The values provided in the config file will be overwritten environment * variables (if present) * * List of the properties <br> * loginsight.host = host name <br> * loginsight.port = port number <br> * loginsight.user = User name <br> * loginsight.password = password <br> * loginsight.ingestion.agentId = agentId <br> * loginsight.connection.scheme = http protocol scheme <br> * loginsight.ingestion.port = Ingestion port number <br> * * @param configFileName * Name of the config file to read * @return Newly created Configuration object */ public static Configuration buildFromConfig(String configFileName) { try { List<FileLocationStrategy> subs = Arrays.asList(new ProvidedURLLocationStrategy(), new FileSystemLocationStrategy(), new ClasspathLocationStrategy()); FileLocationStrategy strategy = new CombinedLocationStrategy(subs); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>( PropertiesConfiguration.class).configure( new Parameters().fileBased().setLocationStrategy(strategy).setFileName(configFileName)); PropertiesConfiguration propConfig = builder.getConfiguration(); Map<String, String> propMap = new HashMap<String, String>(); Iterator<String> keys = propConfig.getKeys(); keys.forEachRemaining(key -> { logger.info(key + ":" + propConfig.getString(key)); propMap.put(key, propConfig.getString(key)); }); Configuration config = Configuration.buildConfig(propMap); config.loadFromEnv(); return config; } catch (ConfigurationException e1) { throw new RuntimeException("Unable to load config", e1); } }
From source file:com.smartmarmot.dbforbix.config.Config.java
/** * Reads the configuration from a properties file * /*from w w w. ja va2 s . c o m*/ * @throws IOException */ public void readFileConfig() throws IOException, NullPointerException { LOG.debug("Parsing config file: " + configFile); calculateFileConfigHash(); try (FileReader reader = new FileReader(configFile)) { PropertiesConfiguration pcfg = new PropertiesConfiguration(); pcfg.read(reader); if (pcfg.containsKey(SET_PERSISTENCETYPE)) persistenceType = pcfg.getString(SET_PERSISTENCETYPE); if (pcfg.containsKey(SET_PERSISTENCEDIR)) persistenceDir = pcfg.getString(SET_PERSISTENCEDIR); if (pcfg.containsKey(SET_UPDATECONFIG)) setUpdateConfigTimeout(pcfg.getInt(SET_UPDATECONFIG)); if (pcfg.containsKey(SET_POOL_MAXACTIVE)) maxActive = pcfg.getInt(SET_POOL_MAXACTIVE); if (pcfg.containsKey(SET_POOL_MAXIDLE)) maxIdle = pcfg.getInt(SET_POOL_MAXIDLE); if (pcfg.containsKey(SET_LOGIN_TIMEOUT)) loginTimeout = Integer.parseInt(pcfg.getString(SET_LOGIN_TIMEOUT)); Iterator<?> it; it = pcfg.getKeys(GLOBAL_ZBXSRV); while (it.hasNext()) { String key = it.next().toString(); String[] keyparts = key.split("\\."); if (keyparts.length == 3) readConfigZSRV(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key)); } it = pcfg.getKeys(GLOBAL_DB); while (it.hasNext()) { String key = it.next().toString(); String[] keyparts = key.split("\\."); if (keyparts.length == 3) readConfigDB(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key)); } } catch (ConfigurationException e) { throw new IOException("Error in configuration: " + e.getLocalizedMessage(), e); } }
From source file:com.sikulix.core.SX.java
private static void setOptions(PropertiesConfiguration someOptions) { if (isNull(someOptions) || someOptions.size() == 0) { return;/*from w w w.j a v a 2 s .c o m*/ } Iterator<String> allKeys = someOptions.getKeys(); List<String> sxSettings = new ArrayList<>(); while (allKeys.hasNext()) { String key = allKeys.next(); if (key.startsWith("Settings.")) { sxSettings.add(key); continue; } trace("!setOptions: %s = %s", key, someOptions.getProperty(key)); } if (sxSettings.size() > 0) { Class cClass = null; try { cClass = Class.forName("org.sikuli.basics.Settings"); } catch (ClassNotFoundException e) { error("!setOptions: %s", cClass); } if (!isNull(cClass)) { for (String sKey : sxSettings) { String sAttr = sKey.substring("Settings.".length()); Field cField = null; Class ccField = null; try { cField = cClass.getField(sAttr); ccField = cField.getType(); if (ccField.getName() == "boolean") { cField.setBoolean(null, someOptions.getBoolean(sKey)); } else if (ccField.getName() == "int") { cField.setInt(null, someOptions.getInt(sKey)); } else if (ccField.getName() == "float") { cField.setFloat(null, someOptions.getFloat(sKey)); } else if (ccField.getName() == "double") { cField.setDouble(null, someOptions.getDouble(sKey)); } else if (ccField.getName() == "String") { cField.set(null, someOptions.getString(sKey)); } trace("!setOptions: %s = %s", sAttr, someOptions.getProperty(sKey)); someOptions.clearProperty(sKey); } catch (Exception ex) { error("!setOptions: %s = %s", sKey, sxOptions.getProperty(sKey)); } } } } }
From source file:org.exist.launcher.LauncherWrapper.java
protected void getVMOpts(List<String> args, PropertiesConfiguration vmProperties) { for (final Iterator<String> i = vmProperties.getKeys(); i.hasNext();) { final String key = i.next(); if (key.startsWith("memory.")) { if ("memory.max".equals(key)) { args.add("-Xmx" + vmProperties.getString(key) + 'm'); } else if ("memory.min".equals(key)) { args.add("-Xms" + vmProperties.getString(key) + 'm'); }// w ww .j a va 2 s .c o m } else if ("vmoptions".equals(key)) { args.add(vmProperties.getString(key)); } else if (key.startsWith("vmoptions.")) { final String os = key.substring("vmoptions.".length()).toLowerCase(); if (OS.contains(os)) { final String value = vmProperties.getString(key); Arrays.stream(value.split("\\s+")).forEach(args::add); } } } }
From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java
public static Map<String, String> getBagitInfo(Path metadataPath) { Map<String, String> metadataList = new HashMap<>(); try {//from ww w.ja v a2 s . c o m PropertiesConfiguration config = new Configurations().properties(metadataPath.toFile()); Iterator<String> keys = config.getKeys(); while (keys.hasNext()) { String key = keys.next(); metadataList.put(key, config.getString(key)); } } catch (ConfigurationException e) { LOGGER.error("Could not load properties with bagit metadata", e); } return metadataList; }
From source file:org.talend.dataprep.encrypt.PropertiesEncryption.java
/** * Applies the specified function to the specified set of parameters contained in the input file. * * @param input The specified name of file to encrypt * @param mustBeModified the specified set of parameters * @param function the specified function to apply to the set of specified parameters *//*from www .jav a2 s . c om*/ private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) { Path inputFilePath = Paths.get(input); if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = // new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) // .configure(params.fileBased() // .setFile(inputFilePath.toFile())); // PropertiesConfiguration config = builder.getConfiguration(); for (String key : mustBeModified) { config.setProperty(key, function.apply(config.getString(key))); } builder.save(); } catch (ConfigurationException e) { LOGGER.error("unable to read {} {}", input, e); } } else { LOGGER.debug("No readable file at {}", input); } }