List of usage examples for org.apache.commons.configuration PropertiesConfiguration setEncoding
public void setEncoding(String encoding)
From source file:org.roda.core.RodaCoreFactory.java
public static Configuration getConfiguration(String configurationFile) throws ConfigurationException { Path config = RodaCoreFactory.getConfigPath().resolve(configurationFile); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.setEncoding(RodaConstants.DEFAULT_ENCODING); if (FSUtils.exists(config)) { LOGGER.trace("Loading configuration from file {}", config); propertiesConfiguration.load(config.toFile()); RodaPropertiesReloadStrategy rodaPropertiesReloadStrategy = new RodaPropertiesReloadStrategy(); rodaPropertiesReloadStrategy.setRefreshDelay(5000); propertiesConfiguration.setReloadingStrategy(rodaPropertiesReloadStrategy); } else {/*from w w w .java2 s .c om*/ InputStream inputStream = RodaCoreFactory.class .getResourceAsStream("/" + RodaConstants.CORE_CONFIG_FOLDER + "/" + configurationFile); if (inputStream != null) { LOGGER.trace("Loading configuration from classpath {}", configurationFile); propertiesConfiguration.load(inputStream); } else { LOGGER.trace("Configuration {} doesn't exist", configurationFile); } } return propertiesConfiguration; }
From source file:org.wisdom.configuration.ApplicationConfigurationImpl.java
/** * This is important: We load stuff as UTF-8. * <p>//from w w w . java 2s. c o m * 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 ww w . j av a2 s. c om*/ propertiesConfiguration.load(file); } catch (ConfigurationException e) { return null; } return propertiesConfiguration; }
From source file:se.vgregion.portal.rss.client.chain.UserOrganizationProcessor.java
/** * Load the replace value map.// w w w. j a va 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: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);/*from w ww. ja va2 s .c o m*/ 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"); }