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

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

Introduction

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

Prototype

public void setProperty(String key, Object value) 

Source Link

Document

Sets a new value for the specified property.

Usage

From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowDescriptorUtils.java

/**
 * replace jar file name with full path where the uploaded jar in the server.
 * //w w  w  . j  a  v  a  2  s  . c o m
 * @param workflowProperty workflow property file
 * 
 * @throws ConfigurationException 
 */
public void replaceJarPath(File workflowProperty) throws ConfigurationException {
    PropertiesConfiguration config = new PropertiesConfiguration(workflowProperty);
    String workflowFolder = workflowProperty.getParent();
    workflowFolder.replace("\\", "/");
    workflowFolder = HadoopWorkflowUtils.fileURLPrefix + workflowFolder;
    config.setProperty("jar.path", workflowFolder);
    config.save();
}

From source file:org.structr.api.config.Settings.java

public static void storeConfiguration(final String fileName) throws IOException {

    try {//from w w  w  .j a va 2s  .  com

        PropertiesConfiguration.setDefaultListDelimiter('\0');

        final PropertiesConfiguration config = new PropertiesConfiguration();

        // store settings
        for (final Setting setting : settings.values()) {

            // story only modified settings and the super user password
            if (setting.isModified() || "superuser.password".equals(setting.getKey())) {

                config.setProperty(setting.getKey(), setting.getValue());
            }
        }

        config.save(fileName);

    } catch (ConfigurationException ex) {
        System.err.println("Unable to store configuration: " + ex.getMessage());
    }

}

From source file:org.talend.mdm.commmon.util.core.EncryptUtil.java

