Example usage for org.apache.commons.configuration FileConfiguration getProperty

List of usage examples for org.apache.commons.configuration FileConfiguration getProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileConfiguration getProperty.

Prototype

Object getProperty(String key);

Source Link

Document

Gets a property from the configuration.

Usage

From source file:gda.util.userOptions.UserOptions.java

public static UserOptions createFromTemplate(String configDir, String configName)
        throws ConfigurationException, IOException, Exception {
    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, false, true);
    UserOptions options = new UserOptions();
    options.title = config.getString(propTitle);
    options.containsDefault = true;/*  w w w  .j  a v a  2 s  . c  om*/
    Integer index = 0;
    while (true) {
        String tag = "options.option(" + index + ").";
        Object description = null;
        try {
            String keyName = config.getString(tag + propKeyName);
            /*
             * stop on last key
             */
            if (keyName == null)
                break;
            description = config.getProperty(tag + propDesc);
            Object type = config.getProperty(tag + propType);
            UserOption<? extends Object, ? extends Object> option;
            if (type != null && type.equals(typeBoolean)) {
                option = new UserOption<Object, Boolean>(description, config.getBoolean(tag + propDefValue));
            } else if (type != null && type.equals(typeString)) {
                option = new UserOption<Object, String>(description, config.getString(tag + propDefValue));
            } else if (type != null && type.equals(typeDouble)) {
                option = new UserOption<Object, Double>(description, config.getDouble(tag + propDefValue));
            } else if (type != null && type.equals(typeInteger)) {
                option = new UserOption<Object, Integer>(description, config.getInt(tag + propDefValue));
            } else {
                option = new UserOption<Object, Object>(description, config.getProperty(tag + propDefValue));
            }
            options.put(keyName, option);
            index++;
        } catch (Exception ex) {
            throw new Exception("Error reading option " + index, ex);
        }
    }
    return options;
}

From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java

private void setViewProperty(FileConfiguration fileConfig, String key, Object value) {
    if (!viewConfig.containsKey(key) || !viewConfig.getProperty(key).equals(value)) {
        LOG.debug("Setting property, key={} value={}", key, fileConfig.getProperty(key));
        viewConfig.setProperty(key, fileConfig.getProperty(key));
    }//ww w . ja va  2s. c  o m
}

From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java

private void loadView(FileConfiguration fileConfig) {
    Iterator fileIter = fileConfig.getKeys();
    while (fileIter.hasNext()) {
        String key = (String) fileIter.next();
        setViewProperty(fileConfig, key, fileConfig.getProperty(key));
    }/*www  . j a  v  a  2  s.co m*/
}

From source file:halfpipe.properties.UrlPropertiesSource.java

private void loadConfig(Map<String, Object> map, FileConfiguration config) throws ConfigurationException {
    config.load();// w  w  w.  ja  v  a2 s.  co m
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        map.put(key, config.getProperty(key));
    }
}

From source file:gda.util.persistence.LocalParametersTest.java

/**
 * Tests that a comma in a property value is not treated as a delimiter.
 * /*w ww.ja  v a 2  s .  c o  m*/
 * @throws Exception
 */
public void testCommaInProperty() throws Exception {
    final String configName = "commatest";
    final File configFile = TestUtils.getResourceAsFile(LocalParametersTest.class, configName + ".xml");
    final File configDirAsFile = configFile.getParentFile();
    final String configDir = configDirAsFile.getAbsolutePath();

    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, false);
    assertEquals(2, getKeysFromXMLConfiguration(config).size());
    // This needs to change if GDA-2492 is fixed
    assertEquals(Arrays.asList(new String[] { "1", "2", "3" }), config.getProperty("not-escaped"));
    assertEquals("1,2,3", config.getProperty("escaped"));
}

From source file:com.manydesigns.portofino.actions.admin.SettingsAction.java

@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY)
public Resolution update() {
    setupFormAndBean();//from ww  w  .ja  va 2 s. c om
    form.readFromRequest(context.getRequest());
    if (form.validate()) {
        logger.debug("Applying settings to model");
        try {
            FileConfiguration fileConfiguration = (FileConfiguration) configuration;
            Settings settings = new Settings();
            form.writeToObject(settings);
            fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName);
            fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage);
            fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage);
            if (!settings.preloadGroovyPages
                    || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES,
                        settings.preloadGroovyPages);
            }
            if (!settings.preloadGroovyClasses
                    || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES,
                        settings.preloadGroovyClasses);
            }
            fileConfiguration.save();
            logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath());
        } catch (Exception e) {
            logger.error("Configuration not saved", e);
            SessionMessages
                    .addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved"));
            return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
        }
        SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully"));
        return new RedirectResolution(this.getClass());
    } else {
        return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
    }
}

From source file:gda.util.userOptions.UserOptions.java

private Map<String, Object> getOptionValuesFromConfig(String configDir, String configName)
        throws ConfigurationException, IOException, Exception {
    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, true, true);
    Map<String, Object> options = new HashMap<String, Object>();
    Integer index = 0;/*from   w  ww  .  j  a v a 2s .c o m*/
    while (true) {
        String tag = "options.option(" + index + ").";
        try {
            String keyName = config.getString(tag + propKeyName);
            /*
             * stop on last key
             */
            if (keyName == null)
                break;
            Object option = config.getProperty(tag + propValue);
            options.put(keyName, option);
            index++;
        } catch (Exception ex) {
            throw new Exception("Error reading option.", ex);
        }
    }
    return options;
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

@Test
public void testConcurrentGetAndReload() throws Exception {
    // final FileConfiguration config = new
    // PropertiesConfiguration("test.properties");
    final FileConfiguration config = new XMLConfiguration("test.xml");
    config.setReloadingStrategy(new FileAlwaysReloadingStrategy());

    assertTrue("Property not found", config.getProperty("test.short") != null);

    Thread testThreads[] = new Thread[THREAD_COUNT];

    for (int i = 0; i < testThreads.length; ++i) {
        testThreads[i] = new ReloadThread(config);
        testThreads[i].start();//from  w ww  .j ava  2  s.  c  om
    }

    for (int i = 0; i < LOOP_COUNT; i++) {
        assertTrue("Property not found", config.getProperty("test.short") != null);
    }

    for (int i = 0; i < testThreads.length; ++i) {
        testThreads[i].join();
    }
}