List of usage examples for org.apache.commons.configuration FileConfiguration addProperty
void addProperty(String key, Object value);
From source file:gda.util.userOptions.UserOptions.java
/** * @param configDir/*www . ja va 2 s . c om*/ * @param configName * @throws ConfigurationException * @throws IOException * @throws Exception */ public void saveValuesToConfig(String configDir, String configName) throws ConfigurationException, IOException, Exception { FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, true, true); //after clear we need to save and then reload to ensure all items are removed config.clear(); config.save(); config = LocalParameters.getXMLConfiguration(configDir, configName, true, true); config.addProperty(propTitle, title); Integer index = 0; Iterator<Map.Entry<String, UserOption>> iter = entrySet().iterator(); while (iter.hasNext()) { try { String tag = "options.option(" + index + ")."; Map.Entry<String, UserOption> entry = iter.next(); config.addProperty(tag + propKeyName, entry.getKey()); config.addProperty(tag + propValue, entry.getValue().value); index++; } catch (Exception ex) { throw new Exception("Error saving " + index, ex); } } config.save(); }
From source file:gda.util.userOptions.UserOptions.java
/** * @param configDir/*from w w w. ja v a 2 s .c om*/ * @param configName * @throws ConfigurationException * @throws IOException * @throws Exception */ public void saveToTemplate(String configDir, String configName) throws ConfigurationException, IOException, Exception { FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, true, true); //after clear we need to save and then reload to ensure all items are removed config.clear(); config.save(); config = LocalParameters.getXMLConfiguration(configDir, configName, true, true); config.addProperty(propTitle, title); Integer index = 0; Iterator<Map.Entry<String, UserOption>> iter = entrySet().iterator(); while (iter.hasNext()) { UserOption option = null; try { String tag = "options.option(" + index + ")."; Map.Entry<String, UserOption> entry = iter.next(); option = entry.getValue(); config.addProperty(tag + propKeyName, entry.getKey()); if (option.defaultValue instanceof Boolean) { config.addProperty(tag + propType, typeBoolean); } else if (option.defaultValue instanceof String) { config.addProperty(tag + propType, typeString); } else if (option.defaultValue instanceof Double) { config.addProperty(tag + propType, typeDouble); } else if (option.defaultValue instanceof Integer) { config.addProperty(tag + propType, typeInteger); } config.addProperty(tag + propDesc, option.description); config.addProperty(tag + propDefValue, option.defaultValue); index++; } catch (Exception ex) { throw new Exception("Error reading saving " + index + ".", ex); } } config.save(); }