Example usage for org.apache.commons.configuration XMLConfiguration setReloadingStrategy

List of usage examples for org.apache.commons.configuration XMLConfiguration setReloadingStrategy

Introduction

In this page you can find the example usage for org.apache.commons.configuration XMLConfiguration setReloadingStrategy.

Prototype

public void setReloadingStrategy(ReloadingStrategy strategy) 

Source Link

Usage

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

/**
 * Get plugin configuration.//  w ww .j  a  v a 2s . c o  m
 *
 * @param inPlugin
 *            input plugin
 * @return plugin configuration
 */
public static XMLConfiguration getPluginConfig(IPlugin inPlugin) {
    String file = "plugin_" + inPlugin.getClass().getSimpleName() + ".xml";
    XMLConfiguration config;
    try {
        config = new XMLConfiguration(ConfigCore.getKitodoConfigDirectory() + file);
    } catch (ConfigurationException e) {
        logger.error(e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());
    return config;
}

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

/**
 * Instantiates a new DB config reader.//from   w  w  w .  j av a  2 s.  co  m
 */
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:gda.util.persistence.LocalParameters.java

/**
 * @param configDir//from w ww .ja  va  2  s.  com
 * @param configName
 * @param createIfMissing
 * @param createAlways true if existing config in the cache is to be thrown away - re-reads the underlying file
 * @return XMLConfiguration
 * @throws ConfigurationException
 * @throws IOException
 */
public synchronized static XMLConfiguration getXMLConfiguration(String configDir, String configName,
        Boolean createIfMissing, boolean createAlways) throws ConfigurationException, IOException {
    // Instantiate the Configuration if it has not been instantiated
    if (configDir == null || configDir.isEmpty())
        throw new IllegalArgumentException("configDir is null or empty");
    if (!configDir.endsWith(File.separator))
        configDir += File.separator;
    final String fullName = getFullName(configDir, configName);
    if (createAlways && configList.containsKey(fullName)) {
        configList.remove(fullName);
    }
    if (configList.containsKey(fullName) == false) {
        XMLConfiguration config;

        // Try to open the file
        try {
            config = loadConfigurationFromFile(fullName);
        } catch (ConfigurationException e)
        // catch (NoClassDefFoundError e)
        {
            // Assume the error occured because the file does not exist

            // Throw exception if createIfMissing is false
            if (createIfMissing == false) {
                logger.error("Could not load " + configDir + configName + ".xml which will not be created");
                throw new ConfigurationException(e);
            }

            // else try to make it...
            try {
                File dir = new File(configDir);
                if (!dir.exists())
                    if (!dir.mkdirs()) {
                        throw new FileNotFoundException("Couldn't create directory: " + dir);
                    }
                File file = new File(fullName);
                PrintWriter out = new PrintWriter(new FileWriter(file));
                out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?>");
                out.println("<" + configName + ">");
                out.println("</" + configName + ">");
                out.close();
            } catch (IOException ee) {
                logger.error("Failed trying to create non-existent file " + fullName);
                throw new IOException(ee);
            }

            // ... and read it again
            try {
                config = loadConfigurationFromFile(fullName);
            } catch (ConfigurationException ee) {
                logger.error("Failed trying to read newly-created file " + fullName);
                throw new ConfigurationException(e);
            }

            logger.debug("Created configuration file: " + fullName);

        } // endif - create a missing file
        config.setReloadingStrategy(new FileChangedReloadingStrategy());
        configList.put(fullName, config);
        logger.debug("Loaded the configuration file: " + fullName);

    } // endif - instantiate a new configuration

    // return the configuration object
    return configList.get(fullName);
}

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

/**
 * Prepares a configuration object for testing a reload operation.
 * //from   ww w.  j a  va 2  s  . com
 * @return the initialized configuration
 * @throws ConfigurationException
 *             if an error occurs
 */
private XMLConfiguration setUpReloadTest() throws ConfigurationException {
    removeTestFile();
    conf.save(testSaveConf);
    XMLConfiguration c = new XMLConfiguration(testSaveConf);
    c.setReloadingStrategy(new FileAlwaysReloadingStrategy());
    conf.setProperty("test(0).entity", "newValue");
    conf.save(testSaveConf);
    return c;
}

From source file:org.apache.juddi.config.AppConfig.java

/**
 * Does the actual work of reading the configuration from System
 * Properties and/or juddiv3.properties file. When the juddiv3.properties
 * file is updated the file will be reloaded. By default the reloadDelay is
 * set to 1 second to prevent excessive date stamp checking.
 *//*from   ww  w.  j a v  a  2s  . c om*/
private void loadConfiguration() throws ConfigurationException {
    //Properties from system properties
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    compositeConfig.addConfiguration(new SystemConfiguration());
    //Properties from file
    //changed 7-19-2013 AO for JUDDI-627
    XMLConfiguration propConfig = null;
    final String filename = System.getProperty(JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY);
    if (filename != null) {
        propConfig = new XMLConfiguration(filename);
        try {
            loadedFrom = new File(filename).toURI().toURL();
            //   propConfig = new PropertiesConfiguration(filename);
        } catch (MalformedURLException ex) {
            try {
                loadedFrom = new URL("file://" + filename);
            } catch (MalformedURLException ex1) {
                log.warn("unable to get an absolute path to " + filename
                        + ". This may be ignorable if everything works properly.", ex1);
            }
        }
    } else {
        //propConfig = new PropertiesConfiguration(JUDDI_PROPERTIES);
        propConfig = new XMLConfiguration(JUDDI_PROPERTIES);
        loadedFrom = ClassUtil.getResource(JUDDI_PROPERTIES, this.getClass());
    }
    //Hey! this may break things
    propConfig.setAutoSave(true);

    log.info("Reading from properties file:  " + loadedFrom);
    long refreshDelay = propConfig.getLong(Property.JUDDI_CONFIGURATION_RELOAD_DELAY, 1000l);
    log.debug("Setting refreshDelay to " + refreshDelay);
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
    propConfig.setReloadingStrategy(fileChangedReloadingStrategy);
    compositeConfig.addConfiguration(propConfig);

    Properties properties = new Properties();
    if ("Hibernate".equals(propConfig.getString(Property.PERSISTENCE_PROVIDER))) {
        if (propConfig.containsKey(Property.DATASOURCE))
            properties.put("hibernate.connection.datasource", propConfig.getString(Property.DATASOURCE));
        if (propConfig.containsKey(Property.HBM_DDL_AUTO))
            properties.put("hibernate.hbm2ddl.auto", propConfig.getString(Property.HBM_DDL_AUTO));
        if (propConfig.containsKey(Property.DEFAULT_SCHEMA))
            properties.put("hibernate.default_schema", propConfig.getString(Property.DEFAULT_SCHEMA));
        if (propConfig.containsKey(Property.HIBERNATE_DIALECT))
            properties.put("hibernate.dialect", propConfig.getString(Property.HIBERNATE_DIALECT));
    }
    // initialize the entityManagerFactory.
    PersistenceManager.initializeEntityManagerFactory(propConfig.getString(Property.JUDDI_PERSISTENCEUNIT_NAME),
            properties);
    // Properties from the persistence layer 
    MapConfiguration persistentConfig = new MapConfiguration(getPersistentConfiguration(compositeConfig));

    compositeConfig.addConfiguration(persistentConfig);
    //Making the new configuration globally accessible.
    config = compositeConfig;
}

From source file:org.apache.juddi.v3.client.config.ClientConfig.java

/**
 * Does the actual work of reading the configuration from System
 * Properties and/or uddi.xml file. When the uddi.xml
 * file is updated the file will be reloaded. By default the reloadDelay is
 * set to 1 second to prevent excessive date stamp checking.
 *///www  .  j ava2 s . c  o  m
private void loadConfiguration(String configurationFile, Properties properties) throws ConfigurationException {
    //Properties from system properties
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    compositeConfig.addConfiguration(new SystemConfiguration());
    //Properties from XML file
    if (System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY) != null) {
        log.info("Using system property config override");
        configurationFile = System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY);
    }
    XMLConfiguration xmlConfig = null;
    if (configurationFile != null) {
        xmlConfig = new XMLConfiguration(configurationFile);
    } else {
        final String filename = System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY);
        if (filename != null) {
            xmlConfig = new XMLConfiguration(filename);
        } else {
            xmlConfig = new XMLConfiguration(DEFAULT_UDDI_CONFIG);
        }
    }
    log.info("Reading UDDI Client properties file " + xmlConfig.getBasePath() + " use -D"
            + UDDI_CONFIG_FILENAME_PROPERTY + " to override");
    this.configurationFile = xmlConfig.getBasePath();
    long refreshDelay = xmlConfig.getLong(Property.UDDI_RELOAD_DELAY, 1000l);
    log.debug("Setting refreshDelay to " + refreshDelay);
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
    xmlConfig.setReloadingStrategy(fileChangedReloadingStrategy);
    compositeConfig.addConfiguration(xmlConfig);
    //Making the new configuration globally accessible.
    config = compositeConfig;
    readConfig(properties);
}

