List of usage examples for org.apache.commons.configuration.tree ConfigurationNode getChild
ConfigurationNode getChild(int index);
From source file:org.kepler.configuration.CommonsConfigurationReader.java
/** * load the configuration for a single file in a module *//*from w w w . j av a2s.c o m*/ public RootConfigurationProperty loadConfiguration(Module m, File f, Locale l) throws ConfigurationManagerException { try { boolean loadfile = loadThisFile(f, l); //System.out.println("Should we load " + f.getName() + //" for locale " + l.toString() + " : " + loadfile); if (!loadfile) { //don't load this file if it's not of the correct locale return null; } f = ConfigurationManager.getOverwriteFile(m, f); XMLConfiguration xmlconfig = new XMLConfiguration(); xmlconfig.setDelimiterParsingDisabled(true); FileInputStream stream = null; try { stream = new FileInputStream(f); xmlconfig.load(stream); } finally { if (stream != null) { stream.close(); } } //David Welker: Adding configuration directives boolean mustSave = applyConfigurationDirectives(m, f, xmlconfig); RootConfigurationProperty cp = new RootConfigurationProperty(m, f); //set the default namespace ConfigurationNamespace namespace = new ConfigurationNamespace(ConfigurationManager .removeLocaleDesignator(ConfigurationManager.removeFileExtension(f.getName()))); cp.setNamespace(namespace); ConfigurationNode rootCN = xmlconfig.getRootNode(); //check to see if there is a namsepace element and use that if there is if (rootCN.getChild(0).getName().equals("namespace")) { String ns = (String) rootCN.getChild(0).getValue(); namespace = new ConfigurationNamespace(ns); cp.setNamespace(namespace); } //create the config property ConfigurationProperty deserializedProp = getConfiguration(rootCN, m, namespace); cp.addProperty(deserializedProp); if (mustSave && configurationWriter != null) configurationWriter.writeConfiguration(cp); return cp; } catch (Exception e) { e.printStackTrace(); throw new ConfigurationManagerException( "Error loading configuration file " + f.getPath() + ": " + e.getMessage()); } }