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:org.jboss.forge.shell.env.ConfigurationImpl.java

@Unwraps
public Configuration getConfiguration() throws ConfigurationException {

    Project project = shell.getCurrentProject();
    if ((project != null) && !project.equals(this.currentProject)) {
        currentProject = project;//  www .  j  a  va  2 s.com
        ScopedConfigurationAdapter projectConfig = new ScopedConfigurationAdapter();
        XMLConfiguration projectLocalConfig;
        try {
            projectLocalConfig = new XMLConfiguration(
                    getProjectSettings(project).getUnderlyingResourceObject());
            projectLocalConfig.setEncoding("UTF-8");
        } catch (org.apache.commons.configuration.ConfigurationException e) {
            throw new ConfigurationException(e);
        }
        projectLocalConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        projectLocalConfig.setAutoSave(true);

        ConfigurationAdapter adapter = BeanManagerUtils.getContextualInstance(bm, ConfigurationAdapter.class,
                new ConfigAdapterQualifierLiteral());
        adapter.setParent(projectConfig);
        adapter.setDelegate(projectLocalConfig);
        adapter.setBeanManager(bm);
        projectConfig.setScopedConfiguration(ConfigurationScope.PROJECT, adapter);
        projectConfig.setScopedConfiguration(ConfigurationScope.USER, getUserConfig());

        this.projectConfig = projectConfig;
        return projectConfig;
    } else if ((project != null) && project.equals(this.currentProject)) {
        return projectConfig;
    }
    return getUserConfig();
}

From source file:org.jboss.forge.shell.env.ConfigurationImpl.java

public Configuration getUserConfig() throws ConfigurationException {
    // FIXME NPE caused when no project exists because config param is null
    if (userConfig == null) {
        XMLConfiguration globalXml;/*w  w  w  .  j  a v a2  s.c o m*/
        try {
            globalXml = new XMLConfiguration(environment.getUserConfiguration().getUnderlyingResourceObject());
            globalXml.setEncoding("UTF-8");
        } catch (org.apache.commons.configuration.ConfigurationException e) {
            throw new ConfigurationException(e);
        }
        globalXml.setReloadingStrategy(new FileChangedReloadingStrategy());
        globalXml.setAutoSave(true);

        ConfigurationAdapter adapter = BeanManagerUtils.getContextualInstance(bm, ConfigurationAdapter.class,
                new ConfigAdapterQualifierLiteral());
        adapter.setDelegate(globalXml);
        adapter.setBeanManager(bm);
        userConfig = new ScopedConfigurationAdapter(ConfigurationScope.USER, adapter);
    }
    return userConfig;
}

From source file:org.kitodo.config.Config.java

/**
 * Returns the configuration./*from   w  ww  . j  av a  2s .  c o m*/
 *
 * @param configFile
 *            file with configuration
 * @return the configuration
 */
static PropertiesConfiguration getConfig(String configFile) {
    if (Objects.isNull(config)) {
        synchronized (Config.class) {
            PropertiesConfiguration initialized = config;
            if (Objects.isNull(initialized)) {
                AbstractConfiguration.setDefaultListDelimiter('&');
                try {
                    initialized = new PropertiesConfiguration(configFile);
                } catch (ConfigurationException e) {
                    logger.warn(
                            "Loading of " + configFile + " failed. Trying to start with empty configuration.",
                            e);
                    initialized = new PropertiesConfiguration();
                }
                initialized.setListDelimiter('&');
                initialized.setReloadingStrategy(new FileChangedReloadingStrategy());
                initialized.setThrowExceptionOnMissing(true);
                config = initialized;
            }
        }
    }
    return config;
}

From source file:org.kitodo.config.ConfigMain.java

/**
 * Get properties from configuration file.
 *
 * @return PropertiesConfiguration object
 *//*from   w w w.  j  a  v  a 2  s . co m*/
private static PropertiesConfiguration getConfig() {
    if (config == null) {
        synchronized (ConfigMain.class) {
            PropertiesConfiguration initialized = config;
            if (initialized == null) {
                PropertiesConfiguration.setDefaultListDelimiter('&');
                try {
                    initialized = new PropertiesConfiguration(CONFIG_FILE);
                } catch (ConfigurationException e) {
                    logger.warn("Loading of {} failed. Trying to start with empty configuration. Exception: {}",
                            CONFIG_FILE, e);
                    initialized = new PropertiesConfiguration();
                }
                initialized.setListDelimiter('&');
                initialized.setReloadingStrategy(new FileChangedReloadingStrategy());
                config = initialized;
            }
        }
    }
    return config;
}

From source file:org.kitodo.config.ConfigProject.java

