Java Code Examples for org.apache.commons.configuration2.PropertiesConfiguration#setProperty()
The following examples show how to use
org.apache.commons.configuration2.PropertiesConfiguration#setProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether auto save mode works. */ @Test public void testAutoSave() throws ConfigurationException { final File file = createTestFile(0); final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class) .configure(new FileBasedBuilderParametersImpl() .setFile(file)); assertFalse("Wrong auto save flag", builder.isAutoSave()); builder.setAutoSave(true); assertTrue("Auto save not enabled", builder.isAutoSave()); builder.setAutoSave(true); // should have no effect final PropertiesConfiguration config = builder.getConfiguration(); config.setProperty(PROP, 1); checkSavedConfig(file, 1); }
Example 2
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests that the auto save mechanism survives a reset of the builder's * configuration. */ @Test public void testAutoSaveWithReset() throws ConfigurationException { final File file = createTestFile(0); final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class) .configure(new FileBasedBuilderParametersImpl() .setFile(file)); final PropertiesConfiguration config1 = builder.getConfiguration(); builder.setAutoSave(true); builder.resetResult(); final PropertiesConfiguration config2 = builder.getConfiguration(); assertNotSame("No new configuration created", config1, config2); config2.setProperty(PROP, 1); config1.setProperty(PROP, 2); checkSavedConfig(file, 1); }
Example 3
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether auto save mode can be disabled again. */ @Test public void testDisableAutoSave() throws ConfigurationException { final File file = createTestFile(0); final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class) .configure(new FileBasedBuilderParametersImpl() .setFile(file)); final PropertiesConfiguration config = builder.getConfiguration(); builder.setAutoSave(true); config.setProperty(PROP, 1); builder.setAutoSave(false); config.setProperty(PROP, 2); builder.setAutoSave(false); // should have no effect checkSavedConfig(file, 1); }
Example 4
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether auto save mode works with a properties configuration. * This is related to CONFIGURATION-646. */ @Test public void testAutoSaveWithPropertiesConfiguration() throws ConfigurationException, IOException { final File file = folder.newFile(); final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class) .configure(new FileBasedBuilderParametersImpl() .setFile(file)); builder.setAutoSave(true); final PropertiesConfiguration config = builder.getConfiguration(); config.setProperty(PROP, 1); checkSavedConfig(file, 1); }
Example 5
Source File: SettingsConfiguration.java From Getaviz with Apache License 2.0 | 5 votes |
private static void loadConfig(HttpServletRequest request) { config = new PropertiesConfiguration(); Enumeration<String> parameters = request.getParameterNames(); while(parameters.hasMoreElements()) { String parameter = parameters.nextElement(); config.setProperty(parameter, request.getParameter(parameter)); } new File(instance.getOutputPath()).mkdirs(); }
Example 6
Source File: SchAdmin.java From datacollector with Apache License 2.0 | 5 votes |
/** * Update dpm.properties file with new configuration. */ private static void updateDpmProperties(Context context, String dpmBaseURL, List<String> labels, boolean enableSch) { if(context.skipUpdatingDpmProperties) { return; } try { FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(new Parameters().properties() .setFileName(context.runtimeInfo.getConfigDir() + "/dpm.properties") .setThrowExceptionOnMissing(true) .setListDelimiterHandler(new DefaultListDelimiterHandler(';')) .setIncludesAllowed(false)); PropertiesConfiguration config; config = builder.getConfiguration(); config.setProperty(RemoteSSOService.DPM_ENABLED, Boolean.toString(enableSch)); config.setProperty(RemoteSSOService.DPM_BASE_URL_CONFIG, dpmBaseURL); config.setProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG, APP_TOKEN_FILE_PROP_VAL); if (labels != null && labels.size() > 0) { config.setProperty(RemoteEventHandlerTask.REMOTE_JOB_LABELS, StringUtils.join(labels, ',')); } else { config.setProperty(RemoteEventHandlerTask.REMOTE_JOB_LABELS, ""); } builder.save(); } catch (ConfigurationException e) { throw new RuntimeException(Utils.format("Updating dpm.properties file failed: {}", e.getMessage()), e); } }
Example 7
Source File: SX.java From SikuliNG with MIT License | 5 votes |
private static void mergeExtraOptions(PropertiesConfiguration baseOptions, PropertiesConfiguration extraOptions) { if (isNull(extraOptions) || extraOptions.size() == 0) { return; } trace("loadOptions: have to merge extra Options"); Iterator<String> allKeys = extraOptions.getKeys(); while (allKeys.hasNext()) { String key = allKeys.next(); if ("sxversion".equals(key)) { baseOptions.setProperty("sxversion_saved", extraOptions.getProperty(key)); continue; } if ("sxbuild".equals(key)) { baseOptions.setProperty("sxbuild_saved", extraOptions.getProperty(key)); continue; } Object value = baseOptions.getProperty(key); if (isNull(value)) { baseOptions.addProperty(key, extraOptions.getProperty(key)); trace("Option added: %s", key); } else { Object extraValue = extraOptions.getProperty(key); if (!value.getClass().getName().equals(extraValue.getClass().getName()) || !value.toString().equals(extraValue.toString())) { baseOptions.setProperty(key, extraValue); trace("Option changed: %s = %s", key, extraValue); } } } }
Example 8
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests whether the managed configuration can be saved. */ @Test public void testSave() throws ConfigurationException { final File file = createTestFile(1); final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class) .configure(new FileBasedBuilderParametersImpl() .setFile(file)); final PropertiesConfiguration config = builder.getConfiguration(); config.setProperty(PROP, 5); builder.save(); checkSavedConfig(file, 5); }
Example 9
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests whether a new configuration can be saved to a file. */ @Test public void testSaveNewFile() throws ConfigurationException, IOException { final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class); final PropertiesConfiguration config = builder.getConfiguration(); config.setProperty(PROP, 2); final File file = folder.newFile(); builder.getFileHandler().setFile(file); builder.save(); checkSavedConfig(file, 2); }