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:gda.util.persistence.LocalParameters.java

private static XMLConfiguration loadConfigurationFromFile(String filename) throws ConfigurationException {
    XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(false); // This needs to change if GDA-2492 is fixed
    config.setFileName(filename);//from   w w  w. ja  v  a 2  s .c  om
    config.load();
    return config;
}

From source file:com.example.TestClass.java

@Test
public void testWithOnlyCommaWithStringBuilderWithoutDelimiterParsing() throws Exception {
    StringBuilder sourceBuilder = new StringBuilder("<configuration>");
    sourceBuilder.append("<key0></key0>");
    sourceBuilder.append("<key1>,</key1>");
    sourceBuilder.append("<key2></key2>");
    sourceBuilder.append("<key3></key3>");
    sourceBuilder.append("</configuration>");
    XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);

    config.load(new StringReader(sourceBuilder.toString()));
    checkConfiguration(config);/*from  w w  w .  j ava  2  s.c  o  m*/
}

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 w w w .ja va2s.  co 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:gda.device.detector.odccd.CrysalisRunListValidator.java

/**
 * @param configPath  Save validation criteria to an XML doc
 *///from   w ww .  ja  v  a  2 s. c  o  m
public void saveToConfig(String configPath) {
    if (configPath == null) {
        configPath = LocalProperties.get(LocalProperties.GDA_CONFIG) + "/xml/CrysalisRunListValidator.xml";
    }
    try {
        XMLConfiguration config;
        config = new XMLConfiguration();

        domegaindeg.addToConfig(config);
        ddetectorindeg.addToConfig(config);
        dkappaindeg.addToConfig(config);
        dphiindeg.addToConfig(config);
        dscanwidthindeg.addToConfig(config);
        dscanspeedratio.addToConfig(config);
        dexposuretimeinsec.addToConfig(config);
        config.save(configPath);
    } catch (Exception ex) {
        throw new IllegalArgumentException("Unable to read configuration from " + configPath, ex);
    }
}

From source file:edu.utexas.cs.tactex.core.BrokerPropertiesService.java

/**
 * Loads the properties from classpath, default config file,
 * and user-specified config file, just in case it's not already been
 * loaded. This is done when properties are first requested, to ensure
 * that the logger has been initialized. Because the CompositeConfiguration
 * treats its config sources in FIFO order, this should be called <i>after</i>
 * any user-specified config is loaded./*  w  ww.  j  ava 2 s. co m*/
 */
void lazyInit() {
    // only do this once
    if (initialized)
        return;
    initialized = true;

    // find and load the default properties file
    log.debug("lazyInit");
    try {
        File defaultProps = new File("broker.properties");
        log.info("adding " + defaultProps.getName());
        config.addConfiguration(new PropertiesConfiguration(defaultProps));
    } catch (Exception e1) {
        log.warn("broker.properties not found: " + e1.toString());
    }

    // set up the classpath props
    try {
        Resource[] xmlResources = context.getResources("classpath*:config/properties.xml");
        for (Resource xml : xmlResources) {
            if (validXmlResource(xml)) {
                log.info("loading config from " + xml.getURI());
                XMLConfiguration xconfig = new XMLConfiguration();
                xconfig.load(xml.getInputStream());
                config.addConfiguration(xconfig);
            }
        }
        Resource[] propResources = context.getResources("classpath*:config/*.properties");
        for (Resource prop : propResources) {
            if (validPropResource(prop)) {
                if (null == prop) {
                    log.error("Null resource");
                }
                log.info("loading config from " + prop.getURI());
                PropertiesConfiguration pconfig = new PropertiesConfiguration();
                pconfig.load(prop.getInputStream());
                config.addConfiguration(pconfig);
            }
        }
    } catch (ConfigurationException e) {
        log.error("Problem loading configuration: " + e.toString());
    } catch (Exception e) {
        log.error("Error loading configuration: " + e.toString());
    }

    // set up the configurator
    configurator.setConfiguration(config);
}

From source file:ch.admin.suis.msghandler.config.ClientConfigurationFactory.java

/**
 * Constructor. Do not forget to call the "init()" method!!!
 *
 * @param configPath xml configuration file
 * @throws ConfigurationException Config Problems
 *//*from   w w  w. ja  va 2s .c  om*/
