Example usage for org.apache.commons.configuration PropertiesConfiguration addProperty

List of usage examples for org.apache.commons.configuration PropertiesConfiguration addProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration addProperty.

Prototype

public void addProperty(String key, Object value) 

Source Link

Document

Adds a new property to this configuration.

Usage

From source file:org.apache.qpid.server.model.adapter.VirtualHostAdapter.java

private VirtualHostConfiguration createVirtualHostConfiguration(String virtualHostName)
        throws ConfigurationException {
    VirtualHostConfiguration configuration;
    String configurationFile = (String) getAttribute(CONFIG_PATH);
    if (configurationFile == null) {
        final MyConfiguration basicConfiguration = new MyConfiguration();
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.addProperty("store.type", (String) getAttribute(STORE_TYPE));
        config.addProperty("store.environment-path", (String) getAttribute(STORE_PATH));
        basicConfiguration.addConfiguration(config);

        CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
        compositeConfiguration.addConfiguration(new SystemConfiguration());
        compositeConfiguration.addConfiguration(basicConfiguration);
        configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration, _broker);
    } else {/*from  ww w.  j  a v a2  s .c om*/
        configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile), _broker);
    }
    return configuration;
}

From source file:org.apache.whirr.karaf.command.support.ConfigurationReader.java

/**
 * Builds the Configuration from Configuration Admin.
 *
 * @param pid/* w  w w.ja  v  a  2 s .c om*/
 * @return
 */
public static PropertiesConfiguration fromConfigAdmin(ConfigurationAdmin configurationAdmin, String pid) {
    List<String> ignoredKeys = Arrays.asList("service.pid", "felix.fileinstall.filename");
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    try {
        Configuration configuration = configurationAdmin.getConfiguration(pid);
        Dictionary properties = configuration.getProperties();
        Enumeration keys = properties.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = properties.get(key);
            if (!ignoredKeys.contains(key)) {
                propertiesConfiguration.addProperty(String.valueOf(key), value);
            }
        }
    } catch (IOException e) {
        System.err.println(String.format("No configuration found for pid:%s.", pid));
        return null;
    }
    return propertiesConfiguration;
}

From source file:org.apache.whirr.service.jclouds.StatementBuilderTest.java

@Test
public void testClusterSpecExports() throws Exception {
    PropertiesConfiguration conf = new PropertiesConfiguration();
    conf.addProperty("ignored", "ignored_value");
    conf.addProperty("whirr.env.fooBar", "my_value");

    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
    clusterSpec.setClusterName("test-cluster");
    clusterSpec.setProvider("test-provider");

    StatementBuilder builder = new StatementBuilder();

    builder.addStatement(Statements.exec("echo $FOO_BAR"));

    String script = builder.name("foo").build(clusterSpec).render(OsFamily.UNIX);

    assertThat(script, containsString("export FOO_BAR="));
    assertThat(script, containsString("my_value"));
    assertThat(script, containsString("echo $FOO_BAR"));
    assertThat(script, not(containsString("ignored")));
}

From source file:org.overlord.dtgov.ui.server.servlets.UiConfigurationServletTest.java

/**
 * Test method for {@link org.overlord.dtgov.ui.server.servlets.UiConfigurationServlet#generateJSONConfig(org.apache.commons.configuration.Configuration)}.
 *///w  w w.  j a  va  2  s  .  c  o m
@Test
public void testGenerateJSONConfig_Configured() throws Exception {
    final PropertiesConfiguration config = new PropertiesConfiguration();
    config.addProperty(DtgovUIConfig.DEPLOYMENT_TYPE_PREFIX + ".switchyard", //$NON-NLS-1$
            "SwitchYard Application:ext/SwitchYardApplication"); //$NON-NLS-1$
    config.addProperty(DtgovUIConfig.DEPLOYMENT_TYPE_PREFIX + ".war", "Web Application:ext/JavaWebApplication"); //$NON-NLS-1$ //$NON-NLS-2$
    config.addProperty(DtgovUIConfig.DEPLOYMENT_CLASSIFIER_STAGE_PREFIX + ".dev", //$NON-NLS-1$
            "Development:http://www.jboss.org/overlord/deployment-status.owl#Dev"); //$NON-NLS-1$
    config.addProperty(DtgovUIConfig.DEPLOYMENT_CLASSIFIER_STAGE_PREFIX + ".prod", //$NON-NLS-1$
            "Production:http://www.jboss.org/overlord/deployment-status.owl#Prod"); //$NON-NLS-1$
    HttpServletRequest request = new MockHttpServletRequest();
    String rval = UiConfigurationServlet.generateJSONConfig(request, new DtgovUIConfig() {
        @Override
        public Configuration getConfiguration() {
            return config;
        }
    });
    Assert.assertNotNull(rval);
    Assert.assertTrue(rval.contains("http://test.overlord.org:8080/s-ramp-ui")); //$NON-NLS-1$
    // TODO re-enable this assertion but make it cross-platform :(
    //        Assert.assertEquals(EXPECTED_CONFIGURED, rval);
}

From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurer.java

