HierarchicalINIConfiguration iniConfObj = new HierarchicalINIConfiguration(iniFile); // Get Section names in ini file Set setOfSections = iniConfObj.getSections(); Iterator sectionNames = setOfSections.iterator(); while(sectionNames.hasNext()){ String sectionName = sectionNames.next().toString(); SubnodeConfiguration sObj = iniObj.getSection(sectionName); Iterator it1 = sObj.getKeys(); while (it1.hasNext()) { // Get element Object key = it1.next(); System.out.print("Key " + key.toString() + " Value " + sObj.getString(key.toString()) + "\n"); }
public ConfigKey generateByPropertiesKey(String key) { SubnodeConfiguration configurationAt = null; try { if (Character.isLetter(key.charAt(0))) { configurationAt = keysConfig.configurationAt(key); } } catch (IllegalArgumentException e) { // Can't find a key. maybe its an alternate key. } if (configurationAt == null || configurationAt.isEmpty()) { key = alternateKeysMap.get(key); configurationAt = keysConfig.configurationAt(key); } String type = configurationAt.getString("type"); if (StringUtils.isBlank(type)) { type = "String"; } String[] validValues = configurationAt.getStringArray("validValues"); // Description containing the list delimiter *will* be broken into an array, so rejoin it using that delimiter. // We pad the separator because the strings in the array are trimmed automatically. String description = StringUtils.join(configurationAt.getStringArray("description"), configurationAt.getListDelimiter() + " "); String alternateKey = keysConfig.getString("/" + key + "/" + "alternateKey"); // If the isReloadable attribute isn't specified - assume it is false boolean reloadable = configurationAt.getBoolean("isReloadable", false); ConfigKey configKey = new ConfigKey(type, description, alternateKey, key, "", validValues, "", getHelperByType(type), reloadable, isDeprecated(key)); configKey.setParser(parser); return configKey; }
/** * Returns the name of the class of the bean to be created. This information * is obtained from the {@code config-class} attribute. * * @return the name of the bean's class */ public String getBeanClassName() { return getConfiguration().getString(ATTR_BEAN_CLASS); }
/** * Returns the name of the bean factory. This information is fetched from * the {@code config-factory} attribute. * * @return the name of the bean factory */ public String getBeanFactoryName() { return getConfiguration().getString(ATTR_BEAN_FACTORY); }
/** * Returns the name of the class of the bean to be created. This information * is obtained from the {@code config-class} attribute. * * @return the name of the bean's class */ public String getBeanClassName() { return getConfiguration().getString(ATTR_BEAN_CLASS); }
/** * Returns the name of the bean factory. This information is fetched from * the {@code config-factory} attribute. * * @return the name of the bean factory */ public String getBeanFactoryName() { return getConfiguration().getString(ATTR_BEAN_FACTORY); }
/** * @return the products */ public String getReporterClass() { String ret = DEFAULT_REPORTER; if (config != null) { try { SubnodeConfiguration configurationAt = config.configurationAt(KEY_REPORTER); String string = configurationAt.getString(""); if (StringUtils.isNotBlank(string)) { ret = string; } else { LOG.warn("Reporter not configured. Using default of " + ret); } } catch (Exception e) { LOG.warn("Reporter specified more than once. Using default of " + ret); } } return ret; }
/** * @return the products */ public String getReaderClass() { String ret = DEFAULT_READER; if (config != null) { try { SubnodeConfiguration configurationAt = config.configurationAt(KEY_READER); String string = configurationAt.getString(""); if (StringUtils.isNotBlank(string)) { ret = string; } else { LOG.warn("Reader not configured. Using default of " + ret); } } catch (Exception e) { LOG.warn("Reader specified more than once. Using default of " + ret); } } return ret; }
public DymolaAdaptersMatParamsWriter(HierarchicalINIConfiguration configuration) { if (configuration == null) { throw new RuntimeException("null config"); } this.configuration = configuration; //this below will simply log parameters .. for (String section : configuration.getSections()) { SubnodeConfiguration node = configuration.getSection(section); List<String> paramsSummary = StreamSupport.stream( Spliterators.spliteratorUnknownSize(node.getKeys(), Spliterator.ORDERED), false).map(p -> p + "=" + node.getString(p)).collect(Collectors.<String>toList()); LOGGER.info("index {}: {}", section, paramsSummary); } }
/** * @see org.pivot4j.analytics.datasource.AbstractDataSourceInfo#restoreSettings(org.apache.commons.configuration.HierarchicalConfiguration) */ @Override public void restoreSettings(HierarchicalConfiguration configuration) { super.restoreSettings(configuration); SubnodeConfiguration connectionConfig = configuration .configurationAt("connection-info"); this.url = connectionConfig.getString("url"); this.driverClass = connectionConfig.getString("driverClass"); this.userName = connectionConfig.getString("user"); this.password = connectionConfig.getString("password"); this.properties = new Properties(); List<HierarchicalConfiguration> propertiesConfig = connectionConfig .configurationsAt("properties.property"); for (HierarchicalConfiguration propertyConfig : propertiesConfig) { String key = propertyConfig.getString("[@name]"); String value = propertyConfig.getString(""); properties.put(key, value); } }
HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(file); Set<String> sectionNames = config.getSections(); SubnodeConfiguration section = config.configurationAt(sectionName); String value = section.getString(keyName);
/** * Loads an object from a configuration. * The object is configured if it is an instance of {@link IConfigurable}. * @param config configuration * @return the object */ public IDaoMaster loadDaoMaster(SubnodeConfiguration config) { // Tweak the class loader to avoid some unexpected RCP problems Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); thread.setContextClassLoader(this.getClass().getClassLoader()); try { String className = config.getString("[@class]"); Class<?> clazz = LangUtils.forName(className); IDaoMaster rc = (IDaoMaster)clazz.getConstructor().newInstance(); rc.setFactory(this); if (rc instanceof IConfigurable) { ((IConfigurable)rc).configure(config); } return rc; } catch (Exception e) { throw new RuntimeException("Cannot load class from configuration", e); } finally { // Restore the class loader thread.setContextClassLoader(loader); } }
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); } }
/** * Creates the configuration object. The class is determined by the file * name's extension. * * @param beanClass the class * @param data the bean declaration * @return the new bean * @throws Exception if an error occurs */ @Override protected Object createBeanInstance(Class<?> beanClass, BeanDeclaration data) throws Exception { String fileName = ((ConfigurationDeclaration) data) .getConfiguration().getString(ATTR_FILENAME); if (fileName != null && fileName.toLowerCase().trim().endsWith(fileExtension)) { return super.createBeanInstance(fetchMatchingClass(), data); } else { return super.createBeanInstance(fetchDefaultClass(), data); } } }
/** * Creates the configuration object. The class is determined by the file * name's extension. * * @param beanClass the class * @param data the bean declaration * @return the new bean * @throws Exception if an error occurs */ @Override protected Object createBeanInstance(Class<?> beanClass, BeanDeclaration data) throws Exception { String fileName = ((ConfigurationDeclaration) data) .getConfiguration().getString(ATTR_FILENAME); if (fileName != null && fileName.toLowerCase().trim().endsWith(fileExtension)) { return super.createBeanInstance(fetchMatchingClass(), data); } else { return super.createBeanInstance(fetchDefaultClass(), data); } } }
public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException { final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION); if (graphFile == null || graphFile.length() == 0) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION); } // get the <properties> section of the xml configuration final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties(); SubnodeConfiguration orientDbSpecificConfiguration; try { orientDbSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES); } catch (IllegalArgumentException iae) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES, iae); } try { final String username = orientDbSpecificConfiguration.getString("username", ""); final String password = orientDbSpecificConfiguration.getString("password", ""); // calling the open method opens the connection to graphdb. looks like the // implementation of shutdown will call the orientdb close method. return OrientGraphFactory.getTxGraphImplFactory().getGraph(graphFile, username, password); } catch (Exception ex) { throw new GraphConfigurationException(ex); } }
@Test public void testReadUser() throws Exception { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(TestUtils.loadFromClasspath( "zanata.ini")); SubnodeConfiguration servers = config.getSection("servers"); String url = "https://translate.jboss.org/"; String username = "joe"; String key = "1234"; String prefix = ConfigUtil.findPrefix(servers, new URL(url)); String gotURL = servers.getString(prefix + ".url"); String gotUsername = servers.getString(prefix + ".username"); String gotKey = servers.getString(prefix + ".key"); assertEquals(url, gotURL); assertEquals(username, gotUsername); assertEquals(key, gotKey); }