List of usage examples for org.apache.commons.configuration PropertiesConfiguration load
public synchronized void load(Reader in) throws ConfigurationException
From source file:org.apache.james.modules.server.JmxConfigurationTest.java
@Test void fromPropertiesShouldReturnConfiguredValues() throws Exception { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.load(new StringReader("jmx.address=172.0.0.5\n" + "jmx.port=889\n")); assertThat(JmxConfiguration.fromProperties(configuration)).isEqualTo( new JmxConfiguration(JmxConfiguration.ENABLED, Optional.of(Host.from("172.0.0.5", 889)))); }
From source file:org.apache.james.modules.server.JmxConfigurationTest.java
@Test void fromPropertiesShouldReturnDisabledWhenConfiguredAsDisabled() throws Exception { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.load(new StringReader("jmx.enabled=false\n")); assertThat(JmxConfiguration.fromProperties(configuration)).isEqualTo(JmxConfiguration.DISABLED); }
From source file:org.apache.james.modules.server.JmxConfigurationTest.java
@Test void fromPropertiesShouldReturnDisabledWhenConfiguredAsDisabledWithHost() throws Exception { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.load(new StringReader("jmx.enabled=false\n" + "jmx.address=172.0.0.5\n" + "jmx.port=889\n")); assertThat(JmxConfiguration.fromProperties(configuration)).isEqualTo(JmxConfiguration.DISABLED); }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
public static void main(String args[]) { String configLocation = "./WebContent/WEB-INF/mfa.properties"; String ttsLocation = "./WebContent/WEB-INF/tts.properties"; PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfiguration tconfig = new PropertiesConfiguration(); Properties x = new Properties(); try {//w ww . j av a 2 s. co m InputStream is = new FileInputStream(configLocation); config.load(is); is.close(); InputStream tis = new FileInputStream(ttsLocation); tconfig.load(tis); tis.close(); MultiFacetedAuthentication mfa = new MultiFacetedAuthenticationImpl(config, tconfig); MFA.setInstance(mfa); } catch (Exception e) { e.printStackTrace(); System.exit(1); } CaptchaConfiguration captchaConfig = new CaptchaConfiguration(config); CaptchaImageResource captcha = new CaptchaImageResource(captchaConfig); InputStream is = null; try { is = new FileInputStream("./WebContent/images/jetspeedlogo98.jpg"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); MultiFacetedAuthenticationImpl.drain(is, bytes); byte[] background = bytes.toByteArray(); captcha.setBackgroundImage(background); } catch (IOException e) { captchaConfig.setUseImageBackground(false); } finally { if (is != null) { try { is.close(); } catch (IOException ee) { } } } captcha.init(); FileOutputStream fs = null; try { fs = new FileOutputStream("/data/result.jpg"); byte[] data = captcha.getImageBytes(); fs.write(data); } catch (IOException e) { logger.error("Unexpected exception during writing captcha image.", e); } finally { try { if (fs != null) fs.close(); } catch (IOException e) { } } }
From source file:org.apache.jetspeed.security.mfa.impl.MFAServletListener.java
public void contextInitialized(ServletContextEvent event) { String configLocation = "/WEB-INF/mfa.properties"; String ttsConfigLocation = "/WEB-INF/tts.properties"; try {/*w w w . ja va 2 s .c om*/ InputStream is = event.getServletContext().getResourceAsStream(configLocation); PropertiesConfiguration config = new PropertiesConfiguration(); config.load(is); is.close(); InputStream tis = event.getServletContext().getResourceAsStream(ttsConfigLocation); PropertiesConfiguration ttsConfig = new PropertiesConfiguration(); ttsConfig.load(tis); tis.close(); String rootPath = event.getServletContext().getRealPath("/"); MultiFacetedAuthentication mfa = new MultiFacetedAuthenticationImpl(config, ttsConfig, rootPath); MFA.setInstance(mfa); } catch (Throwable e) { logger.error("Unexpected error during loading configuration.", e); PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfiguration ttsConfig = new PropertiesConfiguration(); MultiFacetedAuthentication mfa = new MultiFacetedAuthenticationImpl(config, ttsConfig); MFA.setInstance(mfa); } }
From source file:org.apache.jetspeed.security.mfa.TestCaptchaImageResource.java
@Override public void setUp() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); InputStream input = null;/*from w ww . j av a2s . c om*/ try { input = Thread.currentThread().getContextClassLoader().getResourceAsStream("mfa.properties"); config.load(input); } finally { IOUtils.closeQuietly(input); } captchaConfig = new CaptchaConfiguration(config); captchaConfig.setUseImageBackground(true); ByteArrayOutputStream output = null; try { input = Thread.currentThread().getContextClassLoader().getResourceAsStream("Jetspeed_white_sm-1.jpg"); output = new ByteArrayOutputStream(); IOUtils.copy(input, output); background = output.toByteArray(); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } tempCaptchaFile = File.createTempFile("captcha-", ".jpg"); }
From source file:org.apache.s4.deploy.prodcon.TestProducerConsumer.java
private PropertiesConfiguration loadConfig() throws org.apache.commons.configuration.ConfigurationException, IOException { PropertiesConfiguration config = new PropertiesConfiguration(); config.load(Resources.getResource("default.s4.core.properties").openStream()); return config; }
From source file:org.archfirst.common.config.BaseConfigurationService.java
protected void load(String filename) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); try {//ww w . j a v a 2 s . co m propertiesConfiguration.load(filename); config.addConfiguration(propertiesConfiguration); } catch (ConfigurationException e) { throw new ExceptionInInitializerError(e); } logger.info("Loaded {}", filename); }
From source file:org.dataconservancy.packaging.tool.model.PropertiesConfigurationParametersBuilder.java
@Override public PackageGenerationParameters buildParameters(InputStream inputStream) throws ParametersBuildException { PackageGenerationParameters parameters = new PackageGenerationParameters(); PropertiesConfiguration props = new PropertiesConfiguration(); try {/*ww w. j a v a 2 s . c om*/ props.load(new InputStreamReader(inputStream)); } catch (ConfigurationException e) { throw new ParametersBuildException(e); } Iterator<String> keys = props.getKeys(); while (keys.hasNext()) { String key = keys.next(); parameters.addParam(key, Arrays.asList(props.getStringArray(key))); } return parameters; }
From source file:org.dataconservancy.packaging.tool.model.PropertiesPreferenceListBuilder.java
/** * {@inheritDoc}/*www .j av a 2 s.co m*/ * * <p> * This implementation expects a property's name to include two elements about a preference. These two elements are * to be separated by a dot ('.'). Element preceding the dot is the preference's name. Element following the dot is * the preference's valueType. No other dots are to be included in the properties name. * </p> * <p> * This implementation expects references to format-specific preferences files to be held in properties for * preferences whose name ends with {@code "-PGP-ref"}. * </p> * If any format-specific preferences files are detected, Attempts to load them will be made. {@code * PreferencesBuildException} is thrown if one these attempts fails. * @param is The input stream representing the preferences * @return Fully populated {@code PackageGenerationPreferences} object * @throws PreferencesBuildException if the preferences can not be loaded or read. */ @Override public PackageGenerationPreferences buildPackageGenerationPreferences(InputStream is) throws PreferencesBuildException { PackageGenerationPreferences preferences = new PackageGenerationPreferences(); PropertiesConfiguration props = new PropertiesConfiguration(); try { props.load(new InputStreamReader(is)); } catch (ConfigurationException e) { throw new PreferencesBuildException(e); } Iterator<String> keyIter = props.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); String[] propertyKeyTokens = key.split("\\."); String parameterName = propertyKeyTokens[0]; String parameterValueType = propertyKeyTokens[1]; preferences.setPreference( new Preference(parameterName, parameterValueType, Arrays.asList(props.getStringArray(key)))); } //Retrieves list of properties which hold references to format-specific preferences files. List<String> formatSpecificFileRefs = preferences.getReferencesToFormatSpecificPreferences(); //If properties which hold references for format-specific preferences files exist, //Loop through these references and load the files' content into format-specific preferences. if (formatSpecificFileRefs != null && !formatSpecificFileRefs.isEmpty()) { Map<String, Preference> formatSpecificPrefsMap = new HashMap<>(); String formatId = null; //Look up preferences for (String refKey : formatSpecificFileRefs) { //retrieve file's path and name from general preferences: String fileName = preferences.getPreference(refKey).getValues().get(0); //Create a file object from the provide fileName //TODO: should this be passed URI to a file instead of file path? How to load a file from anywhere //in the files system? File file = new File(fileName); props = new PropertiesConfiguration(); try { props.load(new FileReader(file)); } catch (ConfigurationException | FileNotFoundException e) { //TODO: Should builder just log this failure and move on? instead of throwing exception? throw new PreferencesBuildException( "Attempt to load package generation preferences for a specific" + "packaging format failed. " + e); } keyIter = props.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next(); String[] propertyKeyTokens = key.split("\\."); String parameterName = propertyKeyTokens[0]; String parameterValueType = propertyKeyTokens[1]; formatSpecificPrefsMap.put(parameterName, new Preference(parameterName, parameterValueType, Arrays.asList(props.getStringArray(key)))); if (parameterName.equals("package-format")) { formatId = formatSpecificPrefsMap.get(parameterName).getValues().get(0); } } if (formatId != null && !formatId.isEmpty()) { preferences.setPreferences(formatId, formatSpecificPrefsMap); } } } //else no further lookup will be performed. return preferences; }