public static void encryptProperties(String location, String[] properties) {
    try {/*  w  w w .j av  a  2s.com*/
        File file = new File(location);
        if (file.exists()) {
            PropertiesConfiguration config = new PropertiesConfiguration();
            config.setDelimiterParsingDisabled(true);
            config.load(file);
            if (file.getName().equals("mdm.conf")) { //$NON-NLS-1$
                dataSourceName = config.getString(DB_DEFAULT_DATASOURCE) == null ? StringUtils.EMPTY
                        : config.getString(DB_DEFAULT_DATASOURCE);
            }
            updated = false;
            for (String property : properties) {
                String password = config.getString(property);
                if (StringUtils.isNotEmpty(password) && !password.endsWith(Crypt.ENCRYPT)) {
                    password = Crypt.encrypt(password);
                    config.setProperty(property, password);
                    updated = true;
                }
            }
            if (updated) {
                config.save(file);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Encrypt password in '" + location + "' error.", e); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:org.talend.mdm.commmon.util.core.MDMConfiguration.java

private Properties getProperties(boolean reload, boolean ignoreIfNotFound) {
    if (reload) {
        properties = null;/*from  www.ja  v  a  2s .co  m*/
    }
    if (properties != null) {
        return properties;
    }
    properties = new Properties();

    File file = new File(location);
    if (file.exists()) {
        LOGGER.info("MDM Configuration: found in '" + file.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$           
        try {
            PropertiesConfiguration config = new PropertiesConfiguration();
            config.setDelimiterParsingDisabled(true);
            config.load(file);
            // Decrypt the passwords in mdm.conf
            config.setProperty(ADMIN_PASSWORD, Crypt.decrypt(config.getString(ADMIN_PASSWORD)));
            config.setProperty(TECHNICAL_PASSWORD, Crypt.decrypt(config.getString(TECHNICAL_PASSWORD)));
            config.setProperty(TDS_PASSWORD, Crypt.decrypt(config.getString(TDS_PASSWORD)));
            properties = ConfigurationConverter.getProperties(config);
        } catch (Exception e) {
            if (!ignoreIfNotFound) {
                throw new IllegalStateException("Unable to load MDM configuration from '" //$NON-NLS-1$
                        + file.getAbsolutePath() + "'", e); //$NON-NLS-1$
            }
            LOGGER.warn("Unable to load MDM configuration from '" + file.getAbsolutePath() + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
        }
    } else {
        if (!ignoreIfNotFound) {
            throw new IllegalStateException("Unable to load MDM configuration from '" + file.getAbsolutePath() //$NON-NLS-1$
                    + "'"); //$NON-NLS-1$
        }
        LOGGER.warn("Unable to load MDM configuration from '" + file.getAbsolutePath() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return properties;
}

From source file:org.wso2.andes.configuration.qpid.QueueConfigurationTest.java

public void setUp() throws Exception {
    _env = new PropertiesConfiguration();
    _emptyConf = new VirtualHostConfiguration("test", _env);

    PropertiesConfiguration fullEnv = new PropertiesConfiguration();
    fullEnv.setProperty("queues.maximumMessageAge", 1);
    fullEnv.setProperty("queues.maximumQueueDepth", 1);
    fullEnv.setProperty("queues.maximumMessageSize", 1);
    fullEnv.setProperty("queues.maximumMessageCount", 1);
    fullEnv.setProperty("queues.minimumAlertRepeatGap", 1);

    _fullHostConf = new VirtualHostConfiguration("test", fullEnv);

}

From source file:org.wso2.andes.configuration.qpid.QueueConfigurationTest.java

private VirtualHostConfiguration overrideConfiguration(String property, int value)
        throws ConfigurationException {
    PropertiesConfiguration queueConfig = new PropertiesConfiguration();
    queueConfig.setProperty("queues.queue.test." + property, value);

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(_fullHostConf.getConfig());
    config.addConfiguration(queueConfig);

    return new VirtualHostConfiguration("test", config);
}

From source file:org.wso2.andes.configuration.qpid.VirtualHostConfiguration.java

public ConfigurationPlugin getQueueConfiguration(AMQQueue queue) {
    VirtualHostConfiguration hostConfig = queue.getVirtualHost().getConfiguration();

    // First check if we have a named queue configuration (the easy case)
    if (Arrays.asList(hostConfig.getQueueNames()).contains(queue.getName())) {
        return null;
    }//from www . j a va2  s.c  o m

    // We don't have an explicit queue config we must find out what we need.
    ArrayList<Binding> bindings = new ArrayList<Binding>(queue.getBindings());

    List<AMQShortString> exchangeClasses = new ArrayList<AMQShortString>(bindings.size());

    //Remove default exchange
    for (int index = 0; index < bindings.size(); index++) {
        // Ignore the DEFAULT Exchange binding
        if (bindings.get(index).getExchange().getNameShortString()
                .equals(ExchangeDefaults.DEFAULT_EXCHANGE_NAME)) {
            bindings.remove(index);
        } else {
            exchangeClasses.add(bindings.get(index).getExchange().getType().getName());

            if (exchangeClasses.size() > 1) {
                // If we have more than 1 class of exchange then we can only use the global
                // queue configuration.
                // and this will be returned from the default getQueueConfiguration
                return null;
            }
        }
    }

    // If we are just bound the the default exchange then use the default.
    if (bindings.isEmpty()) {
        return null;
    }

    // If we are bound to only one type of exchange then we are going
    // to have to resolve the configuration for that exchange.

    String exchangeName = bindings.get(0).getExchange().getType().getName().toString();

    // Lookup a Configuration handler for this Exchange.

    // Build the expected class name. <Exchangename>sConfiguration
    // i.e. TopicConfiguration or HeadersConfiguration
    String exchangeClass = "org.wso2.andes.configuration.qpid." + exchangeName.substring(0, 1).toUpperCase()
            + exchangeName.substring(1) + "Configuration";

    ExchangeConfigurationPlugin exchangeConfiguration = (ExchangeConfigurationPlugin) queue.getVirtualHost()
            .getConfiguration().getConfiguration(exchangeClass);

    // now need to perform the queue-topic-topics-queues magic.
    // So make a new ConfigurationObject that will hold all the configuration for this queue.
    ConfigurationPlugin queueConfig = new QueueConfiguration.QueueConfig();

    // Initialise the queue with any Global values we may have
    PropertiesConfiguration newQueueConfig = new PropertiesConfiguration();
    newQueueConfig.setProperty("name", queue.getName());

    try {
        //Set the queue name
        CompositeConfiguration mungedConf = new CompositeConfiguration();
        //Set the queue name
        mungedConf.addConfiguration(newQueueConfig);
        //Set the global queue configuration
        mungedConf.addConfiguration(getConfig().subset("queues"));

        // Set configuration
        queueConfig.setConfiguration("virtualhosts.virtualhost.queues", mungedConf);
    } catch (ConfigurationException e) {
        // This will not occur as queues only require a name.
        _logger.error("QueueConfiguration requirements have changed.", e);
    }

    // Merge any configuration the Exchange wishes to apply        
    if (exchangeConfiguration != null) {
        queueConfig.addConfiguration(exchangeConfiguration.getConfiguration(queue));
    }

    //Finally merge in any specific queue configuration we have.
    if (_queues.containsKey(queue.getName())) {
        queueConfig.addConfiguration(_queues.get(queue.getName()));
    }

    return queueConfig;
}

From source file:org.wso2.andes.server.configuration.VirtualHostConfiguration.java

public ConfigurationPlugin getQueueConfiguration(AMQQueue queue) {
    VirtualHostConfiguration hostConfig = queue.getVirtualHost().getConfiguration();

    // First check if we have a named queue configuration (the easy case)
    if (Arrays.asList(hostConfig.getQueueNames()).contains(queue.getName())) {
        return null;
    }//w w  w . j a va2s .c om

    // We don't have an explicit queue config we must find out what we need.
    ArrayList<Binding> bindings = new ArrayList<Binding>(queue.getBindings());

    List<AMQShortString> exchangeClasses = new ArrayList<AMQShortString>(bindings.size());

    //Remove default exchange
    for (int index = 0; index < bindings.size(); index++) {
        // Ignore the DEFAULT Exchange binding
        if (bindings.get(index).getExchange().getNameShortString()
                .equals(ExchangeDefaults.DEFAULT_EXCHANGE_NAME)) {
            bindings.remove(index);
        } else {
            exchangeClasses.add(bindings.get(index).getExchange().getType().getName());

            if (exchangeClasses.size() > 1) {
                // If we have more than 1 class of exchange then we can only use the global queue configuration.
                // and this will be returned from the default getQueueConfiguration
                return null;
            }
        }
    }

    // If we are just bound the the default exchange then use the default.
    if (bindings.isEmpty()) {
        return null;
    }

    // If we are bound to only one type of exchange then we are going
    // to have to resolve the configuration for that exchange.

    String exchangeName = bindings.get(0).getExchange().getType().getName().toString();

    // Lookup a Configuration handler for this Exchange.

    // Build the expected class name. <Exchangename>sConfiguration
    // i.e. TopicConfiguration or HeadersConfiguration
    String exchangeClass = "org.wso2.andes.server.configuration." + exchangeName.substring(0, 1).toUpperCase()
            + exchangeName.substring(1) + "Configuration";

    ExchangeConfigurationPlugin exchangeConfiguration = (ExchangeConfigurationPlugin) queue.getVirtualHost()
            .getConfiguration().getConfiguration(exchangeClass);

    // now need to perform the queue-topic-topics-queues magic.
    // So make a new ConfigurationObject that will hold all the configuration for this queue.
    ConfigurationPlugin queueConfig = new QueueConfiguration.QueueConfig();

    // Initialise the queue with any Global values we may have
    PropertiesConfiguration newQueueConfig = new PropertiesConfiguration();
    newQueueConfig.setProperty("name", queue.getName());

    try {
        //Set the queue name
        CompositeConfiguration mungedConf = new CompositeConfiguration();
        //Set the queue name
        mungedConf.addConfiguration(newQueueConfig);
        //Set the global queue configuration
        mungedConf.addConfiguration(getConfig().subset("queues"));

        // Set configuration
        queueConfig.setConfiguration("virtualhosts.virtualhost.queues", mungedConf);
    } catch (ConfigurationException e) {
        // This will not occur as queues only require a name.
        _logger.error("QueueConfiguration requirements have changed.");
    }

    // Merge any configuration the Exchange wishes to apply        
    if (exchangeConfiguration != null) {
        queueConfig.addConfiguration(exchangeConfiguration.getConfiguration(queue));
    }

    //Finally merge in any specific queue configuration we have.
    if (_queues.containsKey(queue.getName())) {
        queueConfig.addConfiguration(_queues.get(queue.getName()));
    }

    return queueConfig;
}

From source file:org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentUtilOperations.java

private static void updateExistingTokens(String responseFromTokenEP) throws AgentCoreOperationException {
    JSONObject jsonTokenObject = new JSONObject(responseFromTokenEP);
    String newAccessToken = jsonTokenObject.get(APIManagerTokenUtils.ACCESS_TOKEN).toString();
    String newRefreshToken = jsonTokenObject.get(APIManagerTokenUtils.REFRESH_TOKEN).toString();

    if (newAccessToken == null || newRefreshToken == null) {
        String msg = "Neither Access-Token nor Refresh-Token was found in the response [" + responseFromTokenEP
                + "].";
        log.error(AgentConstants.LOG_APPENDER + msg);
        throw new AgentCoreOperationException(msg);
    }//w w  w  . j a  va 2 s . com

    AgentManager.getInstance().getAgentConfigs().setAuthToken(newAccessToken);
    AgentManager.getInstance().getAgentConfigs().setRefreshToken(newRefreshToken);
    String deviceConfigFilePath = AgentManager.getInstance().getRootPath()
            + AgentConstants.AGENT_PROPERTIES_FILE_NAME;

    try {
        PropertiesConfiguration propertyFileConfiguration = new PropertiesConfiguration(deviceConfigFilePath);
        propertyFileConfiguration.setProperty(AgentConstants.AUTH_TOKEN_PROPERTY, newAccessToken);
        propertyFileConfiguration.setProperty(AgentConstants.REFRESH_TOKEN_PROPERTY, newRefreshToken);
        propertyFileConfiguration.save();
    } catch (ConfigurationException e) {
        String msg = "Error occurred whilst trying to update the [" + AgentConstants.AGENT_PROPERTIES_FILE_NAME
                + "] at: " + deviceConfigFilePath + " will the new tokens.";
        log.error(AgentConstants.LOG_APPENDER + msg);
        throw new AgentCoreOperationException(msg);
    }
}

From source file:org.xwiki.contrib.confluence.filter.internal.ConfluenceXMLPackage.java

public PropertiesConfiguration getContentProperties(PropertiesConfiguration properties, String key)
        throws ConfigurationException {
    List<Long> elements = getLongList(properties, key);

    if (elements == null) {
        return null;
    }//from  w ww. j  av  a2  s.  co  m

    PropertiesConfiguration contentProperties = new PropertiesConfiguration();
    for (Long element : elements) {
        PropertiesConfiguration contentProperty = getObjectProperties(element);
        if (contentProperty != null) {
            String name = contentProperty.getString("name");

            Object value = contentProperty.getString("longValue", null);
            if (Strings.isNullOrEmpty((String) value)) {
                value = contentProperty.getString("dateValue", null);
                if (Strings.isNullOrEmpty((String) value)) {
                    value = contentProperty.getString("stringValue", null);
                } else {
                    // TODO: dateValue
                }
            } else {
                value = contentProperty.getLong("longValue", null);
            }

            contentProperties.setProperty(name, value);
        }
    }

    return contentProperties;

}