List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:com.vmware.qe.framework.datadriven.impl.supplier.XMLDataParser.java
/** * Load the data file and convert them in to a list of data's. * // w ww.j a v a 2 s . c o m * @throws Exception */ public static Map<String, HierarchicalConfiguration> load(String dataFilePath, Class<?> clazz) throws Exception { HierarchicalConfiguration dataFromFile = null; URL dataFileURL = clazz.getResource(dataFilePath); log.info("Validating against schema file:"); validateAgainstSchema(dataFileURL); log.info("Reading the data file: " + dataFileURL); dataFromFile = new XMLConfiguration(dataFileURL); return segregate(dataFromFile, clazz); }
From source file:com.github.steveash.typedconfig.NestedMapConfigIntegrationTest.java
@Before public void setUp() throws Exception { xmlConfig = new XMLConfiguration("nestedMapConfig.xml"); proxy = ConfigProxyFactory.getDefault().make(Proxy.class, xmlConfig); }
From source file:net.sf.jclal.experiment.Experiment.java
/** * * @param jobFilename The xml configuration of the experiment. *//*from ww w .j av a 2 s.c om*/ @SuppressWarnings("unchecked") public void executeJob(String jobFilename) { // Try open job file File jobFile = new File(jobFilename); if (jobFile.exists()) { try { // Job configuration XMLConfiguration jobConf = new XMLConfiguration(jobFile); // Process header String header = "process"; // Create and configure evaluation method String aname = jobConf.getString(header + "[@evaluation-method-type]"); Class<IEvaluationMethod> aclass = (Class<IEvaluationMethod>) Class.forName(aname); IEvaluationMethod evaluationMethod = aclass.newInstance(); // Configure runner if (evaluationMethod instanceof IConfigure) { ((IConfigure) evaluationMethod).configure(jobConf.subset(header)); } long t1 = System.currentTimeMillis(); // Execute evaluation runner evaluationMethod.evaluate(); method = evaluationMethod; t1 = System.currentTimeMillis() - t1; runtime = t1; System.out.println("Execution time: " + t1 + " ms"); } catch (ConfigurationException e) { System.out.println("Configuration exception "); } catch (ClassNotFoundException e) { Logger.getLogger(Experiment.class.getName()).log(Level.SEVERE, null, e); } catch (IllegalAccessException e) { Logger.getLogger(Experiment.class.getName()).log(Level.SEVERE, null, e); } catch (InstantiationException e) { Logger.getLogger(Experiment.class.getName()).log(Level.SEVERE, null, e); } } else { System.out.println("Job file not found"); System.exit(1); } }
From source file:com.moviejukebox.tools.SkinProperties.java
/** * Read the skin information from skinVersionFilename in the skin directory */// www .j a v a 2s . com public static void readSkinVersion() { String skinVersionPath = StringTools.appendToPath(SKIN_HOME, SKIN_VERSION_FILENAME); File xmlFile = new File(skinVersionPath); if (xmlFile.exists()) { LOG.debug("Scanning file '{}'", xmlFile.getAbsolutePath()); } else { LOG.debug("{} does not exist, skipping", xmlFile.getAbsolutePath()); return; } try { XMLConfiguration xmlConfig = new XMLConfiguration(xmlFile); setSkinName(xmlConfig.getString("name")); setSkinVersion(xmlConfig.getString("version")); setSkinDate(xmlConfig.getString("date")); setSkinMessage(StringTools.castList(String.class, xmlConfig.getList("message"))); setFileDate(xmlFile.lastModified()); } catch (ConfigurationException error) { LOG.error("Failed reading version information file '{}'", SKIN_VERSION_FILENAME); LOG.warn(SystemTools.getStackTrace(error)); } }
From source file:com.sqewd.open.dal.core.Env.java
private Env(String filename) throws Exception { XMLUtils.validate(filename, "/schema/moong-dal.xsd"); configf = filename;// w ww . j ava 2s .c o m config = new XMLConfiguration(configf); workdir = config.getString(_CONFIG_DIR_WORK_); if (workdir == null || workdir.isEmpty()) throw new Exception("Invalid Configuration : Missing parameter [" + _CONFIG_DIR_WORK_ + "]"); tempdir = config.getString(_CONFIG_DIR_TEMP_); if (tempdir == null || tempdir.isEmpty()) tempdir = System.getProperty("java.io.tmpdir"); }
From source file:au.com.dw.testdatacapturej.config.ConfigurationFileTest.java
@Before public void setUp() throws Exception { try {/*w ww. j a va2s . co m*/ xmlConstructorConfig = new XMLConfiguration("test-constructor-config.xml"); xmlSetterConfig = new XMLConfiguration("test-setter-config.xml"); xmlCollectionConfig = new XMLConfiguration("test-collection-config.xml"); configUtil = new ConfigUtil(); } catch (ConfigurationException cex) { cex.printStackTrace(); } }
From source file:gda.device.detector.odccd.CrysalisRunListValidator.java
CrysalisRunListValidator(String configPath, boolean allowDefaults) { if (configPath == null) { configPath = LocalProperties.get(LocalProperties.GDA_CONFIG) + "/xml/CrysalisRunListValidator.xml"; }//w ww . j a va 2 s . c o m try { XMLConfiguration config = null; try { config = new XMLConfiguration(configPath); } catch (Exception ex) { if (!allowDefaults) throw ex; } ddetectorindeg = new DoubleLimit("ddetectorindeg", config); dkappaindeg = new DoubleLimit("dkappaindeg", config); domegaindeg = new DoubleLimit("domegaindeg", config); dphiindeg = new DoubleLimit("dphiindeg", config); dscanwidthindeg = new DoubleLimit("dscanwidthindeg", config); dscanspeedratio = new DoubleLimit("dscanspeedratio", config); dexposuretimeinsec = new DoubleLimit("dexposuretimeinsec", config); } catch (Exception ex) { throw new IllegalArgumentException("Unable to read configuration from " + configPath, ex); } }
From source file:hu.ppke.itk.nlpg.purepos.cli.configuration.ConfigurationReader.java
public Configuration read(File f) throws ConfigurationException { XMLConfiguration xconf = new XMLConfiguration(f); List<ConfigurationNode> tagMappings = xconf.getRootNode().getChildren(TAG_MAPPING); LinkedList<StringMapping> tag_ret = new LinkedList<StringMapping>(); for (ConfigurationNode m : tagMappings) { String spat = (String) m.getAttributes(PATTERN).get(0).getValue(); String stag = (String) m.getAttributes(TAG).get(0).getValue(); tag_ret.add(new StringMapping(spat, stag)); }/*from ww w . j a v a 2s. co m*/ List<ConfigurationNode> lemmaMappings = xconf.getRootNode().getChildren(LEMMA_MAPPING); LinkedList<StringMapping> lemma_ret = new LinkedList<StringMapping>(); for (ConfigurationNode m : lemmaMappings) { String spat = (String) m.getAttributes(PATTERN).get(0).getValue(); String stag = (String) m.getAttributes(TAG).get(0).getValue(); lemma_ret.add(new StringMapping(spat, stag)); } List<ConfigurationNode> markers = xconf.getRootNode().getChildren(GUESSED_MARKER); String guessedMarker = ""; if (markers.size() > 0) { guessedMarker = (String) markers.get(0).getValue(); } List<ConfigurationNode> params = xconf.getRootNode().getChildren(SUFFIX_MODEL_PARAMETERS); Double weight = null; if (params.size() > 0) { weight = Double.valueOf((String) params.get(0).getValue()); } return new Configuration(tag_ret, lemma_ret, guessedMarker, weight); }
From source file:jp.primecloud.auto.ui.mock.XmlDataLoader.java
public static <T> List<T> getData(String filename, Class<T> clazz) { try {/* www. ja v a 2 s . c o m*/ XMLConfiguration config = new XMLConfiguration(filename); ConfigurationNode o = config.getRootNode(); List<T> result = new ArrayList<T>(); List<?> list = o.getChildren(); for (Object row : list) { Map<String, Object> map = new HashMap<String, Object>(); for (Object field : ((Node) row).getChildren()) { Object name = ((Node) ((Node) field).getAttributes().get(0)).getValue(); Object value = ((Node) field).getValue(); map.put(toCamelCase((String) name), value); } T c = clazz.newInstance(); BeanUtils.populate(c, map); result.add(c); } return result; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java
public ApacheCommonsConfigProvider location(String loc) { try {// ww w.j a v a2s .co m if (loc.toLowerCase(Locale.getDefault()).endsWith(".properties")) { PropertiesConfiguration config = new PropertiesConfiguration(new File(loc)); rootConfig.addConfiguration(config); LOGGER.debug("properties configuration from {}", loc); } else if (loc.toLowerCase(Locale.getDefault()).endsWith(".xml")) { XMLConfiguration config = new XMLConfiguration(new File(loc)); rootConfig.addConfiguration(config); LOGGER.debug("xml configuration from {}", loc); } else if (loc.toLowerCase(Locale.getDefault()).endsWith(".json")) { JsonConfiguration config = new JsonConfiguration(new File(loc)); rootConfig.addConfiguration(config); LOGGER.debug("json configuration from {}", loc); } else if (loc.toLowerCase(Locale.getDefault()).endsWith(".yml")) { YamlConfiguration config = new YamlConfiguration(loc); rootConfig.addConfiguration(config); LOGGER.debug("yaml configuration from {}", loc); } else if (loc.toLowerCase(Locale.getDefault()).endsWith(".yaml")) { YamlConfiguration config = new YamlConfiguration(loc); rootConfig.addConfiguration(config); LOGGER.debug("yaml configuration from {}", loc); } } catch (Exception exep) { LOGGER.error("unable to load configuration from " + loc.toString(), exep); } return this; }