Example usage for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy

List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy

Introduction

In this page you can find the example usage for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy.

Prototype

FileChangedReloadingStrategy

Source Link

Usage

From source file:de.sub.goobi.config.ConfigProjects.java

/**
 * Constructor.//from   w  w w  . j  ava 2s. c  o  m
 *
 * @param projectTitle
 *            project title
 * @param configPfad
 *            config path
 */
public ConfigProjects(String projectTitle, String configPfad) throws IOException {
    if (!(new File(configPfad)).exists()) {
        throw new IOException("File not found: " + configPfad);
    }
    try {
        this.config = new XMLConfiguration(configPfad);
    } catch (ConfigurationException e) {
        logger.error(e);
        this.config = new XMLConfiguration();
    }
    this.config.setListDelimiter('&');
    this.config.setReloadingStrategy(new FileChangedReloadingStrategy());

    int countProjects = this.config.getMaxIndex("project");
    for (int i = 0; i <= countProjects; i++) {
        String title = this.config.getString("project(" + i + ")[@name]");
        if (title.equals(projectTitle)) {
            this.projektTitel = "project(" + i + ").";
            break;
        }
    }

    try {
        this.config.getBoolean(this.projektTitel + "createNewProcess.opac[@use]");
    } catch (NoSuchElementException e) {
        this.projektTitel = "project(0).";
    }

}

From source file:it.grid.storm.config.ConfigReader.java

public ConfigReader(String configurationPathname, int refresh) {

    if (configurationPathname != null) {
        if (refresh < 0)
            refresh = 0;//from   w ww .j  av  a 2s. c o m
        this.refresh = refresh;
        this.configurationPathname = configurationPathname;
        log.info("Configuration file {}. Refresh rate: {} seconds", configurationPathname, refresh);

        try {
            FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
            strategy.setRefreshDelay(refresh);
            PropertiesConfiguration properties = new PropertiesConfiguration(configurationPathname);
            log.debug("Configuration properties:");
            String key;
            for (Iterator<?> i = properties.getKeys(); i.hasNext();) {
                key = (String) i.next();
                log.debug("{} = {}", key, properties.getProperty(key).toString());
            }
            properties.setReloadingStrategy(strategy);
            this.c = new CompositeConfiguration();
            ((CompositeConfiguration) this.c).addConfiguration(properties);
            log.info("Configuration read successfully.");
        } catch (ConfigurationException e) {
            this.c = makeEmptyConfiguration();
            log.error("Configuration parsing error: {}", e.getMessage(), e);
        }
    } else {
        throw new NullPointerException("Null configuration pathname.");
    }
}

From source file:de.unigoettingen.sub.commons.contentlib.servlet.model.ContentServerConfiguration.java

/************************************************************************************
 * get singleton object/*from  w w  w.  j a v a2 s  .  c o  m*/
 ************************************************************************************/
synchronized public static ContentServerConfiguration getInstance() {
    if (instance == null) {
        instance = new ContentServerConfiguration();
        try {
            File file = new File(Util.getBaseFolderAsFile(), "contentServerConfig.xml");
            instance.config = new XMLConfiguration(file);
            instance.config.setReloadingStrategy(new FileChangedReloadingStrategy());
        } catch (ConfigurationException e) {
            LOGGER.error("ConfigurationException occured", e);
            instance.config = new XMLConfiguration();
        }
    }
    return instance;
}

From source file:com.gamma.dam.conf.db.DBConfigReader.java

/**
 * Instantiates a new DB config reader.//from   w w  w.  j av  a2s .com
 */
private DBConfigReader() {
    String basePath = ResourceProperties.instance().getValue(ResourceProperties.DATABASE_CONF);
    String home = System.getProperty("DAM_HOME");
    if (home != null) {
        basePath = home + File.separator + basePath;
    }
    try {
        XMLConfiguration xml = new XMLConfiguration(basePath);
        ReloadingStrategy strategy = new FileChangedReloadingStrategy();
        xml.setReloadingStrategy(strategy);
        Node node = xml.getRoot();
        if (node.hasChildren()) {
            for (ConfigurationNode n : node.getChildren()) {
                DBConfig db = new DBConfig();
                String name = null;
                if (n.getAttributeCount() > 0) {
                    for (ConfigurationNode attr : n.getAttributes()) {
                        switch (attr.getName()) {
                        case "id":

                            break;
                        case "name":
                            name = (String) attr.getValue();
                            break;

                        default:
                            break;
                        }
                    }
                }

                db.parse(n);
                dbs.put(name, db);
            }
        }
    } catch (ConfigurationException e) {
        throw new DAMConfigurationException(e);
    }
}

