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

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

Introduction

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

Prototype

public void save() throws ConfigurationException 

Source Link

Document

Save the configuration.

Usage

From source file:org.lsc.Configuration.java

/**
 * Set the new properties/*from   ww w  . j  a  v a2 s  .  c  o  m*/
 * @param prefix the prefix or null
 * @param props the news properties
 * @throws ConfigurationException
 */
public static void setProperties(String prefix, Properties props) throws ConfigurationException {
    Enumeration<Object> propsEnum = props.keys();
    PropertiesConfiguration conf = Configuration.getConfiguration();
    while (propsEnum.hasMoreElements()) {
        String key = (String) propsEnum.nextElement();
        conf.setProperty((prefix != null ? prefix + "." : "") + key, props.getProperty(key));
    }
    conf.save();
}

From source file:org.manalith.ircbot.plugin.missedmessage.MissedMessageRunner.java

public String addMsg(String sender, String receiver, String msg) {
    StringBuilder result = new StringBuilder();

    boolean savedMsg = false;
    int msglen = msg.length();

    try {/*from w w  w  .j a  v a 2 s  . com*/
        PropertiesConfiguration prop = new PropertiesConfiguration(
                getResourcePath() + MissedMessageRunner.filename);

        Iterator<String> userlist = prop.getKeys();
        if (userlist != null) {
            while (userlist.hasNext()) {
                String key = userlist.next();
                if (key.equals(receiver)) {
                    if (prop.getString(receiver).length() != 0) {
                        result.append(StringUtils.split(receiver, '.')[1]);
                        String str = prop.getString(receiver);

                        result.append("? ?   ( ");
                        int availableSpace = 3 - str.split("\\:\\:").length;
                        if (availableSpace != 0) {
                            if (msglen <= 150) {

                                prop.setProperty(receiver, str + "::" + "[:" + sender + "] " + msg);
                                result.append(availableSpace - 1);
                                result.append(" / 3 )");
                            } else {
                                result.delete(0, result.length());
                                result.append(" ? 150? .");
                            }
                        } else {
                            result.append(availableSpace);
                            result.append(" / 3 ) : ???    ");
                        }
                    } else // if key has no value
                    {
                        if (msglen <= 150) {
                            prop.setProperty(receiver, "[:" + sender + "] " + msg);
                            result.append(StringUtils.split(receiver, '.')[1]);
                            result.append("? ?   ( 2 / 3 )");
                        } else {
                            result.delete(0, result.length());
                            result.append(" ? 150? .");
                        }
                    }
                    savedMsg = true;
                    prop.save();
                    break;
                }
            }

            if (!savedMsg) {
                result.append(receiver.split("\\.")[1]
                        + "? ? ??     ?? .");
            }
        }
    } catch (ConfigurationException ce) {
        return ce.getMessage();
    }

    return result.toString();
}

From source file:org.manalith.ircbot.plugin.missedmessage.MissedMessageRunner.java

public String[] getMsg(String newRecv) {
    String[] msgs = null;/*  ww  w .  ja  v a2  s . c o  m*/

    try {
        // init!
        PropertiesConfiguration prop = new PropertiesConfiguration(
                getResourcePath() + MissedMessageRunner.filename);

        if (isMatchedNickinList(newRecv)) {
            if (prop.getString(newRecv).length() != 0) {
                msgs = prop.getString(newRecv).split("\\:\\:");

                for (int i = 0; i < msgs.length; i++)
                    msgs[i] = newRecv.split("\\.")[1] + ", " + msgs[i];

                prop.setProperty(newRecv, "");
                prop.save();
            }
        }
    } catch (ConfigurationException ce) {
        msgs = new String[1];
        msgs[0] = ce.getMessage();
    }

    return msgs;
}

From source file:org.manalith.ircbot.plugin.missedmessage.MissedMessageRunner.java

public void addMsgSlot(String newRecv) {

    try {//from  w ww .  j a va2s.c  om
        PropertiesConfiguration prop = new PropertiesConfiguration(
                getResourcePath() + MissedMessageRunner.filename);

        // if user not found, init msgslot
        prop.setProperty(newRecv, "");
        prop.save();

    } catch (ConfigurationException ce) {
        // ignore exception
    }
}

