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

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

Introduction

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

Prototype

public void setFile(File file) 

Source Link

Document

Set the file where the configuration is stored.

Usage

From source file:ch.descabato.browser.BackupBrowser.java

public static void main2(final String[] args)
        throws InterruptedException, InvocationTargetException, SecurityException, IOException {
    if (args.length > 1)
        throw new IllegalArgumentException(
                "SYNTAX:  java... " + BackupBrowser.class.getName() + " [initialPath]");

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override//from w ww .j  a v  a2 s.  co  m
        public void run() {
            tryLoadSubstanceLookAndFeel();
            final JFrame f = new JFrame("OtrosVfsBrowser demo");
            f.addWindowListener(finishedListener);
            Container contentPane = f.getContentPane();
            contentPane.setLayout(new BorderLayout());
            DataConfiguration dc = null;
            final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
            File favoritesFile = new File("favorites.properties");
            propertiesConfiguration.setFile(favoritesFile);
            if (favoritesFile.exists()) {
                try {
                    propertiesConfiguration.load();
                } catch (ConfigurationException e) {
                    e.printStackTrace();
                }
            }
            dc = new DataConfiguration(propertiesConfiguration);
            propertiesConfiguration.setAutoSave(true);
            final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null);
            comp.setSelectionMode(SelectionMode.FILES_ONLY);
            comp.setMultiSelectionEnabled(true);
            comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    FileObject[] selectedFiles = comp.getSelectedFiles();
                    System.out.println("Selected files count=" + selectedFiles.length);
                    for (FileObject selectedFile : selectedFiles) {
                        try {
                            FileSize fileSize = new FileSize(selectedFile.getContent().getSize());
                            System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString());
                            Desktop.getDesktop()
                                    .open(new File(new URI(selectedFile.getURL().toExternalForm())));
                            //                byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l);
                            //                JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes)));
                            //                JDialog d = new JDialog(f);
                            //                d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI());
                            //                d.getContentPane().add(sp);
                            //                d.setSize(600, 400);
                            //                d.setVisible(true);
                        } catch (Exception e1) {
                            LOGGER.error("Failed to read file", e1);
                            JOptionPane.showMessageDialog(f,
                                    (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            });

            comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    f.dispose();
                    try {
                        propertiesConfiguration.save();
                    } catch (ConfigurationException e1) {
                        e1.printStackTrace();
                    }
                    System.exit(0);
                }
            });
            contentPane.add(comp);

            f.pack();
            f.setVisible(true);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }
    });
    while (!finished)
        Thread.sleep(100);
}

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 {//from www  .  j a  va 2 s.  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:com.mirth.connect.server.migration.Migrate3_1_0.java

private void migrateLog4jProperties() {
    PropertiesConfiguration log4jproperties = new PropertiesConfiguration();
    log4jproperties.setDelimiterParsingDisabled(true);
    log4jproperties.setFile(new File(ClassPathResource.getResourceURI("log4j.properties")));
    try {//from   w w w  .j  a  v a2  s  . c  o  m
        log4jproperties.load();

        String level = (String) log4jproperties.getProperty("log4j.logger.shutdown");
        if (level != null) {
            log4jproperties.setProperty("log4j.logger.undeploy", level);
            log4jproperties.clearProperty("log4j.logger.shutdown");
            Logger.getLogger("undeploy").setLevel(Level.toLevel(level));
        }

        level = (String) log4jproperties
                .getProperty("log4j.logger.com.mirth.connect.donkey.server.channel.RecoveryTask");
        if (StringUtils.isBlank(level)) {
            level = "INFO";
            log4jproperties.setProperty("log4j.logger.com.mirth.connect.donkey.server.channel.RecoveryTask",
                    level);
            Logger.getLogger("com.mirth.connect.donkey.server.channel.RecoveryTask")
                    .setLevel(Level.toLevel(level));
        }

        log4jproperties.save();
    } catch (ConfigurationException e) {
        logger.error("Failed to migrate log4j properties.");
    }
}

From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NamedList.java

/**
 * This creates a name filter that checks to see if the start of a host name
 * matches particular criteria or not. if it does then it will indicate
 * accordingly that the "Zabbix JSON API host" is a host or VM.
 *//*from   w  ww  .java  2s .com*/
public NamedList() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        namedSet = config.getString("data.logger.filter.names", namedSet);
        config.setProperty("data.logger.filter.names", namedSet);
        hostNames.addAll(Arrays.asList(namedSet.split(",")));
    } catch (ConfigurationException ex) {
        Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO,
                "Error loading the configuration of the named list filter");
    }
}

From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NameEndsFilter.java

/**
 * This creates a name filter that checks to see if the end of a host name
 * matches particular criteria or not. if it does then it will indicate accordingly
 * that the "Zabbix JSON API host" is a host or VM.
 *///from w ww .  j  av  a 2s . co m
