List of usage examples for org.apache.commons.configuration FileConfiguration save
void save() throws ConfigurationException;
From source file:com.manydesigns.elements.configuration.CommonsConfigurationUtils.java
public static void save(Configuration configuration) throws ConfigurationException { FileConfiguration fileConfiguration = getWritableFileConfiguration(configuration); if (fileConfiguration == null) { throw new ConfigurationException("Cannot save configuration"); } else {// www . java 2 s . c o m fileConfiguration.save(); } }
From source file:gda.data.metadata.PersistantMetadataEntry.java
@Override public void setValue(String value) throws Exception { logger.info("Setting PersistantMetadataEntry " + getName() + " to " + value); FileConfiguration config = openConfig(); config.setProperty(getName(), value); config.save(); notifyIObservers(this, value); }
From source file:gda.jython.authoriser.FileAuthoriser.java
/** * Removes an entry from the file//from w w w . ja v a 2 s . c om * * @param username */ public void deleteEntry(String username) { try { FileConfiguration configFile = openConfigFile(); if (configFile.containsKey(username)) { configFile.clearProperty(username); configFile.save(); } } catch (Exception e) { logger.error("Exception while trying to delete an entry from file" + e.getMessage()); } }
From source file:gda.jython.authoriser.FileAuthoriser.java
/** * Adds an entry to the file/*from w w w . j a v a 2 s . c o m*/ * * @param username * @param newLevel * @param isStaff */ public void addEntry(String username, int newLevel, boolean isStaff) { try { FileConfiguration configFile = openConfigFile(); if (!configFile.containsKey(username)) { configFile.setProperty(username, newLevel); configFile.save(); } if (isStaff) { FileConfiguration configFile2 = openStaffFile(); if (!configFile2.containsKey(username)) { configFile2.setProperty(username, newLevel); configFile2.save(); } } } catch (Exception e) { logger.error("Exception while trying to write new entry to file of list of user authorisation levels:" + e.getMessage()); } }
From source file:gda.util.persistence.LocalParametersTest.java
/** * Test adding properties to a configuration. * //w ww. j a v a2 s. co m * @throws Exception */ public void testAddingParameters() throws Exception { FileConfiguration lp = LocalParameters.getXMLConfiguration("newone"); lp.setProperty("gda.a.x", "value gda.a.x"); lp.setProperty("gda.a._11_", "blarghh"); lp.save(); lp.reload(); List<Object> keys = getKeysFromXMLConfiguration(lp); assertTrue(keys.size() == 2 || keys.size() == 3); assertTrue(keys.contains("gda.a.x")); assertTrue(keys.contains("gda.a._11_")); if (keys.size() == 3) { assertTrue(keys.contains("")); } }
From source file:net.sourceforge.jukebox.model.Profile.java
/** * Save the contents to configuration file. * @param configuration Configuration file * @throws ConfigurationException Configuration Exception */// w w w .j a v a2 s . co m public final void save(final FileConfiguration configuration) throws ConfigurationException { String value = this.newPassword + "," + this.userInfo; configuration.setProperty(ADMIN_USERNAME, value); configuration.save(); }
From source file:net.sourceforge.jukebox.model.Settings.java
/** * Save the contents to configuration file. * @param configuration Configuration file * @throws ConfigurationException Configuration Exception *///from w ww .j a v a 2 s .c o m public final void save(final FileConfiguration configuration) throws ConfigurationException { configuration.setProperty(CONTENT_FOLDER, this.contentFolder); configuration.setProperty(PLAYER_URL, this.playerUrl); configuration.setProperty(MODIFIED_DAYS, this.modifiedDays); configuration.save(); }
From source file:gda.data.metadata.PersistantMetadataEntry.java
synchronized private FileConfiguration openConfig() throws ConfigurationException, IOException { // if (config == null) { FileConfiguration config = LocalParameters.getXMLConfiguration("persistantMetadata"); config.reload();// w w w . j a va 2 s. c om if (config.getString(getName()) == null) { logger.warn("No saved entry found for PersistantMetadataEntry named: '" + getName() + "'. Setting it to: '" + getDefaultValue() + "'"); // setValue(getDefaultValue()); config.setProperty(getName(), getDefaultValue()); config.save(); notifyIObservers(this, getDefaultValue()); } // } return config; }
From source file:gda.util.userOptions.UserOptions.java
/** * @param configDir/*from w w w .j a va 2s .c o m*/ * @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/*w w w . jav a 2 s . c o m*/ * @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(); }