From source file:org.nekorp.workflow.desktop.control.imp.WorkflowAppPrototipo.java

@Override
public void setPreferenciasUsuario(PreferenciasUsuario param) {
    try {/*from   w w  w. ja  v  a2  s.  c o  m*/
        PropertiesConfiguration config = new PropertiesConfiguration("app.properties");
        config.setProperty("app.service.busqueda.firstId", param.getFirstId());
        config.setProperty("app.service.busqueda.filtro.ultimo", param.getUltimoFiltro());
        config.save();
    } catch (ConfigurationException ex) {
        WorkflowAppPrototipo.LOGGER.error("error al guardar las preferencias" + ex.getMessage());
    }
}

From source file:org.onlab.stc.ScenarioStore.java

/**
 * Resets status of all steps to waiting and clears all events.
 *//*  w  w w . j  a v a 2  s  . c  o m*/
void reset() {
    events.clear();
    statusMap.clear();
    processFlow.getVertexes().forEach(step -> statusMap.put(step.name(), WAITING));
    try {
        removeLogs();
        PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
        cfg.clear();
        cfg.save();
        startTime = Long.MAX_VALUE;
        endTime = Long.MIN_VALUE;
    } catch (ConfigurationException e) {
        print("Unable to store file %s", storeFile);
    }

}

From source file:org.onlab.stc.ScenarioStore.java

/**
 * Loads the states from disk.//from   www .  j av  a  2 s .  c o  m
 */
private void load() {
    try {
        PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
        cfg.getKeys().forEachRemaining(prop -> add(StepEvent.fromString(cfg.getString(prop))));
        cfg.save();
    } catch (ConfigurationException e) {
        print("Unable to load file %s", storeFile);
    }
}

From source file:org.onlab.stc.ScenarioStore.java

/**
 * Saves the states to disk.//  www  . j  ava  2s. c o m
 */
private void save() {
    try {
        PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
        events.forEach(event -> cfg.setProperty("T" + event.time(), event.toString()));
        cfg.save();
    } catch (ConfigurationException e) {
        print("Unable to store file %s", storeFile);
    }
}

From source file:org.settings4j.helper.configuration.ConfigurationToConnectorAdapterTest.java

@Test
public void testAdapterPropertiesConfig() throws Exception {
    final Settings4jRepository testSettings = createSimpleSettings4jConfig();

    // start test => create adapter and add to Settings4jRepository
    final PropertiesConfiguration configuration = addPropertiesConfiguration(//
            testSettings, "myPropConfigConnector", "propertiesConfig.properties");

    // configure some values
    configuration.setProperty(TEST_VALUE_KEY, "Hello Windows World");
    configuration.save();

    // validate result
    assertThat(testSettings.getSettings().getString(TEST_VALUE_KEY), is("Hello Windows World"));
    assertThat(testSettings.getSettings().getString("unknown/Value"), is(nullValue()));

}

From source file:org.soitoolkit.tools.generator.util.PropertyFileUtil.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void updateMuleDeployPropertyFileConfigFile(String outputFolder, String configFilename) {

    String muleDeployPropertyFile = outputFolder + "/src/main/app/mule-deploy.properties";
    System.err.println("Open muleDeployPropertyFile: " + muleDeployPropertyFile);

    try {//w w w  .  j ava  2  s .c om
        PropertiesConfiguration config = new PropertiesConfiguration(muleDeployPropertyFile);
        String key = "config.resources";
        List value = config.getList(key);
        value.add(configFilename);
        System.err.println("Update muleDeployPropertyFile: " + key + " = " + value);
        config.setProperty(key, value);
        config.save();
        System.err.println("Saved muleDeployPropertyFile");

    } catch (ConfigurationException e1) {
        System.err.println("Error with muleDeployPropertyFile: " + e1.getMessage());
        throw new RuntimeException(e1);
    }
}