List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:edu.cwru.sepia.Main.java
private static HierarchicalConfiguration getConfiguration(String filename) throws ConfigurationException { HierarchicalConfiguration configuration = null; try {//from w ww . ja va2 s .co m configuration = new XMLConfiguration(new File(filename)); } catch (Exception ex) { } if (configuration == null || configuration.isEmpty()) { try { configuration = new HierarchicalINIConfiguration(new File(filename)); } catch (Exception ex) { } } if (configuration == null) throw new ConfigurationException("Unable to load configuration file as XML, or INI."); return configuration; }
From source file:io.haze.core.Application.java
/** * Load a configuration file./* w w w . j a va 2s . c om*/ * * @param path The configuration file path relative to the application directory. * * @throws ConfigurationException If the configuration file could not be loaded. * @throws MalformedURLException If the configuration file URL is invalid. */ public static XMLConfiguration loadConfiguration(String path) throws ConfigurationException, MalformedURLException { return new XMLConfiguration(new File(path).toURL()); }
From source file:com.versatus.jwebshield.filter.SessionCheckFilter.java
/** * @see Filter#init(FilterConfig)/*w w w .j a va2s . c o m*/ */ @Override public void init(FilterConfig fConfig) throws ServletException { String file = fConfig.getServletContext().getInitParameter("configFile"); if (file != null) { UrlExclusionList urlExList = new UrlExclusionList(); fConfig.getServletContext().setAttribute(SecurityConstant.SESSION_CHECK_URL_EXCL_LIST_ATTR_NAME, urlExList); try { XMLConfiguration config = new XMLConfiguration(file); SubnodeConfiguration fields = config.configurationAt("sessionCheck"); List<Object> exclusionList = fields.getList("sessionCheckUrlExclusions"); redirectPage = fields.getString("redirectPage"); attributeToCheck = fields.getString("attributeToCheck"); send401 = fields.getBoolean("send401"); if (exclusionList != null) { for (Object obj : exclusionList) { urlExList.addUrl((String) obj); } } // logger.info("init: sessionCheckUrlExclusions=" + // exclusionList); logger.info("init: sessionCheckUrlExclusionsList=" + urlExList); logger.info("init: redirectPage=" + redirectPage); } catch (Exception cex) { logger.error("init: unable to load configFile " + file, cex); } } else { logger.error("init: No configFile specified"); } }
From source file:net.sf.firemox.tools.Configuration.java
/** * Return the configuration node.//from w w w . j a v a2s.c om * * @return the configuration node. */ public static XMLConfiguration getConfiguration() { if (configuration == null) try { loadTemplateFile(IdConst.FILE_SETTINGS); configuration = new XMLConfiguration(IdConst.FILE_SETTINGS); } catch (ConfigurationException e) { throw new RuntimeException("Could not load the configuration :" + IdConst.FILE_SETTINGS, e); } return configuration; }
From source file:com.intuit.tank.proxy.config.CommonsProxyConfiguration.java
/** * Constructor pulls file out of the jar or reads from disk and sets up refresh policy. * //www.java2 s. com * @param expressionEngine * the expression engine to use. Null results in default expression engine */ private void readConfig() { try { XPathExpressionEngine expressionEngine = new XPathExpressionEngine(); if (reloadingStrategy == null) { reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(0); } File configFile = new File(configPath); System.out.println(configFile.getAbsolutePath()); if (configFile.exists() && configFile.isFile()) { try { config = new XMLConfiguration(configFile); } catch (Exception e) { LOG.error("Error parsing configFile " + configFile.getAbsolutePath() + ": " + e, e); } } if (config == null) { // Load a default from the classpath: LOG.info("Reading default configuration " + DEFAULT_CONFIG + " from classpath..."); // Note: we don't let new XMLConfiguration() lookup the resource // url directly because it may not be able to find the desired // classloader to load the URL from. URL configResourceUrl = this.getClass().getClassLoader().getResource(DEFAULT_CONFIG); if (configResourceUrl == null) { throw new RuntimeException("unable to load resource: " + configPath); } config = new XMLConfiguration(configResourceUrl); // // Copy over a default configuration since none exists: // // Ensure data dir location exists: // configFile = new File(DEFAULT_CONFIG); // // if (!configFile.getParentFile().exists() && !configFile.getParentFile().mkdirs()) { // // throw new RuntimeException("could not create directories."); // // } // LOG.info("Saving default configuration to file " + configFile.getAbsolutePath()); // config.save(configFile); } if (expressionEngine != null) { config.setExpressionEngine(expressionEngine); } // reload at most once per thirty seconds on configuration queries. config.setReloadingStrategy(reloadingStrategy); initConfig(); } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:edu.kit.dama.util.DataManagerSettings.java
/** * Perform the internal initialization by loading the properties from the * URL obtained from {@link #getConfigurationURL()}. *//*from w w w.j a v a 2 s .c om*/ private void initialize() { LOGGER.info("Initializing KIT Data Manager settings"); URL configUrl = null; try { configUrl = getConfigurationURL(); LOGGER.debug("Loading configuration from {}", configUrl); settings = new XMLConfiguration(configUrl); LOGGER.debug("Loading productionMode property"); productionMode = getBooleanProperty(PRODUCTION_MODE_ID, true); //Read default persistence units for staging and authorization services loadDefaultPersistenceUnits(); LOGGER.debug("Configuration initialized successfully."); } catch (ConfigurationException e) { //initialization not possible, quit everything. throw new InitializationError("Failed to load KIT Data Manager settings from URL " + configUrl, e); } }
From source file:com.beginner.core.utils.PropertyUtil.java
/** * ?XML?key?TestResourcesUtil//from ww w. ja v a2s.c o m * @param key XMLkey * @param fileName XML??? * @return String key * @throws Exception */ public static String getXmlProperty(String key, String fileName) throws Exception { if (StringUtils.isBlank(key)) throw new IllegalArgumentException("The key cannot be null and cannot be empty."); if (StringUtils.isBlank(fileName)) throw new IllegalArgumentException("The fileName cannot be null and cannot be empty."); String properties = StringUtils.EMPTY; XMLConfiguration config = null; try { config = new XMLConfiguration(fileName); properties = config.getString(key); } catch (Exception e) { throw new Exception(); } return properties; }
From source file:de.nec.nle.siafu.control.Controller.java
/** * Initialize the simulator itself, and run the simulation. * // ww w . ja va 2 s .c o m * @param configPath the file that defines the parameters of the * simulation * @param simulationPath the path to the simulation data */ public Controller(final String configPath, final String simulationPath) { String verifiedConfigPath = configPath; if (configPath == null) { verifiedConfigPath = Controller.DEFAULT_CONFIG_FILE; } try { config = new XMLConfiguration(verifiedConfigPath); System.out.println("Using configuration at " + verifiedConfigPath); } catch (ConfigurationException e) { System.out.println("The config file doesn't exist or " + "is malformed. Recreating."); config = createDefaultConfigFile(); } // Command Listener thread (for external commands) if (config.getBoolean("commandlistener.enable")) { int tcpPort = config.getInt("commandlistener.tcpport"); try { commandListener = new CommandListener(this, tcpPort); // Start threads new Thread(commandListener, "Command Listener thread").start(); } catch (IOException e) { System.err.println("The TCP port " + tcpPort + " is already in use. Is there another copy of " + "Siafu running? Consider changing the port " + "number in the config file."); return; } } guiUsed = config.getBoolean("ui.usegui"); if (guiUsed) { // Printout to the GUI progress = new GUIProgress(); // If there's a GUI, let it load the // simulation, if it's avaialble gui = new GUI(this, simulationPath); Display display = new Display(); display.syncExec(gui); } else if (simulationPath != null) { // Printout to the Console progress = new ConsoleProgress(); // Start the simulation without a GUI simulation = new Simulation(simulationPath, this); } else { // No simulation and no GUI to load. This won't // work. Die. System.err.println( "Please activate the GUI in the config file " + "or provide a simulation at the command line."); System.exit(1); } }
From source file:com.termmed.reconciliation.test.GroupNumberReconciliationTest.java
/** * Gets the previous file./*from www.j a v a 2s . co m*/ * * @param configFile the config file * @return the previous file * @throws ConfigurationException the configuration exception */ private String[] getPreviousFile(File configFile) throws ConfigurationException { XMLConfiguration xmlConfig; String[] previousInferredRelationshipsFile = null; xmlConfig = new XMLConfiguration(configFile); List<String> prevRelFiles = xmlConfig.getList(I_Constants.PREVIOUS_INFERRED_RELATIONSHIP_FILES); if (prevRelFiles != null && prevRelFiles.size() > 0) { previousInferredRelationshipsFile = new String[prevRelFiles.size()]; prevRelFiles.toArray(previousInferredRelationshipsFile); } return previousInferredRelationshipsFile; }
From source file:de.uni_hannover.dcsec.siafu.control.Controller.java
/** * Initialize the simulator itself, and run the simulation. * /*from ww w . j a v a 2s .c o m*/ * @param configPath * the file that defines the parameters of the simulation * @param simulationPath * the path to the simulation data */ public Controller(final String configPath, final String simulationPath) { String verifiedConfigPath = configPath; if (configPath == null) { verifiedConfigPath = Controller.DEFAULT_CONFIG_FILE; } try { config = new XMLConfiguration(verifiedConfigPath); System.out.println("Using configuration at " + verifiedConfigPath); } catch (ConfigurationException e) { System.out.println("The config file doesn't exist or " + "is malformed. Recreating."); config = createDefaultConfigFile(); } // Command Listener thread (for external commands) if (config.getBoolean("commandlistener.enable")) { int tcpPort = config.getInt("commandlistener.tcpport"); try { commandListener = new CommandListener(this, tcpPort); output = new Output(this, tcpPort); // Start threads new Thread(commandListener, "Command Listener thread").start(); } catch (IOException e) { System.err.println("The TCP port " + tcpPort + " is already in use. Is there another copy of " + "Siafu running? Consider changing the port " + "number in the config file."); return; } } guiUsed = config.getBoolean("ui.usegui"); if (guiUsed) { // Printout to the GUI progress = new GUIProgress(); // If there's a GUI, let it load the // simulation, if it's avaialble gui = new GUI(this, simulationPath); Thread guiThread = new Thread(gui, "GUI thread"); guiThread.setDaemon(false); guiThread.start(); } else if (simulationPath != null) { // Printout to the Console progress = new ConsoleProgress(); // Start the simulation without a GUI simulation = new Simulation(simulationPath, this); } else { // No simulation and no GUI to load. This won't // work. Die. System.err.println( "Please activate the GUI in the config file " + "or provide a simulation at the command line."); System.exit(1); } }