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:org.goobi.production.importer.GoobiHotfolder.java

/**
 * Get instances.// ww w . ja  v  a 2s . c  om
 *
 * @return list of GoobiHotfolder objects
 */
public static List<GoobiHotfolder> getInstances() {
    logger.trace("config 1");
    List<GoobiHotfolder> answer = new ArrayList<>();
    logger.trace("config 2");

    try {
        XMLConfiguration config = new XMLConfiguration(
                ConfigCore.getKitodoConfigDirectory() + "kitodo_hotfolder.xml");

        logger.trace("config 3");

        config.setListDelimiter('&');

        logger.trace("config 4");
        config.setReloadingStrategy(new FileChangedReloadingStrategy());
        logger.trace("config 5");

        int count = config.getMaxIndex("hotfolder");
        logger.trace("config 6");

        for (int i = 0; i <= count; i++) {

            logger.trace("config 7");
            String name = config.getString("hotfolder(" + i + ")[@name]");
            logger.trace("config 8");
            URI folder = URI.create(config.getString("hotfolder(" + i + ")[@folder]"));
            logger.trace("config 9");
            Integer template = config.getInt("hotfolder(" + i + ")[@template]");
            logger.trace("config 10");

            String updateStrategy = config.getString("hotfolder(" + i + ")[@updateStrategy]");
            logger.trace("config 11");
            String collection = config.getString("hotfolder(" + i + ")[@collection]");
            logger.trace("config 12");
            if (name == null || name.equals("") || template == null) {
                logger.trace("config 13");
                break;
            }
            logger.trace("config 14");
            if (updateStrategy == null || updateStrategy.equals("")) {
                logger.trace("config 15");
                updateStrategy = "ignore";
            }
            if (collection.equals("")) {
                logger.trace("config 16");
                collection = null;
            }
            logger.trace("config 17");
            answer.add(new GoobiHotfolder(name, folder, template, updateStrategy, collection));
        }
        logger.trace("config 18");

    } catch (Exception e) {
        if (logger.isTraceEnabled()) {
            logger.trace("config 19" + e.getMessage());
        }
        return new ArrayList<>();
    }
    logger.trace("config 20");
    return answer;
}

From source file:org.goobi.production.properties.PropertyParser.java

/**
 * Get properties for task.// www.  j  a va 2  s  .com
 *
 * @param mySchritt
 *            Task object
 * @return list of ProcessProperty objects
 */
public static ArrayList<ProcessProperty> getPropertiesForStep(Task mySchritt) {
    Hibernate.initialize(mySchritt.getProcess());
    Hibernate.initialize(mySchritt.getProcess().getProject());
    String stepTitle = mySchritt.getTitle();
    String projectTitle = mySchritt.getProcess().getProject().getTitle();
    ArrayList<ProcessProperty> properties = new ArrayList<>();

    if (mySchritt.getProcess().isTemplate()) {
        return properties;
    }

    String path = ConfigCore.getKitodoConfigDirectory() + "kitodo_processProperties.xml";
    XMLConfiguration config;
    try {
        config = new XMLConfiguration(path);
    } catch (ConfigurationException e) {
        logger.error(e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());

    // run though all properties
    int countProperties = config.getMaxIndex("property");
    for (int i = 0; i <= countProperties; i++) {

        // general values for property
        ProcessProperty pp = new ProcessProperty();
        pp.setName(config.getString("property(" + i + ")[@name]"));
        pp.setContainer(config.getInt("property(" + i + ")[@container]"));

        // projects
        int count = config.getMaxIndex("property(" + i + ").project");
        for (int j = 0; j <= count; j++) {
            pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")"));
        }

        // project is configured
        if (pp.getProjects().contains("*") || pp.getProjects().contains(projectTitle)) {

            // showStep
            boolean containsCurrentStepTitle = false;
            count = config.getMaxIndex("property(" + i + ").showStep");
            for (int j = 0; j <= count; j++) {
                ShowStepCondition ssc = new ShowStepCondition();
                ssc.setName(config.getString("property(" + i + ").showStep(" + j + ")[@name]"));
                String access = config.getString("property(" + i + ").showStep(" + j + ")[@access]");
                boolean duplicate = config.getBoolean("property(" + i + ").showStep(" + j + ")[@duplicate]",
                        false);
                ssc.setAccessCondition(AccessCondition.getAccessConditionByName(access));
                if (ssc.getName().equals(stepTitle)) {
                    containsCurrentStepTitle = true;
                    pp.setDuplicationAllowed(duplicate);
                    pp.setCurrentStepAccessCondition(AccessCondition.getAccessConditionByName(access));
                }

                pp.getShowStepConditions().add(ssc);
            }

            // steptitle is configured
            if (containsCurrentStepTitle) {
                // showProcessGroupAccessCondition
                String groupAccess = config.getString("property(" + i + ").showProcessGroup[@access]");
                if (groupAccess != null) {
                    pp.setShowProcessGroupAccessCondition(
                            AccessCondition.getAccessConditionByName(groupAccess));
                } else {
                    pp.setShowProcessGroupAccessCondition(AccessCondition.WRITE);
                }

                // validation expression
                pp.setValidation(config.getString("property(" + i + ").validation"));
                // type
                pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type")));
                // (default) value
                pp.setValue(config.getString("property(" + i + ").defaultvalue"));

                // possible values
                count = config.getMaxIndex("property(" + i + ").value");
                for (int j = 0; j <= count; j++) {
                    pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")"));
                }
                properties.add(pp);
            }
        }
    }

    // add existing 'eigenschaften' to properties from config, so we have
    // all properties from config and
    // some of them with already existing 'eigenschaften'
    ArrayList<ProcessProperty> listClone = new ArrayList<>(properties);
    List<Property> propertyList = mySchritt.getProcess().getProperties();
    for (Property processProperty : propertyList) {

        for (ProcessProperty pp : listClone) {
            // TODO added temporarily a fix for NPE. Properties without
            // title shouldn't exist at all
            if (processProperty.getTitle() != null) {

                if (processProperty.getTitle().equals(pp.getName())) {
                    // pp has no pe assigned
                    if (pp.getProzesseigenschaft() == null) {
                        pp.setProzesseigenschaft(processProperty);
                        pp.setValue(processProperty.getValue());
                        pp.setContainer(processProperty.getContainer());
                    } else {
                        // clone pp
                        ProcessProperty pnew = pp.getClone(processProperty.getContainer());
                        pnew.setProzesseigenschaft(processProperty);
                        pnew.setValue(processProperty.getValue());
                        pnew.setContainer(processProperty.getContainer());
                        properties.add(pnew);
                    }
                }
            }
        }
    }
    return properties;
}

