use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.
the class XYZFilter method readPBC.
/**
* Attempt to parse the String as unit cell parameters.
*
* @param data The String to parse.
*
* @return false if the first token in the String is an integer and true
* otherwise.
*/
private static boolean readPBC(String data, MolecularAssembly activeMolecularAssembly) {
if (firstTokenIsInteger(data)) {
return false;
}
String[] tokens = data.trim().split(" +");
if (tokens != null && tokens.length == 6) {
CompositeConfiguration config = activeMolecularAssembly.getProperties();
double a = Double.parseDouble(tokens[0]);
double b = Double.parseDouble(tokens[1]);
double c = Double.parseDouble(tokens[2]);
double alpha = Double.parseDouble(tokens[3]);
double beta = Double.parseDouble(tokens[4]);
double gamma = Double.parseDouble(tokens[5]);
config.setProperty("a-axis", a);
config.setProperty("b-axis", b);
config.setProperty("c-axis", c);
config.setProperty("alpha", alpha);
config.setProperty("beta", beta);
config.setProperty("gamma", gamma);
Crystal crystal = activeMolecularAssembly.getCrystal();
if (crystal != null) {
crystal.changeUnitCellParameters(a, b, c, alpha, beta, gamma);
}
}
return true;
}
use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.
the class ForceFieldFilter method main.
/**
* Parse a Force Field parameter file and echo the results with slashes.
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
public static void main(String[] args) throws Exception {
if (args == null || args.length < 1) {
System.out.println("Usage: ForceFieldFilter <file.prm>");
System.exit(-1);
}
CompositeConfiguration properties = Keyword.loadProperties(null);
properties.setProperty("parameters", args[0]);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
if (forceField != null) {
forceField.print();
}
}
use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.
the class ForceFieldFilterTest method testParse.
/**
* Test of parse method, of class ForceFieldFilter.
*/
@Test
public void testParse() {
CompositeConfiguration properties = Keyword.loadProperties(null);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
}
use of org.apache.commons.configuration.CompositeConfiguration in project ninja by ninjaframework.
the class MessagesImpl method loadAllMessageFilesForRegisteredLanguages.
/**
* Does all the loading of message files.
*
* Only registered messages in application.conf are loaded.
*/
private Map<String, Configuration> loadAllMessageFilesForRegisteredLanguages() {
Map<String, Configuration> langToKeyAndValuesMappingMutable = Maps.newHashMap();
// Load default messages:
Configuration defaultLanguage = loadLanguageConfiguration("conf/messages.properties");
// Everything else does not make much sense.
if (defaultLanguage == null) {
throw new RuntimeException("Did not find conf/messages.properties. Please add a default language file.");
} else {
langToKeyAndValuesMappingMutable.put("", defaultLanguage);
}
// Get the languages from the application configuration.
String[] applicationLangs = ninjaProperties.getStringArray(NinjaConstant.applicationLanguages);
// We'll use the default messages.properties file.
if (applicationLangs == null) {
return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable);
}
// Load each language into the HashMap containing the languages:
for (String lang : applicationLangs) {
// First step: Load complete language eg. en-US
Configuration configuration = loadLanguageConfiguration(String.format("conf/messages_%s.properties", lang));
Configuration configurationLangOnly = null;
// Overwritten by the default languages.
if (lang.contains("-")) {
// get the lang
String langOnly = lang.split("-")[0];
// And load the configuraion
configurationLangOnly = loadLanguageConfiguration(String.format("conf/messages_%s.properties", langOnly));
}
// it should be there propably.
if (configuration == null) {
logger.info("Did not find conf/messages_{}.properties but it was specified in application.conf. Using default language instead.", lang);
} else {
// add new language, but combine with default language if stuff
// is missing...
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
// Add eg. "en-US"
compositeConfiguration.addConfiguration(configuration);
// Add eg. "en"
if (configurationLangOnly != null) {
compositeConfiguration.addConfiguration(configurationLangOnly);
}
// Add messages.conf (default pack)
compositeConfiguration.addConfiguration(defaultLanguage);
// and add the composed configuration to the hashmap with the
// mapping.
langToKeyAndValuesMappingMutable.put(lang, (Configuration) compositeConfiguration);
}
}
return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable);
}
use of org.apache.commons.configuration.CompositeConfiguration in project es6draft by anba.
the class Resources method loadConfiguration.
/**
* Loads the configuration file.
*/
public static Configuration loadConfiguration(TestConfiguration config) {
String file = config.file();
String name = config.name();
try {
PropertiesConfiguration properties = new PropertiesConfiguration();
// entries are mandatory unless an explicit default value was given
properties.setThrowExceptionOnMissing(true);
properties.setDelimiterParsingDisabled(true);
properties.getInterpolator().setParentInterpolator(MISSING_VAR);
properties.load(resource(file, Paths.get("")), "UTF-8");
SystemConfiguration systemConfiguration = new SystemConfiguration();
systemConfiguration.setDelimiterParsingDisabled(true);
return new CompositeConfiguration(Arrays.asList(systemConfiguration, properties)).subset(name);
} catch (ConfigurationException | IOException e) {
throw new RuntimeException(e);
} catch (NoSuchElementException e) {
throw e;
}
}
Aggregations