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

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

Introduction

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

Prototype

public void setAutoSave(boolean autoSave) 

Source Link

Usage

From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurer.java

/**
 * writes the {@link SahiProxyProperties#PROXY_PORT} value as {@link SahiProxyProperties#SAHI_PROPERTY_PROXY_PORT_MAPPING}
 * property to sahiConfigPropertyFilePath!
 *//* w  w w . j a  v  a 2 s. c o  m*/
protected void modifySahiProxyPortPropertiesConfiguration(String sahiConfigPropertyFilePath, Properties props) {
    final String sahiProxyPort = props.getProperty(SahiProxyProperties.PROXY_PORT);
    if (sahiProxyPort != null) {
        try {
            PropertiesConfiguration propConfig = new PropertiesConfiguration(sahiConfigPropertyFilePath);
            propConfig.setAutoSave(true);
            final String sahiMappingPropertyProxyPort = SahiProxyProperties.SAHI_PROPERTY_PROXY_PORT_MAPPING;

            if (propConfig.containsKey(sahiMappingPropertyProxyPort)) {
                propConfig.clearProperty(sahiMappingPropertyProxyPort);
            }
            //remove property after the test execution, so that the installation can't break
            addToModifiedPropertiesMap(sahiConfigPropertyFilePath, sahiMappingPropertyProxyPort, null);
            propConfig.addProperty(sahiMappingPropertyProxyPort, sahiProxyPort);
            logger.debug("modify properties file '{}' with '{}={}'", sahiConfigPropertyFilePath,
                    sahiMappingPropertyProxyPort, sahiProxyPort);
        } catch (ConfigurationException e) {
            logger.error("modify sahi properties went wrong", e);
        }
    }
}

From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurer.java

/**
 * Modifies the properties file 'propFilePathToConfig' with assigned key from the resource properties.
 *///w  w  w .j a  va 2 s .  c  om
protected void modifyPropertiesConfiguration(String propFilePathToConfig, List<String> updateKeys,
        Properties resourceProps) {
    try {
        PropertiesConfiguration propConfig = new PropertiesConfiguration(propFilePathToConfig);
        propConfig.setAutoSave(true);
        Properties temProps = new Properties();
        for (String propKey : updateKeys) {
            String resolve = resolve(resourceProps.getProperty(propKey), resourceProps);
            if (resolve != null) {
                if (propConfig.containsKey(propKey)) {
                    addToModifiedPropertiesMap(propFilePathToConfig, propKey, propConfig.getProperty(propKey));
                    propConfig.clearProperty(propKey);
                }
                temProps.put(propKey, resolve);
                propConfig.addProperty(propKey, resolve);
            }
        }
        logger.debug("modify properties file '{}' with '{}'", propFilePathToConfig, temProps.toString());
    } catch (ConfigurationException e) {
        logger.error("modify sahi properties went wrong", e);
    }

}

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  www .  j  av a 2  s .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);

        }
    });
}