From source file:org.goobi.production.properties.PropertyParser.java

/**
 * Get properties for process./*from  w w w.j a v  a  2  s . c  o  m*/
 *
 * @param process
 *            object
 * @return ProcessProperty object
 */
public static ArrayList<ProcessProperty> getPropertiesForProcess(Process process) {
    Hibernate.initialize(process.getProject());
    String projectTitle = process.getProject().getTitle();
    ArrayList<ProcessProperty> properties = new ArrayList<>();
    if (process.isTemplate()) {
        List<Property> propertyList = process.getProperties();
        for (Property processProperty : propertyList) {
            ProcessProperty pp = new ProcessProperty();
            pp.setName(processProperty.getTitle());
            pp.setProzesseigenschaft(processProperty);
            pp.setType(Type.TEXT);
            pp.setValue(processProperty.getValue());
            pp.setContainer(processProperty.getContainer());
            properties.add(pp);
        }
        return properties;
    }
    String path = ConfigCore.getKitodoConfigDirectory() + "kitodo_processProperties.xml";
    XMLConfiguration config;
    try {
        config = new XMLConfiguration(path);
    } catch (ConfigurationException e) {
        logger.error(e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());

    // run though all properties
    int countProperties = config.getMaxIndex("property");
    for (int i = 0; i <= countProperties; i++) {

        // general values for property
        ProcessProperty pp = new ProcessProperty();
        pp.setName(config.getString("property(" + i + ")[@name]"));
        pp.setContainer(config.getInt("property(" + i + ")[@container]"));

        // projects
        int count = config.getMaxIndex("property(" + i + ").project");
        for (int j = 0; j <= count; j++) {
            pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")"));
        }

        // project is configured
        if (pp.getProjects().contains("*") || pp.getProjects().contains(projectTitle)) {

            // validation expression
            pp.setValidation(config.getString("property(" + i + ").validation"));
            // type
            pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type")));
            // (default) value
            pp.setValue(config.getString("property(" + i + ").defaultvalue"));

            // possible values
            count = config.getMaxIndex("property(" + i + ").value");
            for (int j = 0; j <= count; j++) {
                pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")"));
            }
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "add property A " + pp.getName() + " - " + pp.getValue() + " - " + pp.getContainer());
            }
            properties.add(pp);

        }
    }
    // add existing 'eigenschaften' to properties from config, so we have
    // all properties from config and some
    // of them with already existing 'eigenschaften'
    List<ProcessProperty> listClone = new ArrayList<>(properties);
    List<Property> propertyList = process.getProperties();
    for (Property processProperty : propertyList) {
        // TODO added temporarily a fix for NPE. Properties without title
        // shouldn't exist at all
        if (processProperty.getTitle() != null) {

            for (ProcessProperty pp : listClone) {
                if (processProperty.getTitle().equals(pp.getName())) {
                    // pp has no pe assigned
                    if (pp.getProzesseigenschaft() == null) {
                        pp.setProzesseigenschaft(processProperty);
                        pp.setValue(processProperty.getValue());
                        pp.setContainer(processProperty.getContainer());
                    } else {
                        // clone pp
                        ProcessProperty pnew = pp.getClone(processProperty.getContainer());
                        pnew.setProzesseigenschaft(processProperty);
                        pnew.setValue(processProperty.getValue());
                        pnew.setContainer(processProperty.getContainer());
                        if (logger.isDebugEnabled()) {
                            logger.debug("add property B " + pp.getName() + " - " + pp.getValue() + " - "
                                    + pp.getContainer());
                        }
                        properties.add(pnew);
                    }
                }
            }
        }
    }

    // add 'eigenschaft' to all ProcessProperties
    for (ProcessProperty pp : properties) {
        if (pp.getProzesseigenschaft() != null) {
            propertyList.remove(pp.getProzesseigenschaft());
        }
    }
    // create ProcessProperties to remaining 'eigenschaften'
    if (propertyList.size() > 0) {
        for (Property processProperty : propertyList) {
            ProcessProperty pp = new ProcessProperty();
            pp.setProzesseigenschaft(processProperty);
            pp.setName(processProperty.getTitle());
            pp.setValue(processProperty.getValue());
            pp.setContainer(processProperty.getContainer());
            pp.setType(Type.TEXT);
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "add property C " + pp.getName() + " - " + pp.getValue() + " - " + pp.getContainer());
            }
            properties.add(pp);

        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("all properties are " + properties.size());
    }

    return properties;
}

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;// w  w w .  j a v a 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;
        try {/*  www .ja v  a  2  s  .co  m*/
            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.jhub1.agent.configuration.PropertiesImpl.java

public PropertiesImpl() throws ConfigurationException {
    reloadingStrategy = new ManagedReloadingStrategy();
    config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    config.addConfiguration(new PropertiesConfiguration("agent.properties"));
    config.addConfiguration(new PropertiesConfiguration("agent.internal.properties"));
    try {/*from ww w.  ja va  2s. c o  m*/
        XMLConfiguration fromFile = new XMLConfiguration("settings.xml");
        fromFile.setReloadingStrategy(reloadingStrategy);
        reloadFlag = true;
        config.addConfiguration(fromFile);
    } catch (ConfigurationException ce) {
        log.error("Problem with loading custom configuration: " + ce.getMessage());
    }
    config.addConfiguration(new XMLConfiguration("settings.default.xml"));
}

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   w ww .  java2  s .c om

    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 {// www  . jav a2  s.c  om
        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.soaplab.services.Config.java

/**************************************************************************
 * Add given XML files as a new configuration to 'cfg' composite
 * configuration. Return true on success.
 **************************************************************************/
private static boolean addXMLConfiguration(CompositeConfiguration cfg, String configFilename) {
    try {/*from w w w.  ja  va2 s.c o  m*/
        XMLConfiguration xmlConfig = new XMLConfiguration(configFilename);
        if (isExistingConfig(xmlConfig))
            return true;
        xmlConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        cfg.addConfiguration(xmlConfig);
        return true;
    } catch (ConfigurationException e) {
        log.error("Loading XML configuration from '" + configFilename + "' failed: " + e.getMessage());
        return false;
    }
}

From source file:org.soaplab.services.DefaultAnalysisInventory.java

/**************************************************************************
 * Check if the property containing filename with an analysis list
 * (or filenames, actually) has changed since the last time we saw
 * it. If yes, reload analysis list(s) defined in this property.
 *************************************************************************/
protected synchronized void reloadConfig() {

    // find the filename(s) with our analysis list(s)
    String[] fileNames = Config.get().getStringArray(Config.PROP_APPLIST_FILENAME);
    if (fileNames == null || fileNames.length == 0) {
        if (!warningIssued) {
            log.warn("Property '" + Config.PROP_APPLIST_FILENAME + "' not found.");
            warningIssued = true;//ww  w.j  a  v a  2s  .co m
        }
        configs = null;
        lastUsedFileNames = null;
        appList = new Hashtable<String, Vector<AnalysisInstallation>>();
        return;
    }

    // has PROP_APPLIST_FILENAME changed since last visit?
    String joined = StringUtils.join(fileNames, ",");
    if (!joined.equals(lastUsedFileNames)) {
        warningIssued = false;
        List<XMLConfiguration> configsList = new ArrayList<XMLConfiguration>();
        for (int i = 0; i < fileNames.length; i++) {
            try {
                XMLConfiguration config = new XMLConfiguration(fileNames[i]);
                config.setReloadingStrategy(new FileChangedReloadingStrategy() {
                    public void reloadingPerformed() {
                        super.reloadingPerformed(); // because of updateLastModified();
                        readConfigs();
                    }
                });
                configsList.add(config);
                log.info("Using analysis list file '" + fileNames[i] + "'");
            } catch (ConfigurationException e) {
                log.error("Loading analysis list from '" + fileNames[i] + "' failed: " + e.getMessage());
            }
        }
        if (configsList.size() > 0) {
            configs = configsList.toArray(new XMLConfiguration[] {});
            readConfigs();
            lastUsedFileNames = joined;
        } else {
            configs = null;
            lastUsedFileNames = null;
            appList = new Hashtable<String, Vector<AnalysisInstallation>>();
        }
    }

    // try to trigger reloading of individual XML file names (if
    // they changed)
    if (configs != null) {
        for (int i = 0; i < configs.length; i++)
            configs[i].isEmpty();
    }

}