Example usage for org.apache.commons.configuration XMLConfiguration setRootElementName

List of usage examples for org.apache.commons.configuration XMLConfiguration setRootElementName

Introduction

In this page you can find the example usage for org.apache.commons.configuration XMLConfiguration setRootElementName.

Prototype

public void setRootElementName(String name) 

Source Link

Document

Sets the name of the root element.

Usage

From source file:com.eyeq.pivot4j.ui.condition.AndConditionTest.java

@Test
public void testSettingsManagement() throws ConfigurationException {
    RenderContext context = createDummyRenderContext();

    AndCondition and = new AndCondition(conditionFactory);
    and.setSubConditions(Arrays.asList(TestCondition.TRUE, TestCondition.TRUE));

    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setRootElementName("condition");

    and.saveSettings(configuration);/*from   w  w  w .j  av  a2  s .  c  o  m*/

    and = new AndCondition(conditionFactory);
    and.restoreSettings(configuration);

    assertThat("Sub conditions should not be null.", and.getSubConditions(), is(notNullValue()));
    assertThat("Sub condition count should be 2.", and.getSubConditions().size(), is(2));
    assertThat("'true && true' should be true.", and.matches(context), is(true));

    System.out.println("Saved configuration : ");

    configuration.save(System.out);
}

From source file:com.eyeq.pivot4j.ui.condition.OrConditionTest.java

@Test
public void testSettingsManagement() throws ConfigurationException {
    RenderContext context = createDummyRenderContext();

    OrCondition or = new OrCondition(conditionFactory);
    or.setSubConditions(Arrays.asList(TestCondition.TRUE, TestCondition.FALSE));

    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setRootElementName("condition");

    or.saveSettings(configuration);/*from  w  w  w . ja v  a  2 s .  c  om*/

    or = new OrCondition(conditionFactory);
    or.restoreSettings(configuration);

    assertThat("Sub conditions should not be null.", or.getSubConditions(), is(notNullValue()));
    assertThat("Sub condition count should be 2.", or.getSubConditions().size(), is(2));
    assertThat("'true || false' should be true.", or.matches(context), is(true));

    System.out.println("Saved configuration : ");

    configuration.save(System.out);
}

From source file:edu.usc.goffish.gopher.impl.client.DeploymentTool.java

private void createClientConfig(StartFloeInfo info, String managerHost, String coordinatorHost)
        throws IOException, ConfigurationException {

    XMLConfiguration config = new XMLConfiguration();
    config.setRootElementName("GopherConfiguration");

    config.setProperty(FLOE_MANAGER, managerHost + ":" + MANAGER_PORT);
    config.setProperty(FLOE_COORDINATOR, coordinatorHost + ":" + COORDINATOR_PORT);

    info.getSourceInfo().sourceNodeTransport.values();

    for (List<TransportInfoBase> b : info.getSourceInfo().sourceNodeTransport.values()) {
        for (TransportInfoBase base : b) {
            String host = base.getParams().get("hostAddress");
            int dataPort = Integer.parseInt(base.getParams().get("tcpListenerPort"));

            int controlPort = Integer.parseInt(base.getControlChannelInfo().getParams().get("tcpListenerPort"));

            config.setProperty(DATA_FLOW_HOST, host);
            config.setProperty(DATA_FLOW_DATA_PORT, dataPort);
            config.setProperty(DATA_FLOW_CONTROL_PORT, controlPort);
            break;
        }//from   w  w  w .  j ava2s. c o  m
        break;
    }

    config.save(new FileWriter(CONFIG_FILE_PATH));

}

From source file:com.eyeq.pivot4j.ui.condition.ExpressionConditionTest.java

@Test
public void testSettingsManagement() throws ConfigurationException {
    RenderContext context = createDummyRenderContext();
    context.setColIndex(2);//from   w  w  w .jav  a2 s .co m
    context.setRowIndex(1);
    context.setAxis(Axis.ROWS);

    String expression = "<#if columnIndex = 2 && rowIndex = 1>true</#if>";

    ExpressionCondition condition = new ExpressionCondition(conditionFactory);
    condition.setExpression(expression);

    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setRootElementName("condition");

    condition.saveSettings(configuration);

    condition = new ExpressionCondition(conditionFactory);
    condition.restoreSettings(configuration);

    assertThat("Expression has been changed.", condition.getExpression(), is(equalTo(expression)));
    assertThat("Expression '" + expression + "' should be true.", condition.matches(context), is(true));

    System.out.println("Saved configuration : ");

    configuration.save(System.out);
}

