List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration load
public void load(Reader reader) throws ConfigurationException
From source file:com.baasbox.db.DbHelper.java
public static void populateConfiguration() throws IOException, ConfigurationException { BaasBoxLogger.info("Load initial configuration..."); InputStream is;// w w w .j ava 2 s .co m if (Play.application().isProd()) is = Play.application().resourceAsStream(CONFIGURATION_FILE_NAME); else is = new FileInputStream(Play.application().getFile("conf/" + CONFIGURATION_FILE_NAME)); HierarchicalINIConfiguration c = new HierarchicalINIConfiguration(); c.setEncoding("UTF-8"); c.load(is); CharSequence doubleDot = ".."; CharSequence dot = "."; Set<String> sections = c.getSections(); for (String section : sections) { Class en = PropertiesConfigurationHelper.CONFIGURATION_SECTIONS.get(section); if (en == null) { BaasBoxLogger.warn(section + " is not a valid configuration section, it will be skipped!"); continue; } SubnodeConfiguration subConf = c.getSection(section); Iterator<String> it = subConf.getKeys(); while (it.hasNext()) { String key = (it.next()); Object value = subConf.getString(key); key = key.replace(doubleDot, dot);//bug on the Apache library: if the key contain a dot, it will be doubled! try { BaasBoxLogger.info("Setting " + value + " to " + key); PropertiesConfigurationHelper.setByKey(en, key, value); } catch (Exception e) { BaasBoxLogger.warn("Error loading initial configuration: Section " + section + ", key: " + key + ", value: " + value, e); } } } is.close(); BaasBoxLogger.info("...done"); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Loads the specified content into the given configuration instance. * * @param instance the configuration/* w ww.j a va2s . c om*/ * @param data the data to be loaded * @throws ConfigurationException if an error occurs */ private static void load(HierarchicalINIConfiguration instance, String data) throws ConfigurationException { StringReader reader = new StringReader(data); instance.load(reader); reader.close(); }
From source file:ee.ria.xroad.common.SystemPropertiesLoader.java
private void load(FileWithSections file) { try {/*w ww . ja v a2s. c om*/ // turn off list delimiting (before parsing), // otherwise we lose everything after first "," // in loadSection/sec.getString(key) HierarchicalINIConfiguration ini = new HierarchicalINIConfiguration(); ini.setDelimiterParsingDisabled(true); ini.load(file.getName()); for (String sectionName : ini.getSections()) { if (isEmpty(file.getSections()) || contains(file.getSections(), sectionName)) { loadSection(sectionName, ini.getSection(sectionName)); } } } catch (ConfigurationException e) { log.warn("Error while loading {}: {}", file.getName(), e); } }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
@Test public void testWriteValueWithCommentChar() throws Exception { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(); config.setProperty("section.key1", "1;2;3"); StringWriter writer = new StringWriter(); config.save(writer);/*from ww w . j a v a 2s . c om*/ HierarchicalINIConfiguration config2 = new HierarchicalINIConfiguration(); config2.load(new StringReader(writer.toString())); assertEquals("value", "1;2;3", config2.getString("section.key1")); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether a configuration can be saved that contains section keys * with delimiter characters. This test is related to CONFIGURATION-409. *//* w ww .j ava 2 s . co m*/ @Test public void testSaveKeysWithDelimiters() throws ConfigurationException { HierarchicalINIConfiguration conf = new HierarchicalINIConfiguration(); final String section = "Section..with..dots"; conf.addProperty(section + ".test1", "test1"); conf.addProperty(section + ".test2", "test2"); conf.save(TEST_FILE); conf = new HierarchicalINIConfiguration(); conf.load(TEST_FILE); assertEquals("Wrong value (1)", "test1", conf.getString(section + ".test1")); assertEquals("Wrong value (2)", "test2", conf.getString(section + ".test2")); }
From source file:org.apache.taverna.robundle.Bundles.java
public static URI getReference(Path path) throws IOException { if (path == null || isMissing(path)) return null; if (!isReference(path)) throw new IllegalArgumentException("Not a reference: " + path); // Note: Latin1 is chosen here because it would not bail out on // "strange" characters. We actually parse the URL as ASCII path = withExtension(path, DOT_URL); try (BufferedReader r = newBufferedReader(path, LATIN1)) { HierarchicalINIConfiguration ini = new HierarchicalINIConfiguration(); ini.load(r); String urlStr = ini.getSection(INI_INTERNET_SHORTCUT).getString(INI_URL); // String urlStr = ini.get(INI_INTERNET_SHORTCUT, INI_URL); if (urlStr == null) throw new IOException("Invalid/unsupported URL format: " + path); return URI.create(urlStr); } catch (ConfigurationException e) { throw new IOException("Can't parse reference: " + path, e); }/*from w ww.j a v a 2 s.co m*/ }