List of usage examples for org.apache.commons.configuration XMLConfiguration load
public void load() throws ConfigurationException
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests string properties with list delimiters when delimiter parsing is * disabled/*from w w w . ja v a 2 s . c o m*/ */ @Test public void testSaveWithDelimiterParsingDisabled() throws ConfigurationException { XMLConfiguration conf = new XMLConfiguration(); conf.setExpressionEngine(new XPathExpressionEngine()); conf.setDelimiterParsingDisabled(true); conf.setAttributeSplittingDisabled(true); conf.setFile(new File(testProperties)); conf.load(); assertEquals("a,b,c", conf.getString("split/list3/@values")); assertEquals(0, conf.getMaxIndex("split/list3/@values")); assertEquals("a\\,b\\,c", conf.getString("split/list4/@values")); assertEquals("a,b,c", conf.getString("split/list1")); assertEquals(0, conf.getMaxIndex("split/list1")); assertEquals("a\\,b\\,c", conf.getString("split/list2")); // save the configuration conf.save(testSaveConf.getAbsolutePath()); // read the configuration and compare the properties XMLConfiguration checkConfig = new XMLConfiguration(); checkConfig.setFileName(testSaveConf.getAbsolutePath()); checkSavedConfig(checkConfig); XMLConfiguration config = new XMLConfiguration(); config.setFileName(testFile2); // config.setExpressionEngine(new XPathExpressionEngine()); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(); config.setProperty("Employee[@attr1]", "3,2,1"); assertEquals("3,2,1", config.getString("Employee[@attr1]")); config.save(testSaveFile.getAbsolutePath()); config = new XMLConfiguration(); config.setFileName(testSaveFile.getAbsolutePath()); // config.setExpressionEngine(new XPathExpressionEngine()); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(); config.setProperty("Employee[@attr1]", "1,2,3"); assertEquals("1,2,3", config.getString("Employee[@attr1]")); config.setProperty("Employee[@attr2]", "one, two, three"); assertEquals("one, two, three", config.getString("Employee[@attr2]")); config.setProperty("Employee.text", "a,b,d"); assertEquals("a,b,d", config.getString("Employee.text")); config.setProperty("Employee.Salary", "100,000"); assertEquals("100,000", config.getString("Employee.Salary")); config.save(testSaveFile.getAbsolutePath()); checkConfig = new XMLConfiguration(); checkConfig.setFileName(testSaveFile.getAbsolutePath()); checkConfig.setExpressionEngine(new XPathExpressionEngine()); checkConfig.setDelimiterParsingDisabled(true); checkConfig.setAttributeSplittingDisabled(true); checkConfig.load(); assertEquals("1,2,3", checkConfig.getString("Employee/@attr1")); assertEquals("one, two, three", checkConfig.getString("Employee/@attr2")); assertEquals("a,b,d", checkConfig.getString("Employee/text")); assertEquals("100,000", checkConfig.getString("Employee/Salary")); }
From source file:org.plannifico.server.configuration.XMLBasedConfigurationManager.java
@Override public boolean loadConfiguration(String configuration_file) { try {/*from w w w . j a va2 s .c o m*/ logger.log(Level.INFO, "Loading configuration from:" + configuration_file); XMLConfiguration config = new XMLConfiguration(configuration_file); config.load(); config.setThrowExceptionOnMissing(true); if (config.isEmpty()) { logger.log(Level.WARNING, "Configuration file is empty:" + DEFAULT_CONFIGURATION_FILE); return false; } List<Object> planning_universes = config.getList("Server.PlanningUniverses.Universe"); for (Object universe : planning_universes) { String universe_name = (String) universe; databaseURL.put(universe_name, config.getString("Server." + universe + ".planningDB.databaseURL")); //"Plannifico.Server.databaseURL"); logger.log(Level.INFO, String.format("Configuration for universe %s: databaseURL: %s", universe_name, databaseURL)); /*workDatabaseURL = config.getString ("Server.workingDB.databaseURL"); logger.log(Level.FINE, "Configuration: workDatabaseURL: " + workDatabaseURL); */ planningDataDBUser.put(universe_name, config.getString("Server." + universe + ".planningDB.dBUser")); logger.log(Level.INFO, String.format("Configuration for universe %s: user name: %s", universe_name, planningDataDBUser)); planningDataDBPwd.put(universe_name, config.getString("Server." + universe + ".planningDB.dBPwd")); planningDBDriver.put(universe_name, config.getString("Server." + universe + ".planningDB.driver")); logger.log(Level.INFO, String.format("Configuration for universe %s: password: %s", universe_name, planningDataDBPwd)); } /* workDataDBUser = config.getString ("Server.workingDB.dBUser"); logger.log(Level.FINE, "Configuration: workDataDBUser: " + workDataDBUser); workDataDBPwd = config.getString ("Server.workingDB.dBPwd"); logger.log(Level.FINE, "Configuration: workDataDBPwd: " + workDataDBPwd); */ configurationLoaded = true; } catch (Exception e) { logger.log(Level.SEVERE, "Error loading configuration " + e.getMessage()); return false; } return true; }
From source file:org.wso2.andes.configuration.AndesConfigurationManager.java
/** * initialize the configuration manager. this MUST be called at application startup. * (QpidServiceComponent bundle -> activate event) * * @throws AndesException/*from w ww . ja v a 2 s. co m*/ */ public static void initialize(int portOffset) throws AndesException { String ROOT_CONFIG_FILE_PATH; // If system property is available set conf path to that value if (componentsPath != null) { ROOT_CONFIG_FILE_PATH = Paths.get(componentsPath).toString(); } else { ROOT_CONFIG_FILE_PATH = Paths.get(System.getProperty(CARBON_HOME), "repository", "conf").toString(); } String brokerConfigFilePath = ROOT_CONFIG_FILE_PATH + File.separator + ROOT_CONFIG_FILE_NAME; log.info("Main andes configuration located at : " + brokerConfigFilePath); try { compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.setDelimiterParsingDisabled(true); XMLConfiguration rootConfiguration = new XMLConfiguration(); rootConfiguration.setDelimiterParsingDisabled(true); rootConfiguration.setFileName(brokerConfigFilePath); rootConfiguration.setExpressionEngine(new XPathExpressionEngine()); rootConfiguration.load(); compositeConfiguration.addConfiguration(rootConfiguration); //Decrypt and maintain secure vault property values in a map for cross-reference. decryptConfigurationFromFile(brokerConfigFilePath); // Derive certain special properties that are not simply specified in the configuration files. addDerivedProperties(); // set carbonPortOffset coming from carbon AndesConfigurationManager.carbonPortOffset = portOffset; //set delivery timeout for a message int deliveryTimeoutForMessage = AndesConfigurationManager .readValue(AndesConfiguration.PERFORMANCE_TUNING_TOPIC_MESSAGE_DELIVERY_TIMEOUT); AndesContext.getInstance().setDeliveryTimeoutForMessage(deliveryTimeoutForMessage); } catch (ConfigurationException e) { String error = "Error occurred when trying to construct configurations from file at path : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } catch (UnknownHostException e) { String error = "Error occurred when trying to derive the bind address for messaging from configurations."; log.error(error, e); throw new AndesException(error, e); } catch (FileNotFoundException e) { String error = "Error occurred when trying to read the configuration file : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } catch (JaxenException e) { String error = "Error occurred when trying to process cipher text in file : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } catch (XMLStreamException e) { String error = "Error occurred when trying to process cipher text in file : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } }
From source file:org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.config.AuthorizationConfiguration.java
public static void initialize() throws AuthorizationException { String brokerConfigFilePath = ROOT_CONFIG_FILE_PATH + ROOT_CONFIG_FILE_NAME; if (log.isDebugEnabled()) { log.debug("Configuration located at : " + brokerConfigFilePath); }/* www . j a v a 2 s.c o m*/ try { compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.setDelimiterParsingDisabled(true); XMLConfiguration rootConfiguration = new XMLConfiguration(); rootConfiguration.setDelimiterParsingDisabled(true); rootConfiguration.setFileName(brokerConfigFilePath); rootConfiguration.setExpressionEngine(new XPathExpressionEngine()); rootConfiguration.load(); readConfigurationFromFile(brokerConfigFilePath); compositeConfiguration.addConfiguration(rootConfiguration); } catch (FileNotFoundException e) { String error = "Error occurred when trying to read the configuration file : " + brokerConfigFilePath; log.error(error, e); throw new AuthorizationException(error, e); } catch (JaxenException e) { String error = "Error occurred when trying to process file : " + brokerConfigFilePath; log.error(error, e); throw new AuthorizationException(error, e); } catch (XMLStreamException e) { String error = "Error occurred when trying to process file : " + brokerConfigFilePath; log.error(error, e); throw new AuthorizationException(error, e); } catch (ConfigurationException e) { String error = "Error occurred when trying to process file :" + brokerConfigFilePath; log.error(error, e); throw new AuthorizationException(error, e); } }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
private static Configuration getVfsFavoritesConfiguration() { File file = new File(AllPluginables.USER_CONFIGURATION_DIRECTORY + File.separator + "vfsFavorites.xml"); XMLConfiguration configuration = new XMLConfiguration(); configuration.setFile(file);//from www .j a v a2 s .com if (file.exists()) { try { configuration.load(); } catch (ConfigurationException e) { LOGGER.severe(String.format("Can't load user configuration from %s: %s", file.getAbsolutePath(), e.getMessage())); } } configuration.setAutoSave(true); return configuration; }
From source file:pl.otros.logview.persistance.PersistentConfiguration.java
private static XMLConfiguration getXMLConfiguration(String file) { XMLConfiguration xmlConfiguration = new XMLConfiguration(); try {//from w ww . j a v a2s .c o m xmlConfiguration = new XMLConfiguration(); xmlConfiguration.setFile(new File(file)); xmlConfiguration.load(); xmlConfiguration.setAutoSave(true); } catch (ConfigurationException e) { LOGGER.severe("Can't load configuration, creating new " + e.getMessage()); try { xmlConfiguration.save(); xmlConfiguration.setAutoSave(true); } catch (ConfigurationException e1) { LOGGER.severe("Can't create persistent configuration: " + e1.getMessage()); } } return xmlConfiguration; }
From source file:uk.ac.ox.it.ords.security.services.impl.ServerConfigurationServiceImpl.java
/** * Loads the configuration file/*from w w w . j a v a2s. c o m*/ * @throws Exception if there is a problem loading the file */ protected void load() throws Exception { String serverConfigurationLocation = DEFAULT_SERVER_CONFIG_LOCATION; // // Check if there is a different load location from the default // try { serverConfigurationLocation = MetaConfiguration.getConfiguration() .getString("ords.server.configuration"); if (serverConfigurationLocation == null) { log.debug("No server configuration location set; using defaults"); serverConfigurationLocation = DEFAULT_SERVER_CONFIG_LOCATION; } } catch (Exception e) { log.debug("No server configuration location set; using defaults"); serverConfigurationLocation = DEFAULT_SERVER_CONFIG_LOCATION; } // // Load the Server Configuration file // XMLConfiguration xmlServerConfiguration = new XMLConfiguration(); try { xmlServerConfiguration.setFileName(serverConfigurationLocation); xmlServerConfiguration.load(); } catch (Exception e1) { log.error("Cannot read server configuration at " + serverConfigurationLocation); throw new Exception("Cannot read server configuration"); } // // Read the server list // int serverArray = xmlServerConfiguration.getStringArray("server[@host]").length; servers = new ArrayList<DatabaseServer>(); for (int i = 0; i < serverArray; i++) { DatabaseServer databaseServer = new DatabaseServer(); databaseServer.setHost(xmlServerConfiguration.getString("server(" + i + ")[@host]")); databaseServer.setPort(xmlServerConfiguration.getInt("server(" + i + ")[@port]")); databaseServer.setUsername(xmlServerConfiguration.getString("server(" + i + ")[@username]")); databaseServer.setPassword(xmlServerConfiguration.getString("server(" + i + ")[@password]")); databaseServer.setMasterDatabaseName(xmlServerConfiguration.getString("server(" + i + ")[@database]")); servers.add(databaseServer); } metadataServer = new DatabaseServer(); metadataServer.setHost(xmlServerConfiguration.getString("metadata(0)[@host]")); metadataServer.setPort(xmlServerConfiguration.getInt("metadata(0)[@port]")); metadataServer.setUsername(xmlServerConfiguration.getString("metadata(0)[@username]")); metadataServer.setPassword(xmlServerConfiguration.getString("metadata(0)[@password]")); metadataServer.setMasterDatabaseName(xmlServerConfiguration.getString("metadata(0)[@database]")); }