From source file:com.eyeq.pivot4j.ui.property.ConditionalPropertyTest.java

@Test
public void testSettingsManagement() throws ConfigurationException {
    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setRootElementName("property");

    property.saveSettings(configuration);
    System.out.println("Saved configuration : ");
    configuration.save(System.out);
    ConditionalProperty property2 = new ConditionalProperty(new DefaultConditionFactory());
    property2.restoreSettings(configuration);

    assertThat("Property name has been changed.", property2.getName(), is(equalTo(property.getName())));
    assertThat("Default value has been changed.", property2.getDefaultValue(),
            is(equalTo(property.getDefaultValue())));

    RenderContext context = createDummyRenderContext();
    context.setColIndex(2);/*from   ww  w.j  av a 2 s . c o m*/
    context.setRowIndex(4);

    String result = property2.getValue(context);

    assertThat("Wrong property value.", result, is(equalTo("blue")));

    System.out.println("Saved configuration : ");
    configuration.save(System.out);
}

From source file:de.nec.nle.siafu.control.Controller.java

/**
 * Create a config file with default values. This is used when the config
 * file doesn't exist in the first place.
 * // w  ww  .  j  a v a  2 s .  c o  m
 * @return the newly created configuration file.
 */
private XMLConfiguration createDefaultConfigFile() {
    System.out.println("Creating a default configuration file at " + DEFAULT_CONFIG_FILE);
    XMLConfiguration newConfig = new XMLConfiguration();
    newConfig.setRootElementName("configuration");
    newConfig.setProperty("commandlistener.enable", true);
    newConfig.setProperty("commandlistener.tcpport", DEFAULT_PORT);
    newConfig.setProperty("ui.usegui", true);
    newConfig.setProperty("ui.speed", DEFAULT_UI_SPEED);
    newConfig.setProperty("ui.gradientcache.prefill", true);
    newConfig.setProperty("ui.gradientcache.size", DEFAULT_CACHE_SIZE);
    newConfig.setProperty("output.type", "null");
    newConfig.setProperty("output.csv.path",
            System.getProperty("user.home") + File.separator + "SiafuContext.csv");
    newConfig.setProperty("output.csv.interval", DEFAULT_CSV_INTERVAL);
    newConfig.setProperty("output.csv.keephistory", true);

    try {
        newConfig.setFileName(DEFAULT_CONFIG_FILE);
        newConfig.save();
    } catch (ConfigurationException e) {
        throw new RuntimeException("Can not create a default config file at " + DEFAULT_CONFIG_FILE, e);
    }

    return newConfig;
}

From source file:logica.EstacionMet.java

@Override
public Stack<PaqueteDatos> actualizar() {
    // Informacion para PaqueteDatos()
    Integer[] sensoresID = new Integer[redSensores.length];
    String[] tipo = new String[redSensores.length];
    String[] medicion = new String[redSensores.length];

    // Cargo el resumen de la estacion si es que existe.
    // Instancio el manejador de XML
    XMLConfiguration registro = new XMLConfiguration();
    registro.setFileName(String.format("resumenes/%d.xml", ID));

    try {//from   www  .j av  a 2s  .c o  m
        // Cargo si existe el registro
        registro.load();
    } catch (ConfigurationException ex) {
        // Si no existe, simplemente seteo el nombre del elemento base
        registro.setRootElementName("resumen");
        // Y creo el archivo
        try {
            registro.save();
        } catch (ConfigurationException ex1) {
            LOGGER.log(Level.SEVERE, null, ex1);
        }
    }

    // Datos de las sub-estaciones
    medidasPila = super.actualizar();

    // Busco y guardo las mediciones de los sensores.
    int largo = redSensores.length;
    for (int i = 0; i < largo; i++) {
        if (redSensores[i] != null) {
            sensoresID[i] = redSensores[i].getID();
            tipo[i] = redSensores[i].getClass().getSimpleName();
            medicion[i] = redSensores[i].getMedicion();
            resumenSave(registro, sensoresID[i], tipo[i], medicion[i]);
        }
    }

    // Agrego el los datos de esta estacion al final de los datos de las sub-estaciones
    medidasPila.push(new PaqueteDatos(ID, getHora(), sensoresID, tipo, medicion));

    return medidasPila;
}

