use of org.apache.commons.configuration.PropertiesConfiguration in project CloudStack-archive by CloudStack-extras.
the class EncryptionSecretKeyChanger method migrateProperties.
private boolean migrateProperties(File dbPropsFile, Properties dbProps, String newMSKey, String newDBKey) {
System.out.println("Migrating db.properties..");
StandardPBEStringEncryptor msEncryptor = new StandardPBEStringEncryptor();
;
initEncryptor(msEncryptor, newMSKey);
try {
PropertiesConfiguration newDBProps = new PropertiesConfiguration(dbPropsFile);
if (newDBKey != null && !newDBKey.isEmpty()) {
newDBProps.setProperty("db.cloud.encrypt.secret", "ENC(" + msEncryptor.encrypt(newDBKey) + ")");
}
String prop = dbProps.getProperty("db.cloud.password");
if (prop != null && !prop.isEmpty()) {
newDBProps.setProperty("db.cloud.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
}
prop = dbProps.getProperty("db.usage.password");
if (prop != null && !prop.isEmpty()) {
newDBProps.setProperty("db.usage.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
}
newDBProps.save(dbPropsFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
return false;
}
System.out.println("Migrating db.properties Done.");
return true;
}
use of org.apache.commons.configuration.PropertiesConfiguration in project jangaroo-tools by CoreMedia.
the class PropertyClassGeneratorTest method testSimplePropertySet.
@Test
public void testSimplePropertySet() throws Exception {
FileLocations locations = new FileLocations();
List<File> sourcePath = new ArrayList<File>();
sourcePath.add(new File(getClass().getResource("/").toURI()));
locations.setSourcePath(sourcePath);
locations.addSourceFile("testPackage/subPackage/Properties.properties");
locations.addSourceFile("testPackage/PropertiesTest.properties");
locations.addSourceFile("testPackage/PropertiesTest_de.properties");
locations.addSourceFile("testPackage/PropertiesTest_es_ES.properties");
locations.addSourceFile("testPackage/PropertiesTest_it_VA_WIN.properties");
PropertyClassGenerator generator = new PropertyClassGenerator(locations);
StringWriter writer = new StringWriter();
ResourceBundleClass rbc = new ResourceBundleClass("testPackage.PropertiesTest");
PropertiesConfiguration p = new PropertiesConfiguration();
p.setProperty("key", "Die Platte \"{1}\" enthält {0}.");
p.setProperty("key2", "Die Platte \"{1}\" enthält {0}.");
PropertiesClass pc = new PropertiesClass(rbc, null, p, null);
generator.generatePropertiesClass(pc, writer);
assertEquals(("package testPackage {\n" + "import joo.ResourceBundleAwareClassLoader;\n" + "import joo.JavaScriptObject;\n" + "\n" + "/**\n" + " * Properties class for ResourceBundle \"PropertiesTest\".\n" + " * @see PropertiesTest_properties#INSTANCE\n" + " */\n" + "[ResourceBundle('PropertiesTest')]\n" + "public class PropertiesTest_properties extends joo.JavaScriptObject {\n" + "\n" + "/**\n" + " * Singleton for the current user Locale's instance of ResourceBundle \"PropertiesTest\".\n" + " * @see PropertiesTest_properties\n" + " */\n" + "public static const INSTANCE:PropertiesTest_properties = ResourceBundleAwareClassLoader.INSTANCE.createSingleton(PropertiesTest_properties) as PropertiesTest_properties;\n" + "\n" + "[Resource(key='key',bundle='PropertiesTest')]\n" + "public native function get key():String;\n" + "[Resource(key='key2',bundle='PropertiesTest')]\n" + "public native function get key2():String;\n" + "\n" + "public function PropertiesTest_properties() {\n" + " this[\"key\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + " this[\"key2\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "}\n" + "}\n" + "}").replaceAll("\n", LINE_SEPARATOR), writer.toString());
PropertiesClass psc = new PropertiesClass(rbc, Locale.ENGLISH, p, null);
writer = new StringWriter();
generator.generatePropertiesClass(psc, writer);
assertEquals(("package testPackage {\n" + "\n" + "/**\n" + " * Properties class for ResourceBundle \"PropertiesTest\" and Locale \"en\".\n" + " * @see PropertiesTest_properties#INSTANCE\n" + " */\n" + "[ResourceBundle('PropertiesTest_en')]\n" + "public class PropertiesTest_properties_en extends PropertiesTest_properties {\n" + "\n" + "\n" + "public function PropertiesTest_properties_en() {\n" + " this[\"key\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + " this[\"key2\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "}\n" + "}\n" + "}").replaceAll("\n", LINE_SEPARATOR), writer.toString());
}
use of org.apache.commons.configuration.PropertiesConfiguration in project archaius by Netflix.
the class WebApplicationProperties method initApplicationProperties.
protected static void initApplicationProperties() throws ConfigurationException, MalformedURLException {
File appPropFile = new File(appConfFolder + "/" + baseConfigFileName + ".properties");
File appEnvPropOverrideFile = new File(appConfFolder + "/" + baseConfigFileName + getEnvironment() + ".properties");
// TODO awang, how do we add this to archaius default config?
PropertiesConfiguration appConf = new PropertiesConfiguration(appPropFile);
// apply env overrides
PropertiesConfiguration overrideConf = new PropertiesConfiguration(appEnvPropOverrideFile);
Properties overrideprops = ConfigurationUtils.getProperties(overrideConf);
for (Object prop : overrideprops.keySet()) {
appConf.setProperty("" + prop, overrideprops.getProperty("" + prop));
}
String path = appPropFile.toURI().toURL().toString();
System.setProperty(URLConfigurationSource.CONFIG_URL, path);
ConfigurationManager.loadPropertiesFromConfiguration(appConf);
}
use of org.apache.commons.configuration.PropertiesConfiguration in project archaius by Netflix.
the class OverridingPropertiesConfiguration method loadFromPropertiesFile.
static void loadFromPropertiesFile(AbstractConfiguration config, String baseUrl, Set<String> loaded, String... nextLoadKeys) {
String nextLoad = getNextLoad(config, nextLoadKeys);
if (nextLoad == null) {
return;
}
String[] filesToLoad = nextLoad.split(",");
for (String fileName : filesToLoad) {
fileName = fileName.trim();
try {
URL url = new URL(baseUrl + "/" + fileName);
// avoid circle
if (loaded.contains(url.toExternalForm())) {
logger.warn(url + " is already loaded");
continue;
}
loaded.add(url.toExternalForm());
PropertiesConfiguration nextConfig = new OverridingPropertiesConfiguration(url);
copyProperties(nextConfig, config);
logger.info("Loaded properties file " + url);
loadFromPropertiesFile(config, baseUrl, loaded, nextLoadKeys);
} catch (Throwable e) {
logger.warn("Unable to load properties file", e);
}
}
}
use of org.apache.commons.configuration.PropertiesConfiguration in project sakuli by ConSol.
the class SakuliPropertyPlaceholderConfigurer method restoreProperties.
@PreDestroy
public void restoreProperties() {
try {
for (Map.Entry<String, Map<String, Object>> entry : modifiedSahiConfigProps.entrySet()) {
String propFile = entry.getKey();
logger.debug("restore properties file '{}' with properties '{}'", propFile, entry.getValue());
PropertiesConfiguration propConfig = new PropertiesConfiguration(propFile);
propConfig.setAutoSave(true);
for (Map.Entry<String, Object> propEntry : entry.getValue().entrySet()) {
String propKey = propEntry.getKey();
if (propConfig.containsKey(propKey)) {
propConfig.clearProperty(propKey);
}
propConfig.addProperty(propKey, propEntry.getValue());
}
}
} catch (ConfigurationException e) {
logger.error("Error in restore sahi config properties", e);
}
}
Aggregations