/** Creates a new config using the given properties. * @param props properties to set. * @throws Exception on error */ public BoneCPConfig(Properties props) throws Exception { this(); this.setProperties(checkNotNull(props)); }
/** * @param xmlConfigFile * @param sectionName * @throws Exception */ private void setXMLProperties(InputStream xmlConfigFile, String sectionName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; // ugly XML parsing, but this is built-in the JDK. try { db = dbf.newDocumentBuilder(); Document doc = db.parse(xmlConfigFile); doc.getDocumentElement().normalize(); // get the default settings Properties settings = parseXML(doc, null); if (sectionName != null){ // override with custom settings settings.putAll(parseXML(doc, sectionName)); } // set the properties setProperties(settings); } catch (Exception e) { throw e; } finally { if (xmlConfigFile != null){ // safety xmlConfigFile.close(); } } }
config.setProperties(properties);