List of usage examples for org.apache.commons.configuration PropertiesConfiguration load
public synchronized void load(Reader in) throws ConfigurationException
From source file:org.w3.i18n.I18nTestRunnerTest.java
private static List<I18nTest> parseTestsFile(File file) { logger.info("Parsing tests file: '" + file + "'."); // Parse the properties file. PropertiesConfiguration configuration = new PropertiesConfiguration(); // (This method must be called before the file is parsed). configuration.setDelimiterParsingDisabled(true); try {/*from ww w. j a v a 2 s . c om*/ configuration.load(file); // (Parses.) } catch (ConfigurationException ex) { throw new RuntimeException(ex); } // Create I18nTests for each prefix (e.g. "charset_5ab") in the file. Set<String> prefixes = findPrefixes(configuration); List<I18nTest> i18nTests = new ArrayList<>(); for (String prefix : prefixes) { List<I18nTest> testsForPrefix = interpretTests(prefix, configuration); logger.info("Created " + testsForPrefix.size() + " I18nTest(s) for prefix '" + prefix + "' in '" + file.getName() + "'."); i18nTests.addAll(testsForPrefix); } Collections.sort(i18nTests); return i18nTests; }
From source file:org.wisdom.configuration.ApplicationConfigurationImpl.java
/** * This is important: We load stuff as UTF-8. * <p>/*from w w w .j ava 2 s. c om*/ * We are using in the default Apache Commons loading mechanism. * <p> * With two little tweaks: 1. We don't accept any delimimter by default 2. * We are reading in UTF-8 * <p> * More about that: * http://commons.apache.org/configuration/userguide/howto_filebased * .html#Loading * <p> * From the docs: - If the combination from base path and file name is a * full URL that points to an existing file, this URL will be used to load * the file. - If the combination from base path and file name is an * absolute file name and this file exists, it will be loaded. - If the * combination from base path and file name is a relative file path that * points to an existing file, this file will be loaded. - If a file with * the specified name exists in the user's home directory, this file will be * loaded. - Otherwise the file name is interpreted as a resource name, and * it is checked whether the data file can be loaded from the classpath. * * @param fileOrUrlOrClasspathUrl Location of the file. Can be on file system, or on the * classpath. Will both work. * @return A PropertiesConfiguration or null if there were problems getting it. */ public final PropertiesConfiguration loadConfigurationInUtf8(String fileOrUrlOrClasspathUrl) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setEncoding("utf-8"); propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.setFileName(fileOrUrlOrClasspathUrl); propertiesConfiguration.getLayout().setSingleLine(APPLICATION_SECRET, true); try { propertiesConfiguration.load(fileOrUrlOrClasspathUrl); } catch (ConfigurationException e) { LOGGER.info("Could not load file " + fileOrUrlOrClasspathUrl + " (not a bad thing necessarily, but you should have a look)", e); return null; } return propertiesConfiguration; }
From source file:org.wisdom.maven.utils.Properties2HoconConverterTest.java
public final PropertiesConfiguration loadPropertiesWithApacheConfiguration(File file) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setEncoding("utf-8"); propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.setFile(file); propertiesConfiguration.setListDelimiter(','); propertiesConfiguration.getLayout().setSingleLine("application.secret", true); try {//from w ww. j ava 2 s . c om propertiesConfiguration.load(file); } catch (ConfigurationException e) { return null; } return propertiesConfiguration; }
From source file:org.xwiki.test.integration.utils.XWikiExecutor.java
/** * @since 4.2M1//from ww w . j av a 2 s.c o m */ private PropertiesConfiguration getPropertiesConfiguration(String path) throws Exception { PropertiesConfiguration properties = new PropertiesConfiguration(); FileInputStream fis; try { fis = new FileInputStream(path); try { properties.load(fis); } finally { fis.close(); } } catch (FileNotFoundException e) { LOGGER.debug("Failed to load properties [" + path + "]", e); } return properties; }
From source file:pl.otros.logview.batch.BatchProcessor.java
public static void main(String[] args) throws IOException, InitializationException, ConfigurationException { CmdLineConfig parserCmdLine = new CmdLineConfig(); try {//from w ww.j a va2 s. co m parserCmdLine.parserCmdLine(args); if (parserCmdLine.printHelp) { parserCmdLine.printUsage(); System.exit(0); } } catch (Exception e) { parserCmdLine.printUsage(); System.err.println(e.getMessage()); return; } finally { checkIfShowBatchProcessingIsEnabled(parserCmdLine); } BatchProcessor batchProcessor = new BatchProcessor(); batchProcessor.setFiles(parserCmdLine.files); if (parserCmdLine.dirWithJars != null) { File f = new File(parserCmdLine.dirWithJars); URL[] urls = null; if (f.isDirectory()) { File[] listFiles = f.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith(".jar"); } }); urls = new URL[listFiles.length]; for (int i = 0; i < urls.length; i++) { urls[i] = listFiles[i].toURI().toURL(); } } else if (f.getName().endsWith("jar")) { urls = new URL[] { f.toURI().toURL() }; } if (urls == null) { System.err.println( "Dir with additional jars or single jars do not point to dir with jars or single jar"); System.exit(1); } URLClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); } ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { batchProcessor.setLogDataParsedListener( (LogDataParsedListener) cl.loadClass(parserCmdLine.logDataParsedListenerClass).newInstance()); // batchProcessor.setLogDataCollector((LogDataParsedListener) cl.loadClass(parserCmdLine.logDataParsedListenerClass).newInstance()); } catch (Exception e2) { System.err.println("Can't load log data collector: " + e2.getMessage()); } batchProcessor.batchProcessingContext.setVerbose(parserCmdLine.verbose); // load processing configuration if (parserCmdLine.batchConfigurationFile != null) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.load(parserCmdLine.batchConfigurationFile); batchProcessor.batchProcessingContext.getConfiguration().append(propertiesConfiguration); } batchProcessor.batchProcessingContext.printIfVerbose("Processing started"); try { batchProcessor.process(); batchProcessor.batchProcessingContext.printIfVerbose("Finished"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); System.out.println(Throwables.getStackTraceAsString(e)); } }
From source file:se.vgregion.portal.rss.client.chain.UserOrganizationProcessor.java
/** * Load the replace value map./*from ww w . java 2 s .c o m*/ * * @param mapFile * - File reference to the replace value property file. * @throws ConfigurationException * an ConfigurationException has occurred * @throws UnsupportedEncodingException * an UnsupportedEncodingException has occurred */ public void setReplaceValues(File mapFile) throws ConfigurationException, UnsupportedEncodingException { try { LOGGER.debug("Map: {}", mapFile.getAbsolutePath()); PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setEncoding(ENCODING); pc.load(mapFile); replaceValues = new HashMap<String, String>(); for (@SuppressWarnings("unchecked") Iterator<String> it = pc.getKeys(); it.hasNext();) { String key = it.next(); String value = pc.getString(key); LOGGER.debug("Key: {} Value: {}", new Object[] { key, value }); if (!StringUtils.isBlank(value)) { value = (urlValueEncoding) ? URLEncoder.encode(value, ENCODING) : value; key = key.toLowerCase(LOCALE); replaceValues.put(key, value); } } } catch (UnsupportedEncodingException e) { String msg = "Encoding failure in mapping"; LOGGER.error(msg + " file [" + mapFilePathErrorMessage(mapFile) + "]", e); } catch (ConfigurationException e) { String msg = "Failed to load replaceValues mapping"; LOGGER.error(msg + " file [" + mapFilePathErrorMessage(mapFile) + "]", e); } }
From source file:umich.ms.batmass.filesupport.core.types.descriptor.FileDescriptor.java
/** * Recreates a FileDescriptor from a properties based file. * @param file The .file_desc file. It's up to you to check it's existence. * @return /*from ww w. j a v a2s . c o m*/ * @throws org.apache.commons.configuration.ConfigurationException */ public static FileDescriptor readFromFile(File file) throws ConfigurationException { PropertiesConfiguration conf = new PropertiesConfiguration(); conf.load(file); String uid = conf.getString(PROP_UID); String path = conf.getString(PROP_PATH); long size = conf.getLong(PROP_SIZE); // String parserType = conf.getString(PROP_PARSER_NAME); String[] children = conf.getStringArray(PROP_CHILDREN); String fileCategory = conf.getString(PROP_FILE_CATEGORY); String fileType = conf.getString(PROP_FILE_TYPE); ArrayList<Path> childPathList = new ArrayList<>(children.length); for (String childPath : children) { childPathList.add(Paths.get(childPath)); } FileDescriptor desc = new FileDescriptor(Paths.get(path), size, childPathList, uid); desc.setFileCategory(fileCategory); desc.setFileType(fileType); return desc; }
From source file:xcmailrstarter.StarterConf.java
public StarterConf(String[] args) throws Exception { // get the server file-location XCM_HOME = System.getProperty("xcmailr.xcmstarter.home"); // get the config file-location String confFile = System.getProperty("ninja.external.configuration"); PropertiesConfiguration cfg = new PropertiesConfiguration(); cfg.setEncoding("utf-8"); cfg.setDelimiterParsingDisabled(true); String confPath = XCM_HOME + "/" + confFile; // try to load the config cfg.load(confPath); final Configuration conf = (Configuration) cfg; XCM_DB_URL = conf.getString("ebean.datasource.databaseUrl"); XCM_DB_USER = conf.getString("ebean.datasource.username"); XCM_DB_PASS = conf.getString("ebean.datasource.password"); XCM_DB_DRIVER = conf.getString("ebean.datasource.databaseDriver"); XCM_PORT = conf.getInt("application.port"); XCM_CONTEXT_PATH = conf.getString("application.basedir"); XCM_HOST = conf.getString("application.host", "localhost"); }