From source file:FocusingField.java

License:asdf

public void saveXML(String path) { // x,y,r
    XMLConfiguration hConfig = new XMLConfiguration();
    hConfig.setRootElementName("focusingHistory");
    if (comment != null) {
        String comment_esc = comment.replace(",", "\\,");
        //          hConfig.addProperty("comment","<![CDATA["+comment_esc+ "]]>");
        hConfig.addProperty("comment", comment_esc);
    }//from   w  ww  . j a  va  2 s. c o m
    if (serialNumber != null)
        hConfig.addProperty("serialNumber", serialNumber);
    if (lensSerial != null)
        hConfig.addProperty("lensSerial", lensSerial);
    hConfig.addProperty("lens_center_x", pX0_distortions); // distortions center, not aberrations!
    hConfig.addProperty("lens_center_y", pY0_distortions);

    hConfig.addProperty("PIXEL_SIZE", PIXEL_SIZE);
    hConfig.addProperty("sensorWidth", sensorWidth);
    hConfig.addProperty("sensorHeight", sensorHeight);

    if ((sampleCoord != null) && (sampleCoord.length > 0) && (sampleCoord[0] != null)
            && (sampleCoord[0].length > 0)) {
        hConfig.addProperty("samples_x", sampleCoord[0].length);
        hConfig.addProperty("samples_y", sampleCoord.length);
        for (int i = 0; i < sampleCoord.length; i++)
            for (int j = 0; j < sampleCoord[i].length; j++) {
                //          double coord[] = {sampleCoord[i][j][0],sampleCoord[i][j][1]};
                hConfig.addProperty("sample_" + i + "_" + j, sampleCoord[i][j][0] + sep + sampleCoord[i][j][1]);
            }
    }
    hConfig.addProperty("measurements", this.measurements.size());
    for (int i = 0; i < this.measurements.size(); i++) {
        FocusingFieldMeasurement meas = this.measurements.get(i);
        String prefix = "measurement_" + i + ".";
        if (meas.timestamp != null)
            hConfig.addProperty(prefix + "timestamp", meas.timestamp);
        hConfig.addProperty(prefix + "temperature", meas.temperature);
        hConfig.addProperty(prefix + "motors", meas.motors[0] + sep + meas.motors[1] + sep + meas.motors[2]);
        hConfig.addProperty(prefix + "sample", meas.asListString());
    }
    File file = new File(path);
    BufferedWriter writer;
    try {
        writer = new BufferedWriter(new FileWriter(file));
        hConfig.save(writer);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.historyPath = path;
}

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

/**
 * Loads a new scenario from the specified input stream.
 *
 * @param stream scenario definition stream
 * @return loaded scenario/*from w  ww. j a v a  2  s.c om*/
 */
public static Scenario loadScenario(InputStream stream) {
    XMLConfiguration cfg = new XMLConfiguration();
    cfg.setAttributeSplittingDisabled(true);
    cfg.setDelimiterParsingDisabled(true);
    cfg.setRootElementName(SCENARIO);
    try {
        cfg.load(stream);
        return loadScenario(cfg);
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException("Unable to load scenario from the stream", e);
    }
}

From source file:org.onosproject.maven.OnosAppMojo.java

private void loadAppFile(File appFile) throws MojoExecutionException {
    XMLConfiguration xml = new XMLConfiguration();
    xml.setRootElementName(APP);

    try (FileInputStream stream = new FileInputStream(appFile)) {
        xml.load(stream);//from   ww  w  .  j  ava 2  s .  c  o  m
        xml.setAttributeSplittingDisabled(true);
        xml.setDelimiterParsingDisabled(true);

        name = xml.getString(NAME);
        version = eval(xml.getString(VERSION));
        featuresRepo = eval(xml.getString(FEATURES_REPO));

        artifacts = xml.configurationsAt(ARTIFACT).stream()
                .map(cfg -> eval(cfg.getRootNode().getValue().toString())).collect(Collectors.toList());

    } catch (ConfigurationException e) {
        throw new MojoExecutionException("Unable to parse app.xml file", e);
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Unable to find app.xml file", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to read app.xml file", e);
    }
}