Example usage for org.apache.commons.configuration PropertiesConfiguration getFile

List of usage examples for org.apache.commons.configuration PropertiesConfiguration getFile

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration getFile.

Prototype

public File getFile() 

Source Link

Document

Return the file where the configuration is stored.

Usage

From source file:dk.dma.ais.abnormal.stat.AbnormalStatBuilderAppModule.java

@Provides
@Singleton/*from  w  ww.  j a  v a  2 s.  c  o m*/
Configuration provideConfiguration() {
    Configuration configuration = null;
    try {
        PropertiesConfiguration configFile = new PropertiesConfiguration("stat-builder.properties");
        configuration = configFile;
        LOG.info("Loaded configuration file " + configFile.getFile().toString() + ".");
    } catch (ConfigurationException e) {
        configuration = new BaseConfiguration();
        LOG.warn(e.getMessage() + ". Using blank configuration.");
    }
    return configuration;
}

From source file:edu.kit.dama.ui.simon.util.SimonConfigurator.java

private void setupProbes() {
    for (PropertiesConfiguration config : configs) {
        try {//from w  w  w  .j a  va 2s. c o  m
            String probeClass = config.getString("probe.class");
            String probeName = config.getString("probe.name",
                    "Unnamed Probe (" + config.getFile().getName() + ")");
            String probeCategory = config.getString("probe.category");
            if (probeClass != null) {
                LOGGER.debug(" - Creating instance for probe {}", probeName);
                Class clazz = Class.forName(probeClass);
                AbstractProbe probe = (AbstractProbe) clazz.newInstance();
                probe.setName(probeName);
                probe.setCategory(probeCategory);
                LOGGER.debug(" - Configuring probe instance");
                if (probe.configure(config)) {
                    LOGGER.debug("Probe successfully configured.");
                } else {
                    LOGGER.info("Failed to configure probe " + probeName + ". Ignoring probe.");
                }
                probes.add(probe);
            } else {
                LOGGER.info("Property probe.class for probe " + probeName + " not defined. Ignoring probe.");
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
            LOGGER.info("Failed to instantiate probe from file " + config.getPath() + ". Ignoring probe.", ex);
        }
    }
}

From source file:com.manydesigns.portofino.actions.admin.mail.MailSettingsAction.java

@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY)
public Resolution update() {
    setupFormAndBean();/*from w w w.ja v  a 2 s  . c  o m*/
    form.readFromRequest(context.getRequest());
    if (form.validate()) {
        logger.debug("Applying settings to app configuration");
        try {
            // mail configuration = portofino configuration + mail.properties defaults
            // CompositeConfiguration compositeConfiguration = (CompositeConfiguration) portofinoConfiguration;
            // FileConfiguration fileConfiguration = (FileConfiguration) compositeConfiguration.getConfiguration(0);
            // SUPERPAN ADD
            PropertiesConfiguration fileConfiguration = (PropertiesConfiguration) portofinoConfiguration;

            MailSettingsForm bean = new MailSettingsForm();
            form.writeToObject(bean);
            fileConfiguration.setProperty(MailProperties.MAIL_ENABLED, bean.mailEnabled);
            fileConfiguration.setProperty(MailProperties.MAIL_KEEP_SENT, bean.keepSent);
            fileConfiguration.setProperty(MailProperties.MAIL_QUEUE_LOCATION, bean.queueLocation);
            fileConfiguration.setProperty(MailProperties.MAIL_SMTP_HOST, bean.smtpHost);
            fileConfiguration.setProperty(MailProperties.MAIL_SMTP_PORT, bean.smtpPort);
            fileConfiguration.setProperty(MailProperties.MAIL_SMTP_SSL_ENABLED, bean.smtpSSL);
            fileConfiguration.setProperty(MailProperties.MAIL_SMTP_TLS_ENABLED, bean.smtpTLS);
            fileConfiguration.setProperty(MailProperties.MAIL_SMTP_LOGIN, bean.smtpLogin);
            fileConfiguration.setProperty(MailProperties.MAIL_SMTP_PASSWORD, bean.smtpPassword);
            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/mail/admin/settings.jsp");
        }
        SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully"));
        return new RedirectResolution(this.getClass());
    } else {
        return new ForwardResolution("/m/mail/admin/settings.jsp");
    }
}

From source file:org.apache.marmotta.platform.core.services.config.ConfigurationServiceImpl.java

protected void saveSecure(final PropertiesConfiguration conf) throws ConfigurationException {
    final File file = conf.getFile();
    try {//from   w  w w.  j ava 2 s  . c o m
        if (file == null) {
            throw new ConfigurationException("No file name has been set!");
        } else if ((file.createNewFile() || true) && !file.canWrite()) {
            throw new IOException("Cannot write to file " + file.getAbsolutePath() + ". Is it read-only?");
        }
    } catch (IOException e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
    log.debug("Saving {}", file.getAbsolutePath());

    final String fName = file.getName();
    try {
        int lastDot = fName.lastIndexOf('.');
        lastDot = lastDot > 0 ? lastDot : fName.length();

        final Path configPath = file.toPath();
        // Create a tmp file next to the original
        final Path tmp = Files.createTempFile(configPath.getParent(), fName.substring(0, lastDot) + ".",
                fName.substring(lastDot));
        try {
            Files.copy(configPath, tmp, StandardCopyOption.COPY_ATTRIBUTES,
                    StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException iox) {
            log.error("Could not create temp-file {}: {}", tmp, iox.getMessage());
            throw iox;
        }
        log.trace("using temporary file: {}", tmp);
        // Save the config to the tmp file
        conf.save(tmp.toFile());

        log.trace("tmp saved, now replacing the original file: {}", configPath);
        // Replace the original with the tmp file
        try {
            try {
                Files.move(tmp, configPath, StandardCopyOption.REPLACE_EXISTING,
                        StandardCopyOption.ATOMIC_MOVE);
            } catch (AtomicMoveNotSupportedException amnx) {
                log.trace("atomic move not available: {}, trying without", amnx.getMessage());
                Files.move(tmp, configPath, StandardCopyOption.REPLACE_EXISTING);
            }
        } catch (IOException iox) {
            log.error("Could not write to {}, a backup was created in {}", configPath, tmp);
            throw iox;
        }
        log.info("configuration successfully saved to {}", configPath);
    } catch (final Throwable t) {
        throw new ConfigurationException("Unable to save the configuration to the file " + fName, t);
    }
}