List of usage examples for org.apache.commons.configuration FileConfiguration setProperty
void setProperty(String key, Object value);
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();//from ww w . j ava 2 s . co m notifyIObservers(this, value); }
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 w w.ja v a2s .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.util.persistence.LocalParametersTest.java
/** * Test adding properties to a configuration. * /*from w w w.j a v a 2s.c o 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:gda.jython.authoriser.FileAuthoriser.java
/** * Adds an entry to the file//from ww w.j ava2s .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:net.sourceforge.jukebox.model.Profile.java
/** * Save the contents to configuration file. * @param configuration Configuration file * @throws ConfigurationException Configuration Exception *//*from w w w . j a v a 2 s .c o 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:com.manydesigns.portofino.actions.admin.SettingsAction.java
@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY) public Resolution update() { setupFormAndBean();// w w w . j a v a 2 s . c o m form.readFromRequest(context.getRequest()); if (form.validate()) { logger.debug("Applying settings to model"); try { FileConfiguration fileConfiguration = (FileConfiguration) configuration; Settings settings = new Settings(); form.writeToObject(settings); fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName); fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage); fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage); if (!settings.preloadGroovyPages || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) { fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES, settings.preloadGroovyPages); } if (!settings.preloadGroovyClasses || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) { fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES, settings.preloadGroovyClasses); } fileConfiguration.save(); logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath()); } catch (Exception e) { logger.error("Configuration not saved", e); SessionMessages .addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved")); return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp"); } SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully")); return new RedirectResolution(this.getClass()); } else { return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp"); } }
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();/*from ww w . jav a 2 s.c o m*/ 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.persistence.LocalParametersTest.java
public void testThreadSafety() throws Exception { final File testScratchDir = TestUtils.createClassScratchDirectory(LocalParametersTest.class); final String configDir = testScratchDir.getAbsolutePath(); final String configName = "threadsafety"; // Delete config from disk, if it exists final File configFile = new File(configDir, configName + ".xml"); configFile.delete();//from w w w .j ava 2 s . co m final AtomicReference<Exception> error = new AtomicReference<Exception>(); final int numThreads = 4; final long threadRunTimeInMs = 5000; final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch finishLatch = new CountDownLatch(numThreads); for (int i = 0; i < numThreads; i++) { Thread t = new Thread() { @Override public void run() { try { final FileConfiguration config = LocalParameters.getThreadSafeXmlConfiguration(configDir, configName, true); // Wait for signal to start startLatch.await(); final String propertyName = Thread.currentThread().getName(); final long startTime = System.currentTimeMillis(); while (true) { // Finish if we've exceeded the run time long elapsedTime = System.currentTimeMillis() - startTime; if (elapsedTime >= threadRunTimeInMs) { break; } // Finish if another thread has generated an exception if (error.get() != null) { break; } config.setProperty(propertyName, System.currentTimeMillis()); config.save(); } } catch (Exception e) { e.printStackTrace(System.err); error.set(e); } finishLatch.countDown(); } }; t.start(); } // Start all threads final long startTime = System.currentTimeMillis(); startLatch.countDown(); // Wait for all threads to finish finishLatch.await(); final long endTime = System.currentTimeMillis(); final long elapsedTime = (endTime - startTime); System.out.printf("Finished after %dms%n", elapsedTime); // No error should have been thrown assertNull("An exception was thrown by one of the threads", error.get()); }
From source file:openlr.mapviewer.coding.ui.ApplyChangesListener.java
/** * Applies the current values of the properties form to the properties * holder of the current application runtime. *///from www . j a v a 2 s.c o m void applyChanges() { FileConfiguration config = propsHolder.getProperties(type); for (Map.Entry<String, JTextComponent> entry : optionsTextFields.entrySet()) { JTextComponent textComponent = entry.getValue(); String text = textComponent.getText(); config.setProperty(entry.getKey(), text); propsHolder.setProperties(type, config); textComponent.setBorder(STANDARD_TEXT_BOX_BORDER); } }
From source file:org.parosproxy.paros.view.AbstractFrame.java
private void storeLocation() { if (frameName == null) { return;/*from ww w . j av a 2s .c o m*/ } FileConfiguration config = loadConfig(); String configName = "ui." + frameName; Point location = getLocation(); config.setAutoSave(true); config.setProperty(configName + PROP_LEFT, Integer.toString(location.x)); config.setProperty(configName + PROP_TOP, Integer.toString(location.y)); config.setProperty(configName + PROP_WIDTH, Integer.toString(getWidth())); config.setProperty(configName + PROP_HEIGHT, Integer.toString(getHeight())); try { config.save(); } catch (ConfigurationException e) { e.printStackTrace(); } System.out.println("STORE " + frameName + " " + location.x + " " + location.y + " " + getWidth() + " " + getHeight()); }