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

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

Introduction

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

Prototype

public void load(Reader in) throws ConfigurationException 

Source Link

Document

Reads a properties file and stores its internal structure.

Usage

From source file:bioLockJ.module.agent.MailAgent.java

/**
 * Used to obtain a new encrypted password hash when the admin email password is set.
 * @param password//from  w  w w  . ja v a2  s  .  com
 * @throws Exception
 */
public static void encryptAndStoreEmailPassword(final String propFile, final String password) throws Exception {
    final String encryptedPassword = encrypt(password);
    final PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(
            new PropertiesConfiguration());
    layout.load(new InputStreamReader(new FileInputStream(propFile)));
    final PropertyFileContainer props = Config.readProps(new File(propFile), null);
    props.setProperty(EMAIL_ENCRYPTED_PASSWORD, encryptedPassword);
    layout.save(new FileWriter(propFile, false));
    System.out.println("CONFIG FILE UPDATED WITH ENCRYPTED PASSWORD: " + encryptedPassword);
}

From source file:com.thoughtworks.go.agent.service.AgentAutoRegistrationProperties.java

public void scrubRegistrationProperties() {
    if (!exist()) {
        return;//from   w  w  w.j a  v  a 2s.c o m
    }
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.setIOFactory(new FilteringOutputWriterFactory());
        PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
        layout.setLineSeparator("\n");
        layout.load(reader());
        layout.save(new FileWriter(this.configFile));
    } catch (ConfigurationException | IOException e) {
        LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
    }
}

From source file:org.sonar.plugins.l10n.L10nHackyPropertiesUpdater.java

public static void main(String[] args) throws ConfigurationException, IOException {
    URL l10nRoot = FrenchPackPlugin.class.getResource(BundleSynchronizedMatcher.L10N_PATH);

    Collection<File> bundles = FileUtils.listFiles(FileUtils.toFile(l10nRoot), new String[] { "properties" },
            false);//from w  w  w.  ja v a 2 s .com

    for (File localizedBundle : bundles) {
        String originalVersion = localizedBundle.getName().replaceFirst("_fr\\.", ".");
        System.out.println("Processing " + localizedBundle + " looking for " + originalVersion);
        URL originalBundle = FrenchPackPlugin.class
                .getResource(BundleSynchronizedMatcher.L10N_PATH + originalVersion);
        if (originalBundle == null) {
            System.out.println("\tOriginal bundle not found");
        } else {
            System.out.println("\tOriginal bundle found, let's try to update the localized version");
            Properties localizedProps = new Properties();
            localizedProps.load(new FileInputStream(localizedBundle));

            PropertiesConfiguration config = new PropertiesConfiguration();
            PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
            layout.load(new InputStreamReader(FrenchPackPlugin.class
                    .getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + originalVersion)));

            for (@SuppressWarnings("unchecked")
            Iterator<String> it = config.getKeys(); it.hasNext();) {
                String key = it.next();
                Object localizedValue = localizedProps.get(key);
                if (localizedValue != null) {
                    config.setProperty(key, localizedValue);
                } else {
                    System.out.println("Nothing found for " + key);
                    String currentValue = config.getString(key);
                    config.setProperty(key, currentValue + " <== TODO");
                }
            }

            layout.save(new FileWriter(localizedBundle));

            System.out.println("\tFixing spaces");
            fixSpacesAroundEqualsAndScrewUpEncoding(localizedBundle);
            System.out.println("OK: file " + localizedBundle + " contains ready-to-translate updated file.");
        }
    }

}