List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration()
XMLConfiguration
. From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java
/** * Run the void checkReload() method test. * //from w ww . j a v a 2s . c o m * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testCheckReload_2() 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:com.appeligo.config.ConfigurationService.java
private static AbstractConfiguration createConfig(File envFile, File baseFile) { if (log.isInfoEnabled()) { log.info("Initiating configuration " + baseFile + " : " + envFile); }/*from w w w . j a v a 2s.c o m*/ AbstractConfiguration envConfig = null; AbstractConfiguration baseConfig = null; if (envFile.isFile()) { try { if (envFile.getName().endsWith(".xml")) { if (log.isDebugEnabled()) { log.debug("Creating xml config: " + envFile); } envConfig = new XMLConfiguration(); ((XMLConfiguration) envConfig).setValidating(false); ((XMLConfiguration) envConfig).load(envFile); } else if (envFile.getName().endsWith(".properties")) { if (log.isDebugEnabled()) { log.debug("Creating properties config: " + envFile); } envConfig = new PropertiesConfiguration(envFile); } } catch (ConfigurationException e) { if (log.isErrorEnabled()) { log.error("Cannot create AbstractConfiguration for: " + envFile, e); } } } if (baseFile.isFile()) { try { if (baseFile.getName().endsWith(".xml")) { if (log.isDebugEnabled()) { log.debug("Creating xml config: " + baseFile); } baseConfig = new XMLConfiguration(); ((XMLConfiguration) baseConfig).setValidating(false); ((XMLConfiguration) baseConfig).load(baseFile); } else if (baseFile.getName().endsWith(".properties")) { if (log.isDebugEnabled()) { log.debug("Creating properties config: " + baseFile); } baseConfig = new PropertiesConfiguration(baseFile); } } catch (ConfigurationException e) { if (log.isErrorEnabled()) { log.error("Cannot create AbstractConfiguration for: " + baseFile, e); } } } if (envConfig != null && baseConfig != null) { //create a combined AbstractConfiguration if (log.isDebugEnabled()) { log.debug("Creating combined config: " + envFile + " -> " + baseFile); } CombinedConfiguration combined = new CombinedConfiguration(); combined.addConfiguration(envConfig); combined.addConfiguration(baseConfig); return combined; } else if (envConfig != null) { return envConfig; } else { return baseConfig; } }
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Validates that the connection pool will properly hand out a connection * to an active Rserve process. Note: this test assumes that a Rserve * process is already running on localhost using the default port. * @throws ConfigurationException if there is a problem setting up the default test connection * @throws RserveException if there is a problem with the connection to the Rserve process *//*from www . j a va2 s. com*/ @Test public void validConnection() throws ConfigurationException, RserveException { final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(POOL_CONFIGURATION_XML)); pool = new RConnectionPool(configuration); assertNotNull("Connection pool should never be null", pool); assertFalse("Everybody in - the pool should be open!", pool.isClosed()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connection should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // get a connection from the pool final RConnection connection = pool.borrowConnection(); assertNotNull("Connection should not be null", connection); assertTrue("The connection should be connected to the server", connection.isConnected()); // there should be no more connections available assertEquals("There should be one connections", 1, pool.getNumberOfConnections()); assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections()); // but try and get another final RConnection connection2 = pool.borrowConnection(100, TimeUnit.MILLISECONDS); assertNull("The first connection hasn't been returned - it should be null", connection2); // it didn't give us a connection, but make sure the counts didn't change assertEquals("There should be one connections", 1, pool.getNumberOfConnections()); assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections()); // return the connection to the pool pool.returnConnection(connection); // now there should be one available in the pool assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connection should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // make sure we can get another good connection after returning the previous one final RConnection connection3 = pool.borrowConnection(100, TimeUnit.MILLISECONDS); assertNotNull("Connection should not be null", connection3); assertTrue("The connection should be connected to the server", connection3.isConnected()); // there should be no more connections available assertEquals("There should be one connections", 1, pool.getNumberOfConnections()); assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections()); pool.returnConnection(connection3); }
From source file:co.turnus.generic.AbstractConfigurable.java
protected void storeConfiguration(File file) { XMLConfiguration xml = new XMLConfiguration(); xml.copy(configuration);//w w w . j av a2 s. c o m try { xml.save(file); } catch (Exception e) { throw new TurnusRuntimeException("Error while storing the configuration to " + file.getAbsolutePath()); } }
From source file:com.bibisco.manager.ConfigManager.java
private XMLConfiguration getXMLConfiguration() { XMLConfiguration lXMLConfiguration = null; lXMLConfiguration = new XMLConfiguration(); lXMLConfiguration.setEncoding(ENCODING); try {// www . jav a2 s. c o m lXMLConfiguration.setBasePath(CONFIG_DIR); lXMLConfiguration.load(CONFIG_FILENAME); lXMLConfiguration.setExpressionEngine(new XPathExpressionEngine()); } catch (ConfigurationException e) { mLog.error(e, "Error while reading configuration from file ", CONFIG_FILENAME); throw new BibiscoException(e, "bibiscoException.configManager.errorWhileReadingConfiguration", CONFIG_FILENAME, e.getMessage()); } return lXMLConfiguration; }
From source file:at.co.malli.relpm.data.SettingsProvider.java
/** * Set up the default configuration in memory. *///from www. j a v a2 s .c o m private void createDefaultConfig() { user = new XMLConfiguration(); Iterator<String> i = defaults.getKeys(); while (i.hasNext()) { String key = i.next(); Object value = defaults.getProperty(key); user.setProperty(key, value); } try { user.save(userconfigFilename); } catch (ConfigurationException ex) { logger.error(ex.getMessage()); ExceptionDisplayer.showErrorMessage(ex); } }
From source file:com.example.TestClass.java
@Test public void testWithOnlyCommaWithStringBuilder() 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.load(new StringReader(sourceBuilder.toString())); checkConfiguration(config);//from ww w . j a v a2 s .c o m }
From source file:net.sf.tweety.cli.plugins.CliMain.java
/** * This method is meant to load the tweety plugin pathes on startup * /*from ww w . jav a 2s . c o m*/ * @return an object with one or more pluginpathes * @throws ConfigurationException */ public static Map<String, String> configCLI() throws ConfigurationException, FileNotFoundException { System.out.println("Initialize CLI..."); // TODO : exception handling for empty/erroneous configuration Map<String, String> loadablePlugins = new HashMap<String, String>(); XMLConfiguration tweetyXmlConfig = new XMLConfiguration(); File in = new File(TWEETY_CLI_DEFAULT_CONFIG); try { System.out.print("Loading Configuration..."); String inPath = in.getAbsolutePath(); tweetyXmlConfig .setBasePath(inPath.substring(0, inPath.length() - TWEETY_CLI_DEFAULT_CONFIG.length() - 1)); tweetyXmlConfig.load(in); System.out.print("success.\n"); } catch (NullPointerException e) { e.printStackTrace(); } // map ueber "plugins.plugin" mit keys () // TODO: Verhalten bei leeren Feldern pruefen // TODO: Verhalten bei einem einzelnen Eintrag prfen Iterator<String> it = tweetyXmlConfig.getKeys("plugin"); // // TODO fix the casts! // if (it.hasNext()) { // // String pluginPath = (String) tweetyXmlConfig.getProperty(it.next() // .toString()); // // String pluginName = (String) tweetyXmlConfig.getProperty(it.next() // .toString()); // // // for (int i = 0; i < pluginPath.size(); i++) { // // System.out.println(pluginName.get(i) + pluginPath.get(i)); // loadablePlugins.put(pluginName, pluginPath); // } // } System.out.print("Getting Plugins..."); // TODO fix the casts! if (it.hasNext()) { @SuppressWarnings("unchecked") ArrayList<String> pluginPath = (ArrayList<String>) tweetyXmlConfig.getProperty(it.next()); @SuppressWarnings("unchecked") ArrayList<String> pluginName = (ArrayList<String>) tweetyXmlConfig.getProperty(it.next()); for (int i = 0; i < pluginPath.size(); i++) { // System.out.println(pluginName.get(i) + pluginPath.get(i)); loadablePlugins.put(pluginName.get(i), pluginPath.get(i)); } } System.out.print("done.\n"); System.out.println("CLI initialized"); return loadablePlugins; }
From source file:com.eyeq.pivot4j.state.StateSavingIT.java
@Test public void testSaveModelSettings() throws ConfigurationException, IOException { PivotModel model = getPivotModel();/*from w w w. ja v a 2s . c o m*/ model.setMdx(getTestQuery()); model.initialize(); model.setSorting(true); model.setTopBottomCount(3); model.setSortCriteria(SortCriteria.BOTTOMCOUNT); CellSet cellSet = model.getCellSet(); CellSetAxis axis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal()); model.sort(axis, axis.getPositions().get(0)); String mdx = model.getCurrentMdx(); XMLConfiguration configuration = new XMLConfiguration(); configuration.setDelimiterParsingDisabled(true); model.saveSettings(configuration); Logger logger = LoggerFactory.getLogger(getClass()); if (logger.isDebugEnabled()) { StringWriter writer = new StringWriter(); configuration.save(writer); writer.flush(); writer.close(); logger.debug("Loading report content :" + System.getProperty("line.separator")); logger.debug(writer.getBuffer().toString()); } PivotModel newModel = new PivotModelImpl(getDataSource()); newModel.restoreSettings(configuration); newModel.getCellSet(); String newMdx = newModel.getCurrentMdx(); if (newMdx != null) { // Currently the parser treats every number as double value. // It's inevitable now and does not impact the result. newMdx = newMdx.replaceAll("3\\.0", "3"); } assertThat("MDX has been changed after the state restoration", newMdx, is(equalTo(mdx))); assertThat("Property 'sorting' has been changed after the state restoration", newModel.isSorting(), is(true)); assertThat("Property 'topBottomCount' has been changed after the state restoration", newModel.getTopBottomCount(), is(equalTo(3))); assertThat("Property 'sortMode' has been changed after the state restoration", newModel.getSortCriteria(), is(equalTo(SortCriteria.BOTTOMCOUNT))); }
From source file:at.gv.egiz.bku.spring.ConfigurationFactoryBean.java
protected Configuration getDefaultConfiguration() throws ConfigurationException, IOException { Resource resource = resourceLoader.getResource(DEFAULT_CONFIG); XMLConfiguration xmlConfiguration = new XMLConfiguration(); xmlConfiguration.load(resource.getInputStream()); xmlConfiguration.setURL(resource.getURL()); return xmlConfiguration; }