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

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

Introduction

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

Prototype

public XMLConfiguration() 

Source Link

Document

Creates a new instance of XMLConfiguration.

Usage

From source file:edu.uw.sig.frames2owl.util.BatchFromIncludeConverter.java

public BatchFromIncludeConverter(String configPath) throws ConfigurationException {
    batchFromIncludeConfig = new XMLConfiguration();
    batchFromIncludeConfig.setDelimiterParsingDisabled(true);
    batchFromIncludeConfig.load(configPath);
}

From source file:edu.hawaii.soest.pacioos.text.TextSourceFactory.java

/**
 * Configure and return a simple text-based source driver instance using the given XML-based
 * configuration file./*from ww w  .  j  a va 2  s.  c  om*/
 * 
 * @param configLocation  the path to the file on disk or in a jar
 * @return  a new instance of a subclassed SimpleTextSource
 * @throws ConfigurationException
 */
public static SimpleTextSource getSimpleTextSource(String configLocation) throws ConfigurationException {

    // Get the per-driver configuration
    XMLConfiguration xmlConfig = new XMLConfiguration();
    xmlConfig.setListDelimiter(new String("|").charAt(0));
    xmlConfig.load(configLocation);
    String connectionType = xmlConfig.getString("connectionType");

    if (log.isDebugEnabled()) {
        Iterator i = xmlConfig.getKeys();
        while (i.hasNext()) {
            String key = (String) i.next();
            String value = xmlConfig.getString(key);
            log.debug(key + ":\t\t" + value);

        }

    }

    // return the correct configuration type
    if (connectionType.equals("file")) {
        FileTextSource fileTextSource = getFileTextSource(xmlConfig);
        String filePath = xmlConfig.getString("connectionParams.filePath");
        fileTextSource.setDataFilePath(filePath);

        simpleTextSource = (SimpleTextSource) fileTextSource;

    } else if (connectionType.equals("socket")) {
        SocketTextSource socketTextSource = getSocketTextSource(xmlConfig);
        String hostName = xmlConfig.getString("connectionParams.hostName");
        socketTextSource.setHostName(hostName);
        int hostPort = xmlConfig.getInt("connectionParams.hostPort");
        socketTextSource.setHostPort(hostPort);

        simpleTextSource = (SimpleTextSource) socketTextSource;

    } else if (connectionType.equals("serial")) {
        SerialTextSource serialTextSource = getSerialTextSource(xmlConfig);
        String serialPort = xmlConfig.getString("connectionParams.serialPort");
        serialTextSource.setSerialPort(serialPort);
        int baudRate = xmlConfig.getInt("connectionParams.serialPortParams.baudRate");
        serialTextSource.setBaudRate(baudRate);
        int dataBits = xmlConfig.getInt("connectionParams.serialPortParams.dataBits");
        serialTextSource.setDataBits(dataBits);
        int stopBits = xmlConfig.getInt("connectionParams.serialPortParams.stopBits");
        serialTextSource.setStopBits(stopBits);
        String parity = xmlConfig.getString("connectionParams.serialPortParams.parity");
        serialTextSource.setParity(parity);

        simpleTextSource = (SimpleTextSource) serialTextSource;

    } else {
        throw new ConfigurationException("There was an issue parsing the configuration."
                + " The connection type of " + connectionType + " wasn't recognized.");
    }

    return simpleTextSource;

}

From source file:com.vaushell.superpipes.DaemonApp.java

@Override
public void init(final DaemonContext context) throws Exception {
    final String[] args = context.getArguments();

    // My config/*from w  w  w . java 2s .  c  o  m*/
    final XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);

    final Path datas;
    switch (args.length) {
    case 1: {
        config.load(args[0]);
        datas = Paths.get("datas");
        break;
    }

    case 2: {
        config.load(args[0]);
        datas = Paths.get(args[1]);
        break;
    }

    default: {
        config.load("conf/configuration.xml");
        datas = Paths.get("datas");
        break;
    }
    }

    dispatcher.init(config, datas, new VC_FileFactory(datas));
}

From source file:com.bytelightning.opensource.pokerface.ProxySpecificTest.java

/**
 * Configure both servers/*from www.j  a v a2  s.  co m*/
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    RemoteTarget = new SunHttpServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 8088), null);
    RemoteTarget.start(new HttpHandler() {
        @Override
        public void handle(HttpExchange exchange) throws IOException {
            OnRemoteTargetRequest(exchange);
        }
    });
    proxy = new PokerFace();
    XMLConfiguration conf = new XMLConfiguration();
    conf.load(ProxySpecificTest.class.getResource("/ProxySpecificTestConfig.xml"));
    proxy.config(conf);
    boolean started = proxy.start();
    Assert.assertTrue("Successful proxy start", started);

}

From source file:com.example.TestClass.java

@Test
public void testWithOnlyComma() throws Exception {
    String source = "<configuration><key0></key0><key1>,</key1><key2></key2><key3></key3></configuration>";
    XMLConfiguration config = new XMLConfiguration();

    config.load(new StringReader(source));
    checkConfiguration(config);// www  . j  a  v a 2s .c o  m
}

From source file:com.oprisnik.semdroid.config.XmlConfig.java

public XmlConfig() {
    mConfiguration = new XMLConfiguration();
}

From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java

/**
 * Run the void checkReload() method test.
 * //www  . j a v a  2s.  co m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testCheckReload_1() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    fixture.checkReload();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
}

From source file:dk.alexandra.fresco.framework.configuration.ConfigurationGenerator.java

public OutputStream generate(int partyNumber, OutputStream out, List<Pair<String, Integer>> hosts)
        throws Exception {
    XMLConfiguration config = new XMLConfiguration();
    for (int inx = 0; inx < hosts.size(); inx++) {
        config.addProperty("parties.party(-1).hostname", hosts.get(inx).getFirst());
        config.addProperty("parties.party.port", hosts.get(inx).getSecond());
    }// w  w w  . j a v  a  2s . co  m

    config.save(out, "UTF-8");
    return out;
}

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

@Test
public void testSettingsManagement() throws ConfigurationException {
    SimpleProperty property = new SimpleProperty("bgColor", "red");

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

    property.saveSettings(configuration);

    SimpleProperty property2 = new SimpleProperty();
    property2.restoreSettings(configuration);

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

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

    configuration.save(System.out);
}

From source file:com.example.TestClass.java

@Test
public void testWithCommaSeparatedList() throws Exception {
    String source = "<configuration><key0></key0><key1>a,b</key1><key2></key2><key3></key3></configuration>";
    XMLConfiguration config = new XMLConfiguration();

    config.load(new StringReader(source));
    checkConfiguration(config);/*  ww  w .  j  a  v  a 2s  .c om*/
}