List of usage examples for org.apache.commons.configuration PropertiesConfiguration setProperty
public void setProperty(String key, Object value)
From source file:com.continuent.tungsten.common.security.SecurityHelper.java
/** * Save passwords from a TungstenProperties into a file * /* w ww. j ava 2 s . c o m*/ * @param authenticationInfo containing password file location */ public static void saveCredentialsFromAuthenticationInfo(AuthenticationInfo authenticationInfo) throws ServerRuntimeException { String passwordFileLocation = authenticationInfo.getPasswordFileLocation(); try { String username = authenticationInfo.getUsername(); String password = authenticationInfo.getPassword(); PropertiesConfiguration props = new PropertiesConfiguration(passwordFileLocation); // Use Apache commons-configuration: // preserves comments in .properties // ! props.setProperty(username, password); props.save(); } catch (org.apache.commons.configuration.ConfigurationException ce) { logger.error("Error while saving properties for file:" + authenticationInfo.getPasswordFileLocation(), ce); throw new ServerRuntimeException("Error while saving Credentials: " + ce.getMessage()); } }
From source file:maltcms.ui.fileHandles.properties.tools.PropertyLoader.java
private static Tuple2D<Configuration, Configuration> loadPropertiesFromClass(Class<?> c) { PropertiesConfiguration ret = new PropertiesConfiguration(); PropertiesConfiguration var = new PropertiesConfiguration(); String requiredVariables = ""; String optionalVariables = ""; String providedVariables = ""; Collection<String> reqVars = AnnotationInspector.getRequiredVariables(c); for (String rv : reqVars) { requiredVariables += rv + ","; }/* w w w .java 2 s.c o m*/ if (requiredVariables.length() > 0) { requiredVariables = requiredVariables.substring(0, requiredVariables.length() - 1); } var.setProperty(REQUIRED_VARS, requiredVariables); Collection<String> optVars = AnnotationInspector.getOptionalRequiredVariables(c); for (String rv : optVars) { optionalVariables += rv + ","; } if (optionalVariables.length() > 0) { optionalVariables = optionalVariables.substring(0, optionalVariables.length() - 1); } var.setProperty(OPTIONAL_VARS, optionalVariables); Collection<String> provVars = AnnotationInspector.getProvidedVariables(c); for (String rv : provVars) { providedVariables += rv + ","; } if (providedVariables.length() > 0) { providedVariables = providedVariables.substring(0, providedVariables.length() - 1); } var.setProperty(PROVIDED_VARS, providedVariables); Collection<String> keys = AnnotationInspector.getRequiredConfigKeys(c); if (!keys.isEmpty()) { for (String key : keys) { ret.setProperty(key, AnnotationInspector.getDefaultValueFor(c, key)); } } return new Tuple2D<Configuration, Configuration>(ret, var); }
From source file:eu.optimis.ecoefficiencytool.core.tools.EnergyCreditsManager.java
private static void updateCurrentEmissionsExcess() throws ConfigurationException { PropertiesConfiguration configEnergyCredits = ConfigManager .getPropertiesConfiguration(ConfigManager.ENERGYCREDITS_CONFIG_FILE); double currentExcess = configEnergyCredits.getDouble("exceededEmissions"); if (currentExcess > 0.0) { Iterator euas = configEnergyCredits.getKeys("EUA"); while (euas.hasNext()) { String key = (String) euas.next(); double remainingCredit = configEnergyCredits.getDouble(key); if (currentExcess < remainingCredit) { remainingCredit = remainingCredit - currentExcess; configEnergyCredits.setProperty(key, Double.toString(remainingCredit)); configEnergyCredits.setProperty("exceededEmissions", Double.toString(0.0)); configEnergyCredits.save(); return; } else { currentExcess = currentExcess - remainingCredit; configEnergyCredits.setProperty(key, Double.toString(0.0)); }// w ww. j a v a2 s .com } if (currentExcess > 0.0) { configEnergyCredits.setProperty("exceededEmissions", Double.toString(currentExcess)); } configEnergyCredits.save(); } }
From source file:com.datatorrent.stram.codec.LogicalPlanSerializer.java
public static PropertiesConfiguration convertToProperties(JSONObject json) throws JSONException { PropertiesConfiguration props = new PropertiesConfiguration(); JSONArray allOperators = json.getJSONArray("operators"); JSONArray allStreams = json.getJSONArray("streams"); for (int j = 0; j < allOperators.length(); j++) { JSONObject operatorDetail = allOperators.getJSONObject(j); String operatorName = operatorDetail.getString("name"); String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorName; props.setProperty(operatorKey + ".classname", operatorDetail.getString("class")); JSONObject properties = operatorDetail.optJSONObject("properties"); if (properties != null) { Iterator<String> iter2 = properties.keys(); while (iter2.hasNext()) { String propertyName = iter2.next(); if (!propertyName.equals("name") && !propertyName.equals("class") && properties.opt(propertyName) != null) { JSONArray list = properties.optJSONArray(propertyName); String value = ""; if (list != null) { for (int i = 0; i < list.length(); i++) { if (i != 0) { value += ","; }//from www .j a va 2 s . c o m value += list.get(i).toString(); } props.setProperty(operatorKey + "." + propertyName, value); } else { props.setProperty(operatorKey + "." + propertyName, properties.get(propertyName)); } } } } } for (int j = 0; j < allStreams.length(); j++) { JSONObject streamDetail = allStreams.getJSONObject(j); String streamName = streamDetail.getString("name"); String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamName; JSONObject sourceDetail = streamDetail.getJSONObject("source"); JSONArray sinksList = streamDetail.getJSONArray("sinks"); props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, sourceDetail.getString("operatorName") + "." + sourceDetail.getString("portName")); String sinksValue = ""; for (int i = 0; i < sinksList.length(); i++) { if (!sinksValue.isEmpty()) { sinksValue += ","; } sinksValue += sinksList.getJSONObject(i).getString("operatorName") + "." + sinksList.getJSONObject(i).getString("portName"); } props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue); String locality = streamDetail.optString("locality", null); if (locality != null) { props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, Locality.valueOf(locality)); } } // TBD: Attributes return props; }
From source file:com.bluelotussoftware.example.apache.commons.Application.java
/** * <p>Sets a property called <code>colors.background</code> to the value provided, or assigns a color * value{@literal #000000} if none is provided .</p> * @param backgroundColor/* w ww . j a va 2 s .c om*/ * @throws ConfigurationException if an <code>Exception</code> is encountered. */ public void setBackground(String backgroundColor) throws ConfigurationException { PropertiesConfiguration config = ConfigManager.instance().getConfig(); if (backgroundColor == null) { config.setProperty("colors.background", "#000000"); } else { config.setProperty("colors.background", backgroundColor); } config.save(PROPERTIES_FILE_NAME); }
From source file:com.nesscomputing.config.TestPrefix.java
@Test public void testOverride() { Assert.assertThat(cfg, is(notNullValue())); PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setProperty("prefix.of.three.string-null-value", "NULL"); pc.setProperty("prefix.of.three.string-value", "another test value"); Config c2 = Config.getOverriddenConfig(cfg, pc); final Configuration config = c2.getConfiguration("prefix.of.three"); Assert.assertThat(config, is(notNullValue())); final String s_cfg1 = config.getString("string-null-value"); Assert.assertThat(s_cfg1, is("NULL")); final String s_cfg2 = config.getString("string-value"); Assert.assertThat(s_cfg2, is("another test value")); }
From source file:dk.dma.ais.abnormal.analyzer.AbnormalAnalyzerAppTestModule.java
@Provides @Singleton/*from w ww.j a v a2s . co m*/ Configuration provideConfiguration() { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.setProperty(CONFKEY_ANALYSIS_DRIFT_PERIOD, 10); configuration.setProperty(CONFKEY_ANALYSIS_DRIFT_DISTANCE, 500); configuration.setProperty(CONFKEY_ANALYSIS_DRIFT_SOG_MIN, 1); configuration.setProperty(CONFKEY_ANALYSIS_DRIFT_SOG_MAX, 5); configuration.setProperty(CONFKEY_ANALYSIS_DRIFT_COGHDG, 45); return configuration; }
From source file:com.nesscomputing.config.TestPrefix.java
@Test public void testSystemStillWins() { Assert.assertThat(cfg, is(notNullValue())); PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setProperty("prefix.of.three.string-null-value", "NULL"); pc.setProperty("prefix.of.three.string-value", "another test value"); PropertiesSaver ps = new PropertiesSaver("prefix.of.three.string-value"); try {/*from w w w. j a v a 2 s . c o m*/ System.setProperty("prefix.of.three.string-value", "system-value"); Config c2 = Config.getOverriddenConfig(cfg, pc); final Configuration config = c2.getConfiguration("prefix.of.three"); Assert.assertThat(config, is(notNullValue())); final String s_cfg2 = config.getString("string-value"); Assert.assertThat(s_cfg2, is("system-value")); } finally { ps.apply(); } }
From source file:com.linkedin.pinot.server.api.resources.ResourceTestHelper.java
public void addTable(String tableName) throws IOException, ConfigurationException { File directory = new File(INDEX_DIR, tableName); FileUtils.forceMkdir(directory);//from w w w. j av a 2s . com PropertiesConfiguration tableConfig = new PropertiesConfiguration(); tableConfig.setProperty("directory", tableName); tableConfig.setProperty("name", tableName); tableConfig.setProperty("dataManagerType", "offline"); tableConfig.setProperty("readMode", "heap"); FileBasedInstanceDataManager dataManager = (FileBasedInstanceDataManager) serverInstance .getInstanceDataManager(); dataManager.addTable(new TableDataManagerConfig(tableConfig)); }
From source file:com.impetus.ankush.agent.action.impl.PropertyFileManipulator.java
/** * Edits the conf value.//from w w w .jav a 2 s . c o m * * @param file * the file * @param propertyName * the property name * @param newPropertyValue * the new property value * @return true, if successful */ @Override public boolean editConfValue(String file, String propertyName, String newPropertyValue) { boolean status = false; try { // read conf file File confFile = new File(file); if (!confFile.exists()) { System.err.println("File " + file + " does not exists."); status = false; } PropertiesConfiguration props = new PropertiesConfiguration(file); props.setProperty(propertyName, newPropertyValue); props.getLayout().setSeparator(propertyName, "="); props.save(); status = true; } catch (Exception e) { System.err.println(e.getMessage()); } return status; }