List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:net.fenyo.gnetwatch.GUI.DialogGeneric.java
private Map<String, String> parseConfigFile(final String name) { Map<String, String> values = new HashMap(); try {/*from ww w . j a v a 2 s . co m*/ final XMLConfiguration initial = new XMLConfiguration(gui.getConfig().getProperty("genericconffile")); initial.setExpressionEngine(new XPathExpressionEngine()); for (final HierarchicalConfiguration subconf : (java.util.List<HierarchicalConfiguration>) initial .configurationsAt("/generic/template")) { final String subconf_name = subconf.getString("name"); if (subconf_name != null && subconf_name.equals(name)) { for (final String key : new String[] { "name", "title", "cmdline", "filename", "workdir", "unit" }) values.put(key, subconf.getString(key)); return values; } } } catch (final ConfigurationException ex) { log.error("Exception", ex); } return null; }
From source file:com.jf.javafx.Application.java
/** * Initialize configurations./*from w w w . j a v a 2 s . c om*/ */ private void _initConfigurations() { File f = new File(_getJFPropertiesFile()); if (f.exists()) { try { config = new XMLConfiguration(f); } catch (ConfigurationException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } } else { config = new XMLConfiguration(); ((XMLConfiguration) getConfiguration()).setFileName(_getJFPropertiesFile()); } }
From source file:io.uploader.drive.config.Configuration.java
public void load(String xmlPath) throws ConfigurationException { String settingFilePath = (xmlPath == null || xmlPath.isEmpty()) ? (defaultXmlPath) : (xmlPath); logger.debug("Load setting file {}.", settingFilePath); checkConfigFile(settingFilePath);/*from w w w .j a v a 2 s .c o m*/ try { config = new XMLConfiguration(settingFilePath); } catch (ConfigurationException e) { logger.error("Error occurred while opening the settings file", e); } if (config == null) return; // TODO: when the commom-configuration 2.0 will be released // set the synchronizer //config.setSynchronizer(new ReadWriteSynchronizer()); config.setThrowExceptionOnMissing(false); httpProxySettings.setConfig(config); httpsProxySettings.setConfig(config); setProxy(); }
From source file:net.handle.servlet.SettingsTest.java
@Test(expected = SettingsException.class) public void testInvalidConfiguration() throws Exception { Configuration configuration = new XMLConfiguration( SettingsTest.class.getResource("/OpenHandleTestInvalid.xml")); Settings settings = new Settings(configuration); assertNull(settings);//from w ww.j a v a 2 s . co m }
From source file:com.dfki.av.sudplan.Configuration.java
/** * Returns whether the configuration file {@code file} is supported by the * current implementation.//from w w w .j a v a 2 s . c o m * * @param file the configuration {@link File} to check * @return {@code true} if a {@code version} tag exists and its value is * equal to {@link #VERSION}. Otherwise {@code false}. */ private static boolean isConfigFileSupported(File file) { try { XMLConfiguration xmlConfig = new XMLConfiguration(file); if (!xmlConfig.containsKey("version")) { log.debug("No version tag."); return false; } String version = xmlConfig.getString("version"); if (version.equalsIgnoreCase(VERSION)) { return true; } else { log.debug("Version {} not supported.", version); return false; } } catch (ConfigurationException ex) { log.error(ex.toString()); } return false; }
From source file:edu.harvard.hul.ois.fits.Fits.java
public Fits(String fits_home) throws FitsConfigurationException { //Set BB_HOME dir with environment variable FITS_HOME = System.getenv("FITS_HOME"); if (FITS_HOME == null) { //if env variable not set check for fits_home passed into constructor if (fits_home != null) { FITS_HOME = fits_home;/*from w w w . j a v a2 s . com*/ } else { //if fits_home is still not set use the current directory FITS_HOME = ""; } } //If fits home is not an empty string and doesn't send with a file separator character, add one if (FITS_HOME.length() > 0 && !FITS_HOME.endsWith(File.separator)) { FITS_HOME = FITS_HOME + File.separator; } FITS_XML = FITS_HOME + "xml" + File.separator; FITS_TOOLS = FITS_HOME + "tools" + File.separator; try { config = new XMLConfiguration(FITS_XML + "fits.xml"); } catch (ConfigurationException e) { throw new FitsConfigurationException("Error reading " + FITS_XML + "fits.xml", e); } try { mapper = new FitsXmlMapper(); } catch (Exception e) { throw new FitsConfigurationException("Error creating FITS XML Mapper", e); } validateToolOutput = config.getBoolean("output.validate-tool-output"); externalOutputSchema = config.getString("output.external-output-schema"); internalOutputSchema = config.getString("output.internal-output-schema"); String consolidatorClass = config.getString("output.dataConsolidator[@class]"); try { Class<?> c = Class.forName(consolidatorClass); consolidator = (ToolOutputConsolidator) c.newInstance(); } catch (Exception e) { throw new FitsConfigurationException("Error initializing " + consolidatorClass, e); } toolbelt = new ToolBelt(FITS_XML + "fits.xml"); }
From source file:eu.betaas.taas.taasvmmanager.configuration.TaaSVMMAnagerConfiguration.java
private static void loadClouds() { int iter;//from w ww .j av a 2s. c o m String type; String url; String user; String pass; String[] cloudData; if (clouds == null) { clouds = new HashMap<String, String[]>(); try { XMLConfiguration config = new XMLConfiguration("vmmanager.conf"); iter = 0; while (config.getProperty("clouds.cloud(" + iter + ")") != null) { type = config.getString("clouds.cloud(" + iter + ")[@type]"); url = config.getString("clouds.cloud(" + iter + ").url"); user = config.getString("clouds.cloud(" + iter + ").user"); pass = config.getString("clouds.cloud(" + iter++ + ").password"); cloudData = new String[3]; cloudData[0] = type; cloudData[1] = user; cloudData[2] = pass; clouds.put(url, cloudData); } } catch (ConfigurationException e) { logger.error(e.getMessage()); } } }
From source file:com.ethanruffing.preferenceabstraction.AutoPreferences.java
/** * Sets this up for the given class, forcing use of the specified storage * system. Defaults to using an XML file if using file-based storage. * * @param c The class for which the preferences are to be stored. * @param configType The storage system to use for the preferences. * @throws ConfigurationException Thrown if an error occurs while loading * the configuration file. *//*from w w w . ja v a2s . co m*/ private void setup(Class<?> c, ConfigurationType configType) throws ConfigurationException { prefsFor = c; this.configType = configType; switch (configType) { case LOCAL: fileConfig = new XMLConfiguration(new File(c.getPackage().getName() + ".xml")); fileConfig.setAutoSave(true); ((XMLConfiguration) fileConfig).setDelimiterParsingDisabled(true); case HOME: fileConfig = new XMLConfiguration( new File(System.getProperty("user.home"), "." + c.getPackage().getName() + ".xml")); fileConfig.setAutoSave(true); ((XMLConfiguration) fileConfig).setDelimiterParsingDisabled(true); break; case SYSTEM: prefs = Preferences.userNodeForPackage(c); break; } }
From source file:de.siemens.quantarch.bugs.impl.BugzillaTracker.java
@Override public void parseIssues() { GenericStatusFetcher statusFetcher = new GenericStatusFetcher(); GenericProductFetcher productFetcher = new GenericProductFetcher(); // get the projectId for the given name long projectId = dao.getProjectId(config.getProjectName()); if (-1 == projectId) { log.error("Project with name: " + config.getProjectName() + " does not exist in the database"); return;//from w ww . ja va 2s .co m } // history fetcher FetchHistory historyFetcher = new GenericHistoryFetcher(config.getIssueTrackerURL()); // Step 1: create a temporary xml configuration file // for b4j using bugzillaURL, proxy server and proxy port File tempFile = null; HttpBugzillaSession session = null; try { tempFile = new File("tempConfig " + new Date().getTime() + ".xml"); writeIntoConfigFile(tempFile, config.getIssueTrackerURL(), config.getProxyHost(), config.getProxyPort()); // Step 2: Parse bugs based on Products and Statuses List<String> products = new ArrayList<String>(); if (config.isProductAsProject()) { products.add(config.getBugsProjectName()); } else { products.addAll(productFetcher.fetchProducts(config.getIssueTrackerURL())); } List<String> statuses = statusFetcher.fetchStatus(config.getIssueTrackerURL()); XMLConfiguration myConfig; myConfig = new XMLConfiguration(tempFile); // Create the session session = new HttpBugzillaSession(); session.configure(myConfig); if (session.open()) { for (String status : statuses) { for (String product : products) { // to maintain the names stat = status; prod = product; DefaultSearchData searchData = new DefaultSearchData(); // Don't limit the search to 500 responses, but allow for an arbitrary amount searchData.add("limit", "0"); searchData.add("product", URLEncoder.encode(product, "UTF-8")); searchData.add("bug_status", status); Iterator<Issue> issueIter = session.searchBugs(searchData, null); while (issueIter.hasNext()) { Issue issue = issueIter.next(); List<BugHistory> bugHistoryList = historyFetcher.fetchBugHistory(issue.getId()); dao.addIssue(issue, projectId, bugHistoryList); // sleep after parsing every bug (as the proxy // will block connections) // Even ISPs would block connections thinkg that // this is a DDoS attack try { Thread.sleep(config.getSleepTimeOut()); } catch (InterruptedException e) { e.printStackTrace(); } } log.info("Product: " + prod + " Status: " + stat + " DONE"); } } } } catch (IOException e) { log.error(e); } catch (ConfigurationException e) { log.error(e); } finally { // close the HTTP Session if (null != session) { session.close(); } // delete the temporary configuration file if (null != tempFile) { if (tempFile.exists()) { tempFile.delete(); } } } }
From source file:com.termmed.utils.FileHelper.java
/** * Gets the file type by header./*from w w w .j ava 2 s . c om*/ * * @param inputFile the input file * @param isReduced the is reduced * @return the file type by header * @throws Exception the exception */ public static String getFileTypeByHeader(File inputFile, boolean isReduced) throws Exception { String namePattern = null; try { Thread currThread = Thread.currentThread(); if (currThread.isInterrupted()) { return null; } String patternFile; if (isReduced) { patternFile = "validation-rules_reduced.xml"; } else { patternFile = "validation-rules.xml"; } XMLConfiguration xmlConfig = new XMLConfiguration( FileHelper.class.getResource("/org/ihtsdo/utils/" + patternFile)); if (xmlConfig == null) { String error = "Pattern file '" + patternFile + "' doesn't exist."; log.error(error); throw new Exception(error); } List<String> namePatterns = new ArrayList<String>(); Object prop = xmlConfig.getProperty("files.file.fileType"); if (prop instanceof Collection) { namePatterns.addAll((Collection) prop); } // System.out.println(""); boolean toCheck = false; String headerRule = null; FileInputStream fis = new FileInputStream(inputFile); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); BufferedReader br = new BufferedReader(isr); String header = br.readLine(); if (header != null) { for (int i = 0; i < namePatterns.size(); i++) { if (currThread.isInterrupted()) { return null; } headerRule = xmlConfig.getString("files.file(" + i + ").headerRule.regex"); namePattern = namePatterns.get(i); // log.info("==================================="); // log.info("For file : " + inputFile.getAbsolutePath()); // log.info("namePattern:" + namePattern); // log.info("headerRule:" + headerRule); if (header.matches(headerRule)) { // log.info("Match"); if ((inputFile.getName().toLowerCase().contains("textdefinition") && namePattern.equals("rf2-descriptions")) || (inputFile.getName().toLowerCase().contains("description") && namePattern.equals("rf2-textDefinition"))) { continue; } toCheck = true; break; } } } if (!toCheck) { log.info("Header for null pattern:" + header); namePattern = null; //System.out.println( "Cannot found header matcher for : " + inputFile.getName()); } br.close(); } catch (FileNotFoundException e) { System.out.println("FileAnalizer: " + e.getMessage()); } catch (UnsupportedEncodingException e) { System.out.println("FileAnalizer: " + e.getMessage()); } catch (IOException e) { System.out.println("FileAnalizer: " + e.getMessage()); } catch (ConfigurationException e) { System.out.println("FileAnalizer: " + e.getMessage()); } return namePattern; }