From source file:org.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java

private void loadConfigurationFiles(CmsRepository associatedRepository, boolean logWarningIfNoXSDFileFound) {

    //Load BetaConcept Definition files from repository home directory
    //which exists in RepositoryContextImpl
    try {//from w  w  w.ja  v  a2s. co  m

        File[] schemaFiles = retrieveXmlSchemaFiles(associatedRepository, logWarningIfNoXSDFileFound);

        //Create a file configuration for each xsd file
        //This is done in order to track any changes made at runtime to XSD
        //in order to reload definition
        definitionFileConfigurations.put(associatedRepository.getId(), new ArrayList<FileConfiguration>());

        if (ArrayUtils.isEmpty(schemaFiles) && logWarningIfNoXSDFileFound) {
            logger.warn("Found no definition schema files for repository " + associatedRepository);
        } else {
            for (File defFile : schemaFiles) {
                try {
                    logger.debug("Loading definition file {} for repository {}", defFile.getAbsolutePath(),
                            associatedRepository.getId());

                    XMLConfiguration fileConfiguration = new XMLConfiguration(defFile);
                    fileConfiguration.setReloadingStrategy(new FileChangedReloadingStrategy());
                    definitionFileConfigurations.get(associatedRepository.getId()).add(fileConfiguration);
                } catch (Exception e) {
                    logger.error("Error loading definition file " + defFile.getAbsolutePath()
                            + " for repository " + associatedRepository.getId()
                            + "Most probably, it is not a valid XML file. All other definitions will be loaded",
                            e);

                    //Load an empty xml configuration
                    XMLConfiguration fileConfiguration = new XMLConfiguration();
                    definitionFileConfigurations.get(associatedRepository.getId()).add(fileConfiguration);
                }
            }
        }
    } catch (Throwable e) {
        throw new CmsException(e);
    }
}

