Example usage for org.apache.commons.configuration2 PropertiesConfiguration PropertiesConfiguration

List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration PropertiesConfiguration

Introduction

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

Prototype

public PropertiesConfiguration() 

Source Link

Document

Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().

Usage

From source file:de.tor.tribes.util.GlobalDefaults.java

/**
 * Add a property//  w  ww .  j av a 2 s  . c  om
 */

public static void loadDefaults() {
    GLOBAL_DEFAULTS = new PropertiesConfiguration();
    GLOBAL_DEFAULTS.addProperty("attack.movement", false);
    GLOBAL_DEFAULTS.addProperty("attack.planer.check.amount", 20000);
    GLOBAL_DEFAULTS.addProperty("attack.planer.enable.check", true);
    GLOBAL_DEFAULTS.addProperty("attack.script.attacks.in.overview", true);
    GLOBAL_DEFAULTS.addProperty("attack.script.attacks.in.place", true);
    GLOBAL_DEFAULTS.addProperty("attack.script.attacks.in.village.info", true);
    GLOBAL_DEFAULTS.addProperty("attack.script.attacks.on.confirm.page", true);
    GLOBAL_DEFAULTS.addProperty("check.updates.on.startup", true);
    GLOBAL_DEFAULTS.addProperty("church.frame.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("clipboard.notification", true);
    GLOBAL_DEFAULTS.addProperty("clock.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("command.sleep.time", 150);
    GLOBAL_DEFAULTS.addProperty("conquers.frame.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("default.browser", "");
    GLOBAL_DEFAULTS.addProperty("default.mark", 0);
    GLOBAL_DEFAULTS.addProperty("default.skin", "default");
    GLOBAL_DEFAULTS.addProperty("delete.farm.reports.on.exit", true);
    GLOBAL_DEFAULTS.addProperty("draw.attacks.by.default", false);
    GLOBAL_DEFAULTS.addProperty("extended.attack.vectors", false);
    GLOBAL_DEFAULTS.addProperty("extended.text.attacks", false);
    GLOBAL_DEFAULTS.addProperty("form.config.frame.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("half.ribbon.size", false);
    GLOBAL_DEFAULTS.addProperty("highlight.tribes.villages", false);
    GLOBAL_DEFAULTS.addProperty("include.support", true);
    GLOBAL_DEFAULTS.addProperty("inform.on.updates", true);
    GLOBAL_DEFAULTS.addProperty("main.size.height",
            (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 50);
    GLOBAL_DEFAULTS.addProperty("main.size.width",
            (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight() - 50);
    GLOBAL_DEFAULTS.addProperty("map.marker.transparency", 80);
    GLOBAL_DEFAULTS.addProperty("map.showcontinents", true);
    GLOBAL_DEFAULTS.addProperty("map.zoom.max", 3.0);
    GLOBAL_DEFAULTS.addProperty("map.zoom.min", 0.4);
    GLOBAL_DEFAULTS.addProperty("map.zoom.in.out.factor", 1.06);
    GLOBAL_DEFAULTS.addProperty("mark.villages.on.minimap", true);
    GLOBAL_DEFAULTS.addProperty("max.density.troops", 65000);
    GLOBAL_DEFAULTS.addProperty("max.farm.space", 20000);
    GLOBAL_DEFAULTS.addProperty("farm.popup.use.real", false);
    GLOBAL_DEFAULTS.addProperty("max.loss.ratio", 50);
    GLOBAL_DEFAULTS.addProperty("max.sim.rounds", 500);
    GLOBAL_DEFAULTS.addProperty("no.welcome", false);
    GLOBAL_DEFAULTS.addProperty("notify.duration", 1);
    GLOBAL_DEFAULTS.addProperty("obst.server", "");
    GLOBAL_DEFAULTS.addProperty("parser.movement.plan", "imported");
    GLOBAL_DEFAULTS.addProperty("parser.movement.delete.all.on.import", "false");
    GLOBAL_DEFAULTS.addProperty("proxySet", false);
    GLOBAL_DEFAULTS.addProperty("proxyHost", "");
    GLOBAL_DEFAULTS.addProperty("proxyPort", 8080);
    GLOBAL_DEFAULTS.addProperty("proxyType", 0);
    GLOBAL_DEFAULTS.addProperty("proxyUser", "");
    GLOBAL_DEFAULTS.addProperty("proxyPassword", "");
    GLOBAL_DEFAULTS.addProperty("radar.size", 60); //in minutes
    GLOBAL_DEFAULTS.addProperty("red.width", 0);
    GLOBAL_DEFAULTS.addProperty("red.height", 0);
    GLOBAL_DEFAULTS.addProperty("report.server.port", 8080);
    GLOBAL_DEFAULTS.addProperty("ribbon.minimized", false);
    GLOBAL_DEFAULTS.addProperty("screen.dir", ".");
    GLOBAL_DEFAULTS.addProperty("search.frame.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("show.barbarian", true);
    GLOBAL_DEFAULTS.addProperty("show.live.countdown", true);
    GLOBAL_DEFAULTS.addProperty("show.map.popup", true);
    GLOBAL_DEFAULTS.addProperty("show.mouseover.info", false);
    GLOBAL_DEFAULTS.addProperty("show.popup.conquers", true);
    GLOBAL_DEFAULTS.addProperty("show.popup.farm.space", true);
    GLOBAL_DEFAULTS.addProperty("show.popup.ranks", true);
    GLOBAL_DEFAULTS.addProperty("show.sectors", true);
    GLOBAL_DEFAULTS.addProperty("show.ruler", true);
    GLOBAL_DEFAULTS.addProperty("show.church", true);
    GLOBAL_DEFAULTS.addProperty("show.watchtower", true);
    GLOBAL_DEFAULTS.addProperty("show.ruler", true);
    GLOBAL_DEFAULTS.addProperty("sos.mark.all.duplicates.as.fake", "true");
    GLOBAL_DEFAULTS.addProperty("standard.defense.split", "heavy=0/spy=50/sword=500/archer=500/spear=500");
    GLOBAL_DEFAULTS.addProperty("standard.off", "catapult=50/light=3000/ram=300/axe=7000/marcher=500");
    GLOBAL_DEFAULTS.addProperty("stats.frame.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("support.tolerance", 0);
    GLOBAL_DEFAULTS.addProperty("systray.enabled", SystrayHelper.isSystraySupported());
    GLOBAL_DEFAULTS.addProperty("tag.frame.menu.visible", true);
    GLOBAL_DEFAULTS.addProperty("tag.frame.table.visibility", "true;true;true;false");
    GLOBAL_DEFAULTS.addProperty("tap.height", 0);
    GLOBAL_DEFAULTS.addProperty("tap.width", 0);
    GLOBAL_DEFAULTS.addProperty("text.attacks.per.file", "10");
    GLOBAL_DEFAULTS.addProperty("village.order", 0);
    GLOBAL_DEFAULTS.addProperty("watchtower.frame.alwaysOnTop", false);
    GLOBAL_DEFAULTS.addProperty("zip.text.attacks", false);

    for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
        GLOBAL_DEFAULTS.addProperty(unit.getName() + ".color", "#ff0000");
    }

    GLOBAL_DEFAULTS.addProperty("layer.order",
            "Markierungen;" + "Drfer;" + "Dorfsymbole;" + "Truppendichte;" + "Notizmarkierungen;"
                    + "Angriffe;" + "Untersttzungen;" + "Zeichnungen;" + "Kirchenradien;" + "Wachturmradien");

    //Default templates
    GLOBAL_DEFAULTS.addProperty("attack.template.header", "<Standard>");
    GLOBAL_DEFAULTS.addProperty("attack.template.header.internal", "templates/attack_header.tmpl");
    GLOBAL_DEFAULTS.addProperty("attack.template.block", "<Standard>");
    GLOBAL_DEFAULTS.addProperty("attack.template.block.internal", "templates/attack_block.tmpl");
    GLOBAL_DEFAULTS.addProperty("attack.template.footer", "<Standard>");
    GLOBAL_DEFAULTS.addProperty("attack.template.footer.internal", "templates/attack_footer.tmpl");
    GLOBAL_DEFAULTS.addProperty("report.list.bbexport.template",
            de.tor.tribes.util.bb.ReportListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("attack.bbexport.template",
            de.tor.tribes.util.AttackToBBCodeFormater.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("ally.report.stats.bbexport.template",
            de.tor.tribes.util.bb.AllyReportStatsFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("attack.list.bbexport.template",
            de.tor.tribes.util.bb.AttackListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("def.stats.bbexport.template",
            de.tor.tribes.util.bb.DefStatsFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("form.list.bbexport.template",
            de.tor.tribes.util.bb.FormListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("kills.stats.bbexport.template",
            de.tor.tribes.util.bb.KillStatsFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("marker.list.bbexport.template",
            de.tor.tribes.util.bb.MarkerListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("note.list.bbexport.template",
            de.tor.tribes.util.bb.NoteListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("overall.report.stats.bbexport.template",
            de.tor.tribes.util.bb.OverallReportStatsFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("point.stats.bbexport.template",
            de.tor.tribes.util.bb.PointStatsFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("report.list.bbexport.template",
            de.tor.tribes.util.bb.ReportListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("sos.list.bbexport.template",
            de.tor.tribes.util.bb.SosListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("tag.list.bbexport.template",
            de.tor.tribes.util.bb.TagListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("tribe.report.stats.bbexport.template",
            de.tor.tribes.util.bb.TribeReportStatsFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("troops.list.bbexport.template",
            de.tor.tribes.util.bb.TroopListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("village.list.bbexport.template",
            de.tor.tribes.util.bb.VillageListFormatter.STANDARD_TEMPLATE);

    GLOBAL_DEFAULTS.addProperty("winner.loser.stats.bbexport.template",
            de.tor.tribes.util.bb.WinnerLoserStatsFormatter.STANDARD_TEMPLATE);

    //TODO set to true after Moral is working
    GLOBAL_DEFAULTS.addProperty("show.popup.moral",
            ServerSettings.getSingleton().getMoralType() == ServerSettings.POINTBASED_MORAL);
}

From source file:io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.java

public Swagger2MarkupConfigBuilder() {
    this(new PropertiesConfiguration());
}

From source file:com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl.java

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

From source file:com.wavemaker.commons.properties.PropertiesWriter.java

/**
 * This api use apache commons property configuration to persist properties into file
 * and this api will avoid writing current date as comment into property file.
 *
 * @param os//from w  w  w.java  2s . c  o  m
 */
protected void storeSansDate(OutputStream os) {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.getLayout().setGlobalSeparator("=");
    Enumeration enumeration = properties.keys();
    boolean canComment = true;
    while (enumeration.hasMoreElements()) {
        String key = (String) enumeration.nextElement();
        if (canComment && StringUtils.isNotBlank(comments)) {
            configuration.getLayout().setComment(key, comments);
            canComment = false;
        }
        configuration.setProperty(key, properties.get(key));
    }
    try {
        configuration.getLayout().save(configuration, new OutputStreamWriter(os));

    } catch (ConfigurationException e) {
        throw new WMRuntimeException("Unable to write properties to output stream", e);
    } finally {
        IOUtils.closeSilently(os);
    }
    configuration.clear();
}

From source file:de.tor.tribes.ui.windows.AbstractDSWorkbenchFrame.java

public void restoreProperties() {
    if (frameProperties == null) {
        frameProperties = new PropertiesConfiguration();
        String dataDir = DataHolder.getSingleton().getDataDirectory();
        if (!new File(dataDir).exists()) {
            logger.warn("Data directory '" + dataDir + "' does not exist. Skip reading properties");
            return;
        }//w  w w. j a  v  a2s .  com

        try {
            frameProperties.read(new FileReader(dataDir + "/usergui.properties"));
            frameProperties.setThrowExceptionOnMissing(false);
        } catch (IOException | ConfigurationException ex) {
            logger.info("Cannot read properties", ex);
            return;
        }
    }
    String prefix = getPropertyPrefix();

    Dimension size = new Dimension(frameProperties.getInteger(prefix + ".width", getWidth()),
            frameProperties.getInteger(prefix + ".height", getHeight()));
    setPreferredSize(size);
    setSize(size);
    setLocation(frameProperties.getInteger(prefix + ".x", getX()),
            frameProperties.getInteger(prefix + ".y", getY()));
    setAlwaysOnTop(frameProperties.getBoolean(prefix + ".alwaysOnTop", false));

    restoreCustomProperties(frameProperties);
    toSave.add(this);
}

From source file:com.smartmarmot.dbforbix.config.Config.java

/**
 * Reads the configuration from a properties file
 * //from   w w w. ja va 2s .  c  o  m
 * @throws IOException
 */
public void readFileConfig() throws IOException, NullPointerException {
    LOG.debug("Parsing config file: " + configFile);
    calculateFileConfigHash();
    try (FileReader reader = new FileReader(configFile)) {
        PropertiesConfiguration pcfg = new PropertiesConfiguration();
        pcfg.read(reader);
        if (pcfg.containsKey(SET_PERSISTENCETYPE))
            persistenceType = pcfg.getString(SET_PERSISTENCETYPE);
        if (pcfg.containsKey(SET_PERSISTENCEDIR))
            persistenceDir = pcfg.getString(SET_PERSISTENCEDIR);
        if (pcfg.containsKey(SET_UPDATECONFIG))
            setUpdateConfigTimeout(pcfg.getInt(SET_UPDATECONFIG));
        if (pcfg.containsKey(SET_POOL_MAXACTIVE))
            maxActive = pcfg.getInt(SET_POOL_MAXACTIVE);
        if (pcfg.containsKey(SET_POOL_MAXIDLE))
            maxIdle = pcfg.getInt(SET_POOL_MAXIDLE);
        if (pcfg.containsKey(SET_LOGIN_TIMEOUT))
            loginTimeout = Integer.parseInt(pcfg.getString(SET_LOGIN_TIMEOUT));
        Iterator<?> it;
        it = pcfg.getKeys(GLOBAL_ZBXSRV);
        while (it.hasNext()) {
            String key = it.next().toString();
            String[] keyparts = key.split("\\.");
            if (keyparts.length == 3)
                readConfigZSRV(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key));
        }
        it = pcfg.getKeys(GLOBAL_DB);
        while (it.hasNext()) {
            String key = it.next().toString();
            String[] keyparts = key.split("\\.");
            if (keyparts.length == 3)
                readConfigDB(keyparts[0], keyparts[1], keyparts[2], pcfg.getString(key));
        }

    } catch (ConfigurationException e) {
        throw new IOException("Error in configuration: " + e.getLocalizedMessage(), e);
    }
}

From source file:org.exist.launcher.LauncherWrapper.java

public static PropertiesConfiguration getVMProperties() {
    final PropertiesConfiguration vmProperties = new PropertiesConfiguration();
    final java.nio.file.Path propFile = ConfigurationHelper.lookup("vm.properties");
    InputStream is = null;/*www. j  av a2  s .co  m*/
    try {
        if (Files.isReadable(propFile)) {
            is = Files.newInputStream(propFile);
        }
        if (is == null) {
            is = LauncherWrapper.class.getResourceAsStream("vm.properties");
        }
        if (is != null) {
            vmProperties.read(new InputStreamReader(is, "UTF-8"));
        }
    } catch (final IOException e) {
        System.err.println("vm.properties not found");
    } catch (ConfigurationException e) {
        System.err.println("exception reading vm.properties: " + e.getMessage());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (final IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
    return vmProperties;
}

From source file:org.linqs.psl.config.Config.java

public static void loadResource(InputStream stream, String resourceName) {
    try {/*from   www. ja  v a 2  s  .  c o m*/
        PropertiesConfiguration props = new PropertiesConfiguration();
        props.read(new InputStreamReader(stream));
        config.append(props);
    } catch (IOException | ConfigurationException ex) {
        throw new RuntimeException("Failed to load config resource: " + resourceName, ex);
    }

    log.debug("Configuration stream loaded: {}", resourceName);
}

From source file:org.linqs.psl.config.Config.java

public static void loadResource(String path) {
    try {// w  ww .j  a v a 2s  .  c  o m
        PropertiesConfiguration props = new PropertiesConfiguration();
        props.read(new FileReader(path));
        config.append(props);
    } catch (IOException | ConfigurationException ex) {
        throw new RuntimeException("Failed to load config resource: " + path, ex);
    }

    log.debug("Configuration file loaded: {}", path);
}

From source file:org.mitre.mpf.wfm.util.MpfPropertiesConfigurationBuilder.java

private void updateConfigurationSnapshot() {
    PropertiesConfiguration tmpConfig = new PropertiesConfiguration();

    // this will copy over each property one at a time,
    // essentially generating a "flat" config from the composite config
    ConfigurationUtils.copy(mpfCompositeConfig, tmpConfig);

    mpfConfigSnapshot = tmpConfig;//from   w w w.  j a v a2  s  . c om
}