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. * //ww w. j a v a2s .c o m * @throws Exception */ public static Map<String, HierarchicalConfiguration> load(URL dataFileURL, Class<?> clazz) throws Exception { log.debug("Validating against schema file."); validateAgainstSchema(dataFileURL); log.debug("Reading the data file: " + dataFileURL); HierarchicalConfiguration dataFromFile = new XMLConfiguration(dataFileURL); return segregate(dataFromFile, clazz); }
From source file:com.github.steveash.typedconfig.HierarchicalConfigurationSanityTest.java
@Before public void setUp() throws Exception { config = new XMLConfiguration("nestedConfig1.xml"); }
From source file:de.unigoettingen.sub.search.opac.ConfigOpac.java
private static XMLConfiguration getConfig() throws FileNotFoundException { if (Objects.nonNull(config)) { return config; }// ww w . j a va 2 s .c o m KitodoConfigFile opacConfiguration = KitodoConfigFile.OPAC_CONFIGURATION; if (!opacConfiguration.exists()) { throw new FileNotFoundException("File not found: " + opacConfiguration.getAbsolutePath()); } try { config = new XMLConfiguration(opacConfiguration.getFile()); } catch (ConfigurationException e) { logger.error(e.getMessage(), e); config = new XMLConfiguration(); } config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); return config; }
From source file:net.handle.servlet.RequestAdapterTest.java
@Before public void setup() throws Exception { settings = new Settings(new XMLConfiguration(RequestAdapterTest.class.getResource("/OpenHandleTest.xml"))); handle = "10101/nature"; request = new MockHttpServletRequest(); }
From source file:com.microrisc.simply.utilities.XMLConfigurationMappingReader.java
/** * Reads in and returns configuration mapping from specified source XML file. * Returned mapping's keys are values at {@code key} nodes. The values * of returned mapping are {@code Configuration} objects at nodes specified * by {@code sourceNodeName}. {@code key} node must be contained within * {@code sourceNodeName} node, and all of its values should be unique. * @param configFileName source XML file name * @param sourceNodeName name of node within the XML file, where to get configurations from * @param key name of node within {@code sourceNodeName}, whose values constitutes keys * of returned mapping//from w w w . ja v a2 s . c o m * @return configuration mapping <br> * empty mapping if no node with {@code sourceNodeName} exist within the source file * @throws ConfigurationException if an error has encountered during reading * source file */ public static Map<String, Configuration> getConfigMapping(String configFileName, String sourceNodeName, String key) throws ConfigurationException { XMLConfiguration mapperConfig = new XMLConfiguration(configFileName); // get all 'nodeName' nodes List<HierarchicalConfiguration> nodeMappings = mapperConfig.configurationsAt(sourceNodeName); // result mapping Map<String, Configuration> configMappings = new HashMap<String, Configuration>(); // if no mapping exists, return empty mappings if (nodeMappings.isEmpty()) { return configMappings; } // read in all impl mappings for (HierarchicalConfiguration nodeMapping : nodeMappings) { String keyValue = nodeMapping.getString(key); configMappings.put(keyValue, nodeMapping); } return configMappings; }
From source file:com.sm.store.cluster.BuildStoreConfig.java
private void init() { try {//from w w w . j a va2 s . c o m config = new XMLConfiguration(fileName); } catch (ConfigurationException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.moviejukebox.reader.MovieJukeboxLibraryReader.java
public static Collection<MediaLibraryPath> parse(File libraryFile) { Collection<MediaLibraryPath> mlp = new ArrayList<>(); if (!libraryFile.exists() || libraryFile.isDirectory()) { LOG.error("The moviejukebox library input file you specified is invalid: {}", libraryFile.getName()); return mlp; }/*from w w w . jav a 2s. c om*/ try { XMLConfiguration c = new XMLConfiguration(libraryFile); List<HierarchicalConfiguration> fields = c.configurationsAt("library"); for (HierarchicalConfiguration sub : fields) { // sub contains now all data about a single medialibrary node String path = sub.getString("path"); String nmtpath = sub.getString("nmtpath"); // This should be depreciated String playerpath = sub.getString("playerpath"); String description = sub.getString("description"); boolean scrapeLibrary = true; String scrapeLibraryString = sub.getString("scrapeLibrary"); if (StringTools.isValidString(scrapeLibraryString)) { try { scrapeLibrary = sub.getBoolean("scrapeLibrary"); } catch (Exception ignore) { /* ignore */ } } long prebuf = -1; String prebufString = sub.getString("prebuf"); if (prebufString != null && !prebufString.isEmpty()) { try { prebuf = Long.parseLong(prebufString); } catch (NumberFormatException ignore) { /* ignore */ } } // Note that the nmtpath should no longer be used in the library file and instead "playerpath" should be used. // Check that the nmtpath terminates with a "/" or "\" if (nmtpath != null) { if (!(nmtpath.endsWith("/") || nmtpath.endsWith("\\"))) { // This is the NMTPATH so add the unix path separator rather than File.separator nmtpath = nmtpath + "/"; } } // Check that the playerpath terminates with a "/" or "\" if (playerpath != null) { if (!(playerpath.endsWith("/") || playerpath.endsWith("\\"))) { // This is the PlayerPath so add the Unix path separator rather than File.separator playerpath = playerpath + "/"; } } List<Object> excludes = sub.getList("exclude[@name]"); File medialibfile = new File(path); if (medialibfile.exists()) { MediaLibraryPath medlib = new MediaLibraryPath(); medlib.setPath(medialibfile.getCanonicalPath()); if (playerpath == null || StringUtils.isBlank(playerpath)) { medlib.setPlayerRootPath(nmtpath); } else { medlib.setPlayerRootPath(playerpath); } medlib.setExcludes(excludes); medlib.setDescription(description); medlib.setScrapeLibrary(scrapeLibrary); medlib.setPrebuf(prebuf); mlp.add(medlib); if (description != null && !description.isEmpty()) { LOG.info("Found media library: {}", description); } else { LOG.info("Found media library: {}", path); } // Save the media library to the log file for reference. LOG.debug("Media library: {}", medlib); } else { LOG.info("Skipped invalid media library: {}", path); } } } catch (ConfigurationException | IOException ex) { LOG.error("Failed parsing moviejukebox library input file: {}", libraryFile.getName()); LOG.error(SystemTools.getStackTrace(ex)); } return mlp; }
From source file:edu.harvard.hul.ois.fits.tools.ToolBelt.java
public ToolBelt(String configFile) throws FitsConfigurationException { XMLConfiguration config = null;//from w w w. j a v a 2s . co m try { config = new XMLConfiguration(configFile); } catch (ConfigurationException e) { throw new FitsConfigurationException("Error reading " + configFile, e); } tools = new ArrayList<Tool>(); // get number of tools int size = config.getList("tools.tool[@class]").size(); // for each tools get the class path and any excluded extensions for (int i = 0; i < size; i++) { String tClass = config.getString("tools.tool(" + i + ")[@class]"); List<String> excludes = config.getList("tools.tool(" + i + ")[@exclude-exts]"); Tool t = null; try { Class c = Class.forName(tClass); t = (Tool) c.newInstance(); } catch (Exception e) { throw new FitsConfigurationException("Error initializing " + tClass, e); } if (t != null) { for (String ext : excludes) { t.addExcludedExtension(ext); } tools.add(t); } } }
From source file:com.github.steveash.typedconfig.LookupIntegrationTest.java
@Before public void setUp() throws Exception { proxy = ConfigProxyFactory.getDefault().make(House.class, new XMLConfiguration("lookupIntegration.xml")); }
From source file:apacheCommonsTest.testConfig.java
@Test public void config() throws ConfigurationException, FileNotFoundException, DocumentException { //xml config test DOMConfigurator.configureAndWatch("res/gameConfig/log4j.xml"); XMLConfiguration goodsxml = new XMLConfiguration("res/goods.xml"); HierarchicalConfiguration.Node node = goodsxml.getRoot(); int count = node.getChild(0).getAttributeCount(); // String id = (String) node.getChild(0).getAttribute(3).getValue(); SAXReader read = new SAXReader(); Document doc = null;/*from w w w .ja v a 2s . co m*/ doc = read.read(new FileInputStream("res/goods.xml")); XMLConfiguration xmlConfiguration = new XMLConfiguration( Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_LEVEL); // AttributeMap nodeList= (AttributeMap) xmlConfiguration.getDocument().getElementsByTagName("itemDrop"); // Boolean auto = xmlConfiguration.getBoolean("basic.autoRelaodConfig",false) ; // long refresh=xmlConfiguration.getLong("basic.refreshDelay"); // System.out.println(auto); // FileChangedReloadingStrategy reloadingStrategy=new FileChangedReloadingStrategy(); // reloadingStrategy.setRefreshDelay(xmlConfiguration.getLong("basic.refreshDelay")); // xmlConfiguration.setReloadingStrategy(reloadingStrategy); //properties config PropertiesConfiguration config = new PropertiesConfiguration("res/client.properties"); FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); //default 5000 config.setReloadingStrategy(strategy); System.out.println(config.getInt("num")); System.out.println(config.getString("host", "127.0.0.1")); }