@PreDestroy
public void restoreProperties() {
    try {/*from  ww  w. j  a  v a 2  s.  c o  m*/
        for (Map.Entry<String, Map<String, Object>> entry : modifiedSahiConfigProps.entrySet()) {
            String propFile = entry.getKey();
            logger.debug("restore properties file '{}' with properties '{}'", propFile, entry.getValue());
            PropertiesConfiguration propConfig = new PropertiesConfiguration(propFile);
            propConfig.setAutoSave(true);
            for (Map.Entry<String, Object> propEntry : entry.getValue().entrySet()) {
                String propKey = propEntry.getKey();
                if (propConfig.containsKey(propKey)) {
                    propConfig.clearProperty(propKey);
                }
                propConfig.addProperty(propKey, propEntry.getValue());
            }
        }
    } catch (ConfigurationException e) {
        logger.error("Error in restore sahi config properties", e);
    }
}

From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurer.java

/**
 * writes the {@link SahiProxyProperties#PROXY_PORT} value as {@link SahiProxyProperties#SAHI_PROPERTY_PROXY_PORT_MAPPING}
 * property to sahiConfigPropertyFilePath!
 *///  w  ww.  ja v a2  s  .c  om
protected void modifySahiProxyPortPropertiesConfiguration(String sahiConfigPropertyFilePath, Properties props) {
    final String sahiProxyPort = props.getProperty(SahiProxyProperties.PROXY_PORT);
    if (sahiProxyPort != null) {
        try {
            PropertiesConfiguration propConfig = new PropertiesConfiguration(sahiConfigPropertyFilePath);
            propConfig.setAutoSave(true);
            final String sahiMappingPropertyProxyPort = SahiProxyProperties.SAHI_PROPERTY_PROXY_PORT_MAPPING;

            if (propConfig.containsKey(sahiMappingPropertyProxyPort)) {
                propConfig.clearProperty(sahiMappingPropertyProxyPort);
            }
            //remove property after the test execution, so that the installation can't break
            addToModifiedPropertiesMap(sahiConfigPropertyFilePath, sahiMappingPropertyProxyPort, null);
            propConfig.addProperty(sahiMappingPropertyProxyPort, sahiProxyPort);
            logger.debug("modify properties file '{}' with '{}={}'", sahiConfigPropertyFilePath,
                    sahiMappingPropertyProxyPort, sahiProxyPort);
        } catch (ConfigurationException e) {
            logger.error("modify sahi properties went wrong", e);
        }
    }
}

From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurer.java

/**
 * Modifies the properties file 'propFilePathToConfig' with assigned key from the resource properties.
 *///ww  w.  j  av  a  2  s .c  om
protected void modifyPropertiesConfiguration(String propFilePathToConfig, List<String> updateKeys,
        Properties resourceProps) {
    try {
        PropertiesConfiguration propConfig = new PropertiesConfiguration(propFilePathToConfig);
        propConfig.setAutoSave(true);
        Properties temProps = new Properties();
        for (String propKey : updateKeys) {
            String resolve = resolve(resourceProps.getProperty(propKey), resourceProps);
            if (resolve != null) {
                if (propConfig.containsKey(propKey)) {
                    addToModifiedPropertiesMap(propFilePathToConfig, propKey, propConfig.getProperty(propKey));
                    propConfig.clearProperty(propKey);
                }
                temProps.put(propKey, resolve);
                propConfig.addProperty(propKey, resolve);
            }
        }
        logger.debug("modify properties file '{}' with '{}'", propFilePathToConfig, temProps.toString());
    } catch (ConfigurationException e) {
        logger.error("modify sahi properties went wrong", e);
    }

}

From source file:org.sonar.plugins.objectivec.coverage.CoberturaSensorTest.java

@Test
public void shouldExecuteOnProjectShouldBeTrueWhenProjectIsObjc() {
    final Project project = new Project("Test");
    final CoberturaSensor testedSensor = new CoberturaSensor();
    final PropertiesConfiguration config = new PropertiesConfiguration();
    config.addProperty("sonar.language", ObjectiveC.KEY);
    project.setConfiguration(config);/*from w  ww  .j a  v a 2s. co  m*/

    assertTrue(testedSensor.shouldExecuteOnProject(project));
}

From source file:org.sonar.plugins.objectivec.coverage.CoberturaSensorTest.java

@Test
public void shouldExecuteOnProjectShouldBeFalseWhenProjectIsSomethingElse() {
    final Project project = new Project("Test");
    final CoberturaSensor testedSensor = new CoberturaSensor();
    final PropertiesConfiguration config = new PropertiesConfiguration();
    config.addProperty("sonar.language", "Test");
    project.setConfiguration(config);/*  w  ww  . java2  s .  c  o  m*/

    assertFalse(testedSensor.shouldExecuteOnProject(project));
}

From source file:org.sonar.plugins.objectivec.violations.OCLintSensorTest.java

@Test
public void shouldExecuteOnProjectShouldBeTrueWhenProjectIsObjc() {
    final Project project = new Project("Test");
    final OCLintSensor testedSensor = new OCLintSensor();
    final PropertiesConfiguration config = new PropertiesConfiguration();
    config.addProperty("sonar.language", ObjectiveC.KEY);
    project.setConfiguration(config);//ww w.  ja va  2s .com

    assertTrue(testedSensor.shouldExecuteOnProject(project));
}