From source file:apacheCommonsTest.testConfig.java

@Test
public void config() throws ConfigurationException, FileNotFoundException, DocumentException {

    //xml config test
    DOMConfigurator.configureAndWatch("res/gameConfig/log4j.xml");
    XMLConfiguration goodsxml = new XMLConfiguration("res/goods.xml");
    HierarchicalConfiguration.Node node = goodsxml.getRoot();
    int count = node.getChild(0).getAttributeCount(); //
    String id = (String) node.getChild(0).getAttribute(3).getValue();

    SAXReader read = new SAXReader();
    Document doc = null;//from   w  w  w . j a v a2s  .co  m
    doc = read.read(new FileInputStream("res/goods.xml"));

    XMLConfiguration xmlConfiguration = new XMLConfiguration(
            Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_LEVEL);
    //        AttributeMap nodeList= (AttributeMap) xmlConfiguration.getDocument().getElementsByTagName("itemDrop");

    //        Boolean auto = xmlConfiguration.getBoolean("basic.autoRelaodConfig",false) ;
    //        long  refresh=xmlConfiguration.getLong("basic.refreshDelay");
    //        System.out.println(auto);
    //        FileChangedReloadingStrategy reloadingStrategy=new FileChangedReloadingStrategy();
    //        reloadingStrategy.setRefreshDelay(xmlConfiguration.getLong("basic.refreshDelay"));
    //        xmlConfiguration.setReloadingStrategy(reloadingStrategy);

    //properties config
    PropertiesConfiguration config = new PropertiesConfiguration("res/client.properties");
    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); //default 5000
    config.setReloadingStrategy(strategy);
    System.out.println(config.getInt("num"));
    System.out.println(config.getString("host", "127.0.0.1"));

}

From source file:com.xtesy.core.internals.impl.Settings.java

/**
 * @author Wasiq B//from  w w w. j  a v  a2s .c o m
 * @throws ConfigurationException
 * @throws FileNotFoundException
 * @since 04-Jul-2015 6:17:05 pm
 */
private void parseConfig() throws ConfigurationException, FileNotFoundException {
    String file = getString(Constants.TEST_CONFIG_FILE);
    if (file == null) {
        file = "test.properties";
    }
    final URL url = FileUtils.getResource(file);
    if (url == null)
        throw new FileNotFoundException(file);
    this.prop = new PropertiesConfiguration(url);
    this.prop.setAutoSave(true);
    this.prop.setReloadingStrategy(new FileChangedReloadingStrategy());
    addConfiguration(this.prop);
}

From source file:eu.abc4trust.guice.configuration.ConfigurationParserTest.java

@Test
public void testPropertiesConfiguration() throws IOException {
    File tmp = TemporaryFileFactory.createTemporaryFile();
    String filename = tmp.getAbsolutePath();

    String credentialFilename = "credentials.file";
    String keystorageFilename = "keystorage.file";
    String tokensFilename = "tokens.file";
    String pseudonymsFilename = "pseudonyms.file";
    String defaultImagePath = "default.jpg";
    String imageCacheDir = "image_cache_dir";

    FileWriter writer = new FileWriter(tmp);
    writer.write(" credentialstorage_file" + "=" + credentialFilename + "\n");
    writer.write("keystorage_file" + " = " + keystorageFilename + "\n\n");
    writer.write("  pseudonyms_file" + "   =    " + pseudonymsFilename + "    \n");
    writer.write("tokenstorage_file" + "=" + tokensFilename + "\n");
    writer.write("default_image_path" + "=" + defaultImagePath + "\n");
    writer.write("image_cache_dir" + "=" + imageCacheDir + "\n");
    writer.close();/*  w ww.  j  a  va2 s . co m*/

    PropertiesConfiguration config;
    try {
        config = new PropertiesConfiguration(filename);

        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        ConfigurationParser configurationParser = new ConfigurationParser(config);
        AbceConfigurationImpl abceConfiguration = new AbceConfigurationImpl();
        configurationParser.loadConfiguration(abceConfiguration);
        assertEquals(abceConfiguration.getCredentialFile().getName(), credentialFilename);
        assertEquals(abceConfiguration.getKeyStorageFile().getName(), keystorageFilename);
        assertEquals(abceConfiguration.getPseudonymsFile().getName(), pseudonymsFilename);
        assertEquals(abceConfiguration.getTokensFile().getName(), tokensFilename);
        assertEquals(abceConfiguration.getDefaultImagePath(), defaultImagePath);
        assertEquals(abceConfiguration.getImageCacheDir().getName(), imageCacheDir);
    } catch (ConfigurationException e) {
        throw new RuntimeException("Could not load property configuration", e);
    }
}