public NameEndsFilter() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        ends = config.getString("data.logger.filter.begins", ends);
        config.setProperty("data.logger.filter.begins", ends);
        isHost = config.getBoolean("data.logger.filter.isHost", isHost);
        config.setProperty("data.logger.filter.isHost", isHost);
    } catch (ConfigurationException ex) {
        Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO,
                "Error loading the configuration of the name ends filter");
    }
}

From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NameBeginsFilter.java

/**
 * This creates a name filter that checks to see if the start of a host name
 * matches particular criteria or not. if it does then it will indicate accordingly
 * that the "Zabbix JSON API host" is a host or VM.
 *///from  w  ww  . jav a 2s  . c o m
public NameBeginsFilter() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        begins = config.getString("data.logger.filter.begins", begins);
        config.setProperty("data.logger.filter.begins", begins);
        isHost = config.getBoolean("data.logger.filter.isHost", isHost);
        config.setProperty("data.logger.filter.isHost", isHost);
    } catch (ConfigurationException ex) {
        Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO,
                "Error loading the configuration of the name begins filter");
    }
}

From source file:eu.tango.energymodeller.energypredictor.workloadpredictor.CpuRecentHistoryWorkloadPredictor.java

/**
 * This sets up a CPU Recent History Workload Predictor. The main need is to
 * establish the time window by which the workload predictor must work.
 *//*  w ww  .j a va2s.c o m*/
public CpuRecentHistoryWorkloadPredictor() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        readSettings(config);
    } catch (ConfigurationException ex) {
        Logger.getLogger(CpuOnlyEnergyPredictor.class.getName()).log(Level.SEVERE,
                "Taking the default load from the settings file did not work", ex);
    }
}

From source file:eu.tango.energymodeller.energypredictor.AveragePowerEnergyPredictor.java

/**
 * This creates a new average power energy predictor. The predictor when
 * running takes the last power reading and makes the assumption no change
 * will occur. An observation time window is used for taking the measurement,
 * which is set via a configuration file.
 *///w w w . j  a v a2 s .  co m
public AveragePowerEnergyPredictor() {
    try {
        if (database == null) {
            database = new DefaultDatabaseConnector();
        }
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {

            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        powerObservationTimeMin = config.getInt(
                "energy.modeller.energy.predictor.cpu.utilisation.observe_time.min", powerObservationTimeMin);
        config.setProperty("energy.modeller.energy.predictor.cpu.utilisation.observe_time.min",
                powerObservationTimeMin);
        powerObservationTimeSec = config.getInt(
                "energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec", powerObservationTimeSec);
        config.setProperty("energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec",
                powerObservationTimeSec);
        observationTime = powerObservationTimeSec + (int) TimeUnit.MINUTES.toSeconds(powerObservationTimeMin);
    } catch (ConfigurationException ex) {
        Logger.getLogger(AveragePowerEnergyPredictor.class.getName()).log(Level.SEVERE,
                "The average power energy predictor failed to initialise", ex);
    }
}

From source file:cz.cas.lib.proarc.common.config.AppConfiguration.java

private void buildConfiguration(CompositeConfiguration cc, File cfgFile) {
    try {/*  ww  w .  j a v  a 2s.co  m*/
        // envConfig contains interpolated properties
        PropertiesConfiguration envConfig = new PropertiesConfiguration();
        envConfig.addProperty(PROPERTY_APP_HOME, configHome.getPath());
        cc.addConfiguration(envConfig);
        // external configuration editable by users; UTF-8 expected
        PropertiesConfiguration external = new PropertiesConfiguration();
        external.setEncoding("UTF-8");
        FileChangedReloadingStrategy reloading = new FileChangedReloadingStrategy();
        external.setReloadingStrategy(reloading);
        external.setFile(cfgFile);
        cc.addConfiguration(external);
        try {
            // bundled default configurations
            Enumeration<URL> resources = AppConfiguration.class.getClassLoader()
                    .getResources(DEFAULT_PROPERTIES_RESOURCE);
            for (URL resource; resources.hasMoreElements();) {
                resource = resources.nextElement();
                LOG.log(Level.FINE, "classpath config: {0}", resource);
                cc.addConfiguration(new PropertiesConfiguration(resource));
            }
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    } catch (ConfigurationException ex) {
        LOG.log(Level.SEVERE, null, ex);
    }
}

From source file:com.mirth.connect.manager.ManagerController.java

private PropertiesConfiguration initializeProperties(String path, boolean alert) {
    PropertiesConfiguration properties = new PropertiesConfiguration();

    // Auto reload changes
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(1000);
    properties.setReloadingStrategy(fileChangedReloadingStrategy);
    properties.setFile(new File(path));

    if (properties.isEmpty() && alert) {
        alertErrorDialog("Could not load properties from file: " + path);
    }/*from   w w  w.  j av a 2  s  .com*/

    return properties;
}