public ClientConfigurationFactory(String configPath) throws ConfigurationException {
    FileUtils.isFile(configPath, "config path");

    xmlConfig = new XMLConfiguration();
    // enable the schema validation
    xmlConfig.setSchemaValidation(true);

    /*
    * Start Mantis 0006347
     * Problem: Wenn im config.xml ein \\ vorhanden war wurde von der xmlConfig nur ein \ zurckgeliefert. Mit
     * xmlConfig.setDelimiterParsingDisabled(true); wird dies unterdrckt und wir sollten wie gewohnt zwei "\" erhalten.
     *
     * Siehe auch:
     * https://extranet.glue.ch/mantis/view.php?id=6347
     * http://mail-archives.apache.org/mod_mbox/commons-issues/201003.mbox/%3C91316976.200621268302587552.JavaMail.jira@brutus.apache.org%3E
     * https://issues.apache.org/jira/browse/CONFIGURATION-411
     */
    xmlConfig.setDelimiterParsingDisabled(true);
    //Das Problem besteht weiterhin bei XML Attributen. xmlConfig.setAttributeSplittingDisabled(true) bietet hier abhilfe.
    xmlConfig.setAttributeSplittingDisabled(true);
    //End Mantis 0006347

    xmlConfig.setFileName(configPath);
    try {
        xmlConfig.load();
    } catch (ConfigurationException ex) {
        LOG.error("XML File: " + configPath + " could not be loaded. It seems the XML file is not valid");
        throw ex;
    }
}

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  .  j a v  a  2 s . c om*/
    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.norconex.jef4.status.JobSuiteStatusSnapshot.java

public static JobSuiteStatusSnapshot newSnapshot(File suiteIndex) throws IOException {
    //--- Ensure file looks good ---
    if (suiteIndex == null) {
        throw new IllegalArgumentException("Suite index file cannot be null.");
    }/* w  w w.  j a  v  a2  s .c  o  m*/
    if (!suiteIndex.exists()) {
        return null;
    }
    if (!suiteIndex.isFile()) {
        throw new IllegalArgumentException("Suite index is not a file: " + suiteIndex.getAbsolutePath());
    }

    //--- Load XML file ---
    String suiteName = FileUtil.fromSafeFileName(FilenameUtils.getBaseName(suiteIndex.getPath()));
    XMLConfiguration xml = new XMLConfiguration();
    ConfigurationUtil.disableDelimiterParsing(xml);
    try {
        xml.load(suiteIndex);
    } catch (ConfigurationException e) {
        throw new IOException("Could not load suite index: " + suiteIndex, e);
    }

    //--- LogManager ---
    ILogManager logManager = ConfigurationUtil.newInstance(xml, "logManager");

    //--- Load status tree ---
    IJobStatusStore serial = ConfigurationUtil.newInstance(xml, "statusStore");
    return new JobSuiteStatusSnapshot(loadTreeNode(null, xml.configurationAt("job"), suiteName, serial),
            logManager);
}

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   ww  w  . j  ava2 s .  c om
        break;
    }

    config.save(new FileWriter(CONFIG_FILE_PATH));

}

From source file:com.flexoodb.FlexManager.java

public FlexManager(String conf) throws Exception {

    XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);
    String dbimplementation = null;
    if (conf == null) {

        byte[] b = FlexUtils
                .getBytesFromInputStream(this.getClass().getClassLoader().getResourceAsStream("flexoodb.xml"));
        if (b != null) {
            config.load(new ByteArrayInputStream(b));
            dbimplementation = config.getString("flexoodb[@engine]");
        }/*from  w w w .j a v  a2 s .co  m*/

    } else {
        config.load(conf);
        dbimplementation = config.getString("flexoodb[@engine]");
    }

    // use the default impl
    if (dbimplementation == null) {
        dbimplementation = "com.flexoodb.engines.FlexJAXBDBDataEngine";
    }

    //_flexdb = (FlexDataInterface) Class.forName(dbimplementation).newInstance();
    _flexdb = (FlexDataInterface) ClassLoader.getSystemClassLoader().loadClass((dbimplementation))
            .newInstance();

    _flexdb.initialize(config);

}