From source file:com.w20e.socrates.config.ConfigurationResource.java

/**
 * Get configuration from URL. If it's a file base configuration (which
 * it is...) make sure to apply the file changed reloading strategy. 
 *
 * @param configUrl/*from   ww w  .j av  a 2  s . c o m*/
 *            an <code>URL</code> value
 * @throws ConfigurationException
 *             when the configuration couldn't be found
 * @return a <code>Configuration</code> value
 */
public Configuration getConfiguration(final URL configUrl) throws ConfigurationException {

    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(configUrl);

    builder.setReloadingStrategy(new FileChangedReloadingStrategy());

    return builder.getConfiguration();
}

From source file:com.freemedforms.openreact.engine.Configuration.java

public static void loadConfiguration(String defaultConfig, String overrideConfig) {
    logger.trace("Entered loadConfiguration");
    if (compositeConfiguration == null) {
        logger.info("Configuration object not present, instantiating");
        compositeConfiguration = new CompositeConfiguration();

        PropertiesConfiguration defaults = null;
        try {//ww  w  .  jav a 2s .c o  m
            logger.info("Attempting to create PropertiesConfiguration object for DEFAULT_CONFIG");
            defaults = new PropertiesConfiguration(defaultConfig);
            logger.info("Loading default configuration from " + defaultConfig);
            defaults.load();
        } catch (ConfigurationException e) {
            logger.error("Could not load default configuration from " + defaultConfig);
            logger.error(e);
        }
        if (overrideConfig != null) {
            PropertiesConfiguration overrides = null;
            try {
                logger.info("Attempting to create PropertiesConfiguration object for OVERRIDE_CONFIG");
                overrides = new PropertiesConfiguration();
                logger.info("Setting file for OVERRIDE_CONFIG");
                overrides.setFile(new File(overrideConfig));
                logger.info("Setting reload strategy for OVERRIDE_CONFIG");
                overrides.setReloadingStrategy(new FileChangedReloadingStrategy());
                logger.info("Loading OVERRIDE_CONFIG");
                overrides.load();
            } catch (ConfigurationException e) {
                logger.error("Could not load overrides", e);
            } catch (Exception ex) {
                logger.error(ex);
            }
            if (overrides != null) {
                compositeConfiguration.addConfiguration(overrides);
            }
        }
        // Afterwards, add defaults so they're read second.
        compositeConfiguration.addConfiguration(defaults);
    }
}

From source file:edu.umich.its.google.oauth.GoogleServiceAccount.java

static private void initProperties() {
    String propertiesFilePath = System.getProperty(SYSTEM_PROPERTY_FILE_PATH);
    File in = null;//  w  ww.  j a  va2s.co  m
    try {
        // loads the file from the tomcat directory

        if (!isEmpty(propertiesFilePath)) {
            in = new File(propertiesFilePath);
        } else {
            // loads the file from inside of the war
            String packagePath = GoogleServiceAccount.class.getPackage().getName().replace(".", File.separator);
            in = new File(GoogleServiceAccount.class.getClassLoader()
                    .getResource(packagePath + File.separator + SYSTEM_PROPERTY_FILE_DEFAULT_NAME).toURI());
        }
        if (in != null) {
            config = new PropertiesConfiguration(in);
            config.setReloadingStrategy(new FileChangedReloadingStrategy());
        }
    } catch (Exception err) {
        M_log.error("Failed to load system properties(googleServiceProps.properties) for GoogleServiceAccount",
                err);
    } finally {
    }
}