List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration addProperty
@Override public final void addProperty(final String key, final Object value)
From source file:com.sikulix.core.SX.java
private static void mergeExtraOptions(PropertiesConfiguration baseOptions, PropertiesConfiguration extraOptions) { trace("loadOptions: have to merge extra Options"); if (isNull(extraOptions) || extraOptions.size() == 0) { return;/*ww w .j ava2 s. c om*/ } Iterator<String> allKeys = extraOptions.getKeys(); while (allKeys.hasNext()) { String key = allKeys.next(); if (isNull(baseOptions.getProperty(key))) { baseOptions.addProperty(key, extraOptions.getProperty(key)); trace("Option added: %s", key); } else { baseOptions.addProperty(key, extraOptions.getProperty(key)); trace("Option changed: %s", key); } } }
From source file:org.dspace.servicemanager.config.DSpaceConfigurationServiceTest.java
/** * Tests the ability of our ConfigurationService to automatically reload properties after a set period * of time./*from w ww .j ava2 s.c o m*/ */ @Test public void testAutomaticReload() throws ConfigurationException, InterruptedException { // Initialize new config service DSpaceConfigurationService dscs = new DSpaceConfigurationService(); // Assert a property exists with a specific initial value assertNotNull(dscs.getProperty("prop.to.auto.reload")); assertEquals("D-space", dscs.getProperty("prop.to.auto.reload")); // Now, change the value of that Property in the file itself (using a separate builder instance) FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new Configurations() .propertiesBuilder(propertyFilePath); PropertiesConfiguration config = builder.getConfiguration(); // Clear out current value. Add in a new value config.clearProperty("prop.to.auto.reload"); config.addProperty("prop.to.auto.reload", "DSpace"); // Save updates to file builder.save(); // Check immediately. Property should be unchanged // NOTE: If this fails, then somehow the configuration reloaded *immediately* assertEquals("D-space", dscs.getProperty("prop.to.auto.reload")); // Wait now for 3 seconds Thread.sleep(3_000); // Check again. Property should have reloaded // NOTE: reload time is set in config-definition.xml to reload every 2 seconds assertEquals("DSpace", dscs.getProperty("prop.to.auto.reload")); }
From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java
public static IPDescriptiveMetadata createBagitMetadata(Map<String, String> metadata, List<String> ancestors, Path metadataPath) {/*from www. j av a2 s. c om*/ try { FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new Configurations() .propertiesBuilder(metadataPath.toFile()); Files.createFile(metadataPath); PropertiesConfiguration config = builder.getConfiguration(); for (Entry<String, String> entry : metadata.entrySet()) { config.setProperty(entry.getKey(), entry.getValue()); } for (String ancestor : ancestors) { config.addProperty(IPConstants.BAGIT_PARENT, ancestor); } builder.save(); } catch (IOException | ConfigurationException e) { LOGGER.error("Could not save bagit metadata content on file", e); } return new IPDescriptiveMetadata(metadataPath.getFileName().toString(), new IPFile(metadataPath), new MetadataType(BAGIT), ""); }