From source file:org.goobi.production.cli.WebInterfaceConfig.java

/**
 * Get credentials.//from   ww w.j  a  v a2  s  .  c o m
 *
 * @param requestIp
 *            String
 * @param requestPassword
 *            String
 * @return list of Strings
 */
public static List<String> getCredentials(String requestIp, String requestPassword) {
    ArrayList<String> allowed = new ArrayList<>();
    try {
        XMLConfiguration config = new XMLConfiguration(
                ConfigCore.getKitodoConfigDirectory() + "kitodo_webapi.xml");
        config.setListDelimiter('&');
        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        int count = config.getMaxIndex("credentials");
        for (int i = 0; i <= count; i++) {
            String ip = config.getString("credentials(" + i + ")[@ip]");
            String password = config.getString("credentials(" + i + ")[@password]");
            if (requestIp.startsWith(ip) && requestPassword.equals(password)) {
                int countCommands = config.getMaxIndex("credentials(" + i + ").command");

                for (int j = 0; j <= countCommands; j++) {
                    allowed.add(config.getString("credentials(" + i + ").command(" + j + ")[@name]"));
                }
            }
        }
    } catch (Exception e) {
        allowed = new ArrayList<>();
    }
    return allowed;

}

From source file:org.goobi.production.export.ExportXmlLog.java

private HashMap<String, String> getMetsFieldsFromConfig(boolean useAnchor) {
    String xmlpath = "mets.property";
    if (useAnchor) {
        xmlpath = "anchor.property";
    }//from www  .  ja v  a  2s  . co  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 (Exception e) {
        fields = new HashMap<>();
    }
    return fields;
}

From source file:org.goobi.production.export.ExportXmlLog.java

private HashMap<String, String> getNamespacesFromConfig() {
    HashMap<String, String> nss = new HashMap<>();
    try {//from  www . j  a  va 2  s.co  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 (Exception e) {
        nss = new HashMap<>();
    }
    return nss;

}