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:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceUtils.java

public void dumpConfigContent(StructuredLogicalConfigServiceContent content, Writer writer)
        throws InvalidConfigServiceException {
    try {//from ww w. j ava2  s. co m
        ValidatorUtil.validate(content);
    } catch (TechnicalException e) {
        throw new InvalidConfigServiceException("Invalid structured content:" + e, e);
    }
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout();
    layout.setLineSeparator("\n");
    String headerComment = content.getHeaderComment();
    if (headerComment != null) {
        layout.setHeaderComment(headerComment);
    }
    for (ConfigEntry configEntry : content.configEntries) {
        String key = configEntry.getKey();
        propertiesConfiguration.addProperty(key, configEntry.getValue());
        String comment = configEntry.getComment();
        layout.setSeparator(key, "=");
        if (comment != null) {
            layout.setComment(key, comment);
        }
    }
    try {
        propertiesConfiguration.save(writer);
    } catch (ConfigurationException e) {
        throw new InvalidConfigServiceException("Invalid structured content or output:" + e, e);
    }
}

From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java

private void saveConfigurationProperties(Map<String, ConfigurationProperty> map) throws ControllerException {
    try {//from  w  w  w. j  av  a2s  .  c  o m
        PropertiesConfiguration configurationMapProperties = new PropertiesConfiguration();
        configurationMapProperties.setDelimiterParsingDisabled(true);
        configurationMapProperties.setListDelimiter((char) 0);
        configurationMapProperties.clear();

        PropertiesConfigurationLayout layout = configurationMapProperties.getLayout();

        Map<String, ConfigurationProperty> sortedMap = new TreeMap<String, ConfigurationProperty>(
                String.CASE_INSENSITIVE_ORDER);
        sortedMap.putAll(map);

        for (Entry<String, ConfigurationProperty> entry : sortedMap.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue().getValue();
            String comment = entry.getValue().getComment();

            if (StringUtils.isNotBlank(key)) {
                configurationMapProperties.addProperty(key, value);
                layout.setComment(key, StringUtils.isBlank(comment) ? null : comment);
            }
        }

        configurationMapProperties.save(new File(configurationFile));
    } catch (Exception e) {
        throw new ControllerException(e);
    }
}

From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java

private void writeToFile(String fileName, String vmId) {
    try {//  www .  j  a va2 s . c o  m

        HashMap<String, String> hmap = PRODUCT_PROPS.get(vmId);

        Iterator<String> hmapIter = hmap.keySet().iterator();
        new File(productPropsFolder + PROPS_FILE_NAME).createNewFile();

        PropertiesConfiguration props_config = new PropertiesConfiguration(
                new File(productPropsFolder + PROPS_FILE_NAME));
        props_config.addProperty(vmId, hmap);
        log.debug("saving to properties file..");
        props_config.save();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}

From source file:es.bsc.servicess.ide.editors.ImplementationFormPage.java

/**
 * Delete a orchestration class from the project metadata 
 * @param classToDelete Orchestration class to be deleted
 * @throws ConfigurationException//w w w  .j a va 2 s  .  c o  m
 */
protected void deleteClassFromMetadataFile(String classToDelete) throws ConfigurationException {
    IFile f = ((ServiceFormEditor) getEditor()).getMetadataFile();
    PropertiesConfiguration config = new PropertiesConfiguration(f.getRawLocation().toOSString());
    String[] classes = config.getStringArray("service.class");
    config.clearProperty("service.class");
    for (String c : classes) {
        if (!c.equals(classToDelete)) {
            config.addProperty("service.class", c);
        }
    }
    config.save();
}

From source file:ninja.utils.MockNinjaProperties.java

/**
 * Create a mock ninja properties, with the given args as the properties.
 *
 * The arguments must be in key value pairs, every second argument being the
 * value for the key name in the previous argument.
 *
 * @param mode The mode/*ww w  .  j  av  a 2  s. c  om*/
 * @param args The key value pairs.
 * @throws AssertionError If an odd number of arguments is supplied.
 */
public static MockNinjaProperties createWithMode(String mode, String contextPath, String... args) {
    assertTrue("You must supply an even number of arguments to form key value pairs", args.length % 2 == 0);
    PropertiesConfiguration props = new PropertiesConfiguration();
    props.setDelimiterParsingDisabled(true);
    for (int i = 0; i < args.length; i += 2) {
        props.addProperty(args[i], args[i + 1]);
    }
    return new MockNinjaProperties(mode, contextPath, props);
}

From source file:org.apache.accumulo.core.conf.Property.java

/**
 * Gets the default value for this property. System properties are interpolated into the value if necessary.
 *
 * @return default value/*from w w w .  j av a 2s.c  o m*/
 */
public String getDefaultValue() {
    String v;
    if (isInterpolated()) {
        PropertiesConfiguration pconf = new PropertiesConfiguration();
        Properties systemProperties = System.getProperties();
        synchronized (systemProperties) {
            pconf.append(new MapConfiguration(systemProperties));
        }
        pconf.addProperty("hack_default_value", this.defaultValue);
        v = pconf.getString("hack_default_value");
    } else {
        v = getRawDefaultValue();
    }
    if (this.type == PropertyType.ABSOLUTEPATH && !(v.trim().equals("")))
        v = new File(v).getAbsolutePath();
    return v;
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenURIIsNull() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", null);

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class).hasMessage("You need to specify the URI of RabbitMQ");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenURIIsEmpty() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", "");

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class).hasMessage("You need to specify the URI of RabbitMQ");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenURIIsInvalid() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", ":invalid");

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class).hasMessage("You need to specify a valid URI");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenManagementURIIsNotInTheConfiguration() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672");

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class)
            .hasMessage("You need to specify the management URI of RabbitMQ");
}