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

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

Introduction

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

Prototype

public void load() throws ConfigurationException 

Source Link

Document

Load the configuration from the underlying location.

Usage

From source file:org.gss_project.gss.server.configuration.GSSConfigurationFactory.java

/**
 * @return the configuration object// www .ja  v  a  2s .  com
 */
public synchronized static DataConfiguration getConfiguration() {
    try {
        if (configuration == null) {
            PropertiesConfiguration gssConfig = (PropertiesConfiguration) getClass(
                    PropertiesConfiguration.class.getCanonicalName()).newInstance();
            gssConfig.setBasePath("");
            gssConfig.setFileName(configFilename);
            gssConfig.setEncoding("ISO-8859-7");
            // Set automatic reloading.
            gssConfig.setReloadingStrategy(new VfsFileChangedReloadingStrategy());
            gssConfig.load();
            // Decorator.
            configuration = new DataConfiguration(gssConfig);
        }
        return configuration;
    } catch (ClassNotFoundException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    } catch (InstantiationException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    } catch (IllegalAccessException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    } catch (ConfigurationException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    }
}

From source file:org.unitime.timetable.util.MessageResources.java

private Configuration getConfiguration(String name) {
    Configuration configuration = null;
    URL url = Thread.currentThread().getContextClassLoader().getResource(name);
    if (url != null) {
        PropertiesConfiguration pc = new PropertiesConfiguration();
        pc.setURL(url);//  w w w  .j av a2 s.  co m

        // Set reloading strategy 
        String dynamicReload = ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload", null);
        if (dynamicReload != null && dynamicReload.equalsIgnoreCase("true")) {
            long refreshDelay = Constants.getPositiveInteger(
                    ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload_interval"), 15000);

            FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
            strategy.setRefreshDelay(refreshDelay);
            pc.setReloadingStrategy(strategy);

            pc.addConfigurationListener(new MessageResourcesCfgListener(pc.getBasePath()));
        }

        try {
            pc.load();
            configuration = pc;
        } catch (ConfigurationException e) {
            Debug.error("Message Resources configuration exception: " + e.getMessage());
        }
    }

    return configuration;
}

From source file:pl.otros.vfs.browser.demo.TestBrowser.java

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

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override//from w w w.  ja v a  2s  .c o  m
        public void run() {
            tryLoadSubstanceLookAndFeel();
            final JFrame f = new JFrame("OtrosVfsBrowser demo");
            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());
                            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);

        }
    });
}