/**
 * Constructor for ConfigProject.//from ww w  .  j  a v  a2  s. c o m
 * 
 * @param projectTitle
 *            for which configuration is going to be read
 * @throws IOException
 *             if config file not found
 */
public ConfigProject(String projectTitle) throws IOException {
    KitodoConfigFile configFile = KitodoConfigFile.PROJECT_CONFIGURATION;

    if (!configFile.exists()) {
        throw new IOException("File not found: " + configFile.getAbsolutePath());
    }
    try {
        this.config = new XMLConfiguration(configFile.getAbsolutePath());
    } catch (ConfigurationException e) {
        logger.error(e.getMessage(), 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.projectTitle = "project(" + i + ").";
            break;
        }
    }

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

From source file:org.kitodo.config.OPACConfig.java

private static XMLConfiguration getConfig() {
    if (config != null) {
        return config;
    }//from www . j a  v a  2  s. co m
    KitodoConfigFile kitodoConfigOpacFile = KitodoConfigFile.OPAC_CONFIGURATION;
    if (!kitodoConfigOpacFile.exists()) {
        String message = "File not found: " + kitodoConfigOpacFile.getAbsolutePath();
        throw new ConfigException(message, new FileNotFoundException(message));
    }
    try {
        config = new XMLConfiguration(kitodoConfigOpacFile.getFile());
    } catch (ConfigurationException e) {
        logger.error(e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());
    return config;
}

From source file:org.kitodo.production.exporter.ExportXmlLog.java

private HashMap<String, String> getMetsFieldsFromConfig(boolean useAnchor) {
    String xmlpath = "mets." + PROPERTY;
    if (useAnchor) {
        xmlpath = "anchor." + PROPERTY;
    }/*from ww w  . j  a  v a2  s  .c  o m*/

    HashMap<String, String> fields = new HashMap<>();
    try {
        File file = new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_exportXml.xml");
        if (file.exists() && file.canRead()) {
            XMLConfiguration config = new XMLConfiguration(file);
            config.setListDelimiter('&');
            config.setReloadingStrategy(new FileChangedReloadingStrategy());

            int count = config.getMaxIndex(xmlpath);
            for (int i = 0; i <= count; i++) {
                String name = config.getString(xmlpath + "(" + i + ")[@name]");
                String value = config.getString(xmlpath + "(" + i + ")[@value]");
                fields.put(name, value);
            }
        }
    } catch (ConfigurationException | RuntimeException e) {
        logger.debug(e.getMessage(), e);
        fields = new HashMap<>();
    }
    return fields;
}

From source file:org.kitodo.production.exporter.ExportXmlLog.java

private HashMap<String, String> getNamespacesFromConfig() {
    HashMap<String, String> nss = new HashMap<>();
    try {//from w  w  w.  j av a 2 s .c  o m
        File file = new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_exportXml.xml");
        if (file.exists() && file.canRead()) {
            XMLConfiguration config = new XMLConfiguration(file);
            config.setListDelimiter('&');
            config.setReloadingStrategy(new FileChangedReloadingStrategy());

            int count = config.getMaxIndex("namespace");
            for (int i = 0; i <= count; i++) {
                String name = config.getString("namespace(" + i + ")[@name]");
                String value = config.getString("namespace(" + i + ")[@value]");
                nss.put(name, value);
            }
        }
    } catch (ConfigurationException | RuntimeException e) {
        logger.debug(e.getMessage(), e);
        nss = new HashMap<>();
    }
    return nss;

}

From source file:org.kitodo.production.metadata.display.helper.ConfigDisplayRules.java

/**
 * Reads given xml file into XMLConfiguration.
 *//*from  w w w.  ja  v a  2  s.c om*/
private ConfigDisplayRules() {
    String configPath = KitodoConfigFile.METADATA_DISPLAY_RULES.getAbsolutePath();
    try {
        config = new XMLConfiguration(configPath);
        config.setReloadingStrategy(new FileChangedReloadingStrategy());
        getDisplayItems();
    } catch (ConfigurationException e) {
        /*
         * no configuration file found, default configuration (textarea) will be used,
         * nothing to do here
         */
    }
}

From source file:org.kitodo.production.plugin.opac.pica.ConfigOpac.java

private static XMLConfiguration getConfig() {
    if (config != null) {
        return config;
    }/*from w  w w  .  ja v a 2 s  . c  om*/
    String configPfad = FilenameUtils.concat(PicaPlugin.getConfigDir(), PicaPlugin.OPAC_CONFIGURATION_FILE);
    if (!new File(configPfad).exists()) {
        String message = "File not found: ".concat(configPfad);
        throw new RuntimeException(message, new FileNotFoundException(message));
    }
    try {
        config = new XMLConfiguration(configPfad);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());
    return config;
}