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:com.bibisco.test.AllTests.java

private static XMLConfiguration getXMLConfiguration() throws ConfigurationException {

    XMLConfiguration lXMLConfiguration = null;
    lXMLConfiguration = new XMLConfiguration();
    lXMLConfiguration.setEncoding(ENCODING);
    lXMLConfiguration.setBasePath(CONFIG_DIR);
    lXMLConfiguration.load(CONFIG_FILENAME);
    lXMLConfiguration.setExpressionEngine(new XPathExpressionEngine());

    return lXMLConfiguration;
}

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

/**
 * Run the void readConfig() method test.
 * // w w  w.  j  ava 2 s. c om
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testReadConfig_1() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    fixture.readConfig();

    // 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:com.flexoodb.common.FlexUtils.java

/**
* retrieves all possible elements and values of an XML file (string).
* 
* @param  content the XML whose elements will be obtained.
* @return a Hashtable containing the element name (as key) and Element object containign the type (ie class and the value).
* @see Hashtable//  w  w w .ja v a 2s.  c  o  m
* @see Element
*/
public Hashtable<String, Element> getAvailableValues(String content) throws Exception {
    Hashtable<String, Element> h = new Hashtable<String, Element>();

    XMLConfiguration x = new XMLConfiguration();
    x.setDelimiterParsingDisabled(true);
    x.load(new ByteArrayInputStream(content.getBytes()));
    Iterator it = x.getKeys();
    String method = null;
    String type = null;

    boolean hasmethod = false;
    while (it.hasNext()) {
        String s = (String) it.next();
        // make sure they have the same type?
        if (s.contains("[@")) {
            type = x.getString(s);
            if (!hasmethod) // then must be empty
            {
                h.put(s.substring(0, s.indexOf("[")), new Element(type, ""));
                type = null;
                method = null;
            }
        } else {
            hasmethod = true;
            method = s;
        }

        if (type != null && method != null) {
            if (type.endsWith("Date")) {
                h.put(method,
                        new Element(type, (new SimpleDateFormat(_dateformat)).parse(x.getString(method))));
            } else if (type.endsWith("byte[]")) {
                h.put(method, new Element(type, (byte[]) Base64.decodeBase64(x.getString(method).getBytes())));
            } else if (type.endsWith("Serializable")) {
                h.put(method, new Element(type,
                        (Serializable) getObject(Base64.decodeBase64(x.getString(method).getBytes()))));
            } else {
                h.put(method, new Element(type, x.getString(method)));
            }
            type = null;
            method = null;
            hasmethod = false;
        }
    }

    return h;
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

@Test
public void testSettingFileNames() {
    conf = new XMLConfiguration();
    conf.setFileName(testProperties);/*from   www  . j a  v a2 s.  c  o  m*/
    assertEquals(testProperties.toString(), conf.getFileName());

    conf.setBasePath(testBasePath);
    conf.setFileName("hello.xml");
    assertEquals("hello.xml", conf.getFileName());
    assertEquals(testBasePath.toString(), conf.getBasePath());
    assertEquals(new File(testBasePath, "hello.xml"), conf.getFile());

    conf.setBasePath(testBasePath);
    conf.setFileName("subdir/hello.xml");
    assertEquals("subdir/hello.xml", conf.getFileName());
    assertEquals(testBasePath.toString(), conf.getBasePath());
    assertEquals(new File(testBasePath, "subdir/hello.xml"), conf.getFile());
}

From source file:edu.cornell.med.icb.R.TestRConnectionPool.java

/**
 * Validates that a pool can be reopened after it has been closed.
 * @throws ConfigurationException if there is a problem setting up the default test connection
 *//*  w w  w . j av  a  2 s . com*/
@Test
public void closeAndReopen() throws ConfigurationException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());

    pool.close();

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());
    assertTrue("The pool should be closed", pool.isClosed());

    pool.reopen();

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

@Test
public void testLoad() throws Exception {
    conf = new XMLConfiguration();
    conf.setFileName(testProperties);/*from   w  w  w  .  j  a  v  a2  s  . co m*/
    conf.load();

    assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
}

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

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

    fixture.readConfig();

    // 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:io.datalayer.conf.XmlConfigurationTest.java

@Test
public void testLoadWithBasePath() throws Exception {
    conf = new XMLConfiguration();

    conf.setFileName("test.xml");
    conf.setBasePath(testBasePath);/* w w  w  . j av a  2s.c  o  m*/
    conf.load();

    assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
}

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

/**
 * Run the void readConfig() method test.
 * //from  www.j  a  v  a2s  .  c  o m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testReadConfig_3() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    fixture.readConfig();

    // 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:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests loading from a stream./*from  w w w .  jav  a 2 s .  c  o m*/
 */
@Test
public void testLoadFromStream() throws Exception {
    String xml = "<?xml version=\"1.0\"?><config><test>1</test></config>";
    conf = new XMLConfiguration();
    conf.load(new ByteArrayInputStream(xml.getBytes()));
    assertEquals(1, conf.getInt("test"));

    conf = new XMLConfiguration();
    conf.load(new ByteArrayInputStream(xml.getBytes()), "UTF8");
    assertEquals(1, conf.getInt("test"));
}