Example usage for org.apache.commons.configuration Configuration setProperty

List of usage examples for org.apache.commons.configuration Configuration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration setProperty.

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:cross.Factory.java

private void configureThreadPool(final Configuration cfg) {
    this.maxthreads = cfg.getInt("cross.Factory.maxthreads", 1);
    final int numProcessors = Runtime.getRuntime().availableProcessors();
    this.log.debug("{} processors available to current runtime", numProcessors);
    if (this.maxthreads < 1) {
        this.log.debug("Automatically selecting {} threads according to number of available processors!",
                this.maxthreads);
        this.maxthreads = numProcessors;
    }//  w w  w  .j a  v  a  2 s. co  m
    this.maxthreads = (this.maxthreads < numProcessors) ? this.maxthreads : numProcessors;
    cfg.setProperty("cross.Factory.maxthreads", this.maxthreads);
    cfg.setProperty("maltcms.pipelinethreads", this.maxthreads);
    this.log.debug("Starting with Thread-Pool of size: " + this.maxthreads);
    initThreadPools();
}

From source file:net.sf.maltcms.chromaui.project.spi.project.ChromAUIProject.java

@Override
public UUID getId() {
    Configuration settings = getSettings();
    if (settings.containsKey(ProjectSettings.KEY_UID)) {
        return UUID.fromString((String) settings.getString(ProjectSettings.KEY_UID));
    } else {//w  ww.ja v  a2s  .c o  m
        UUID uid = UUID.randomUUID();
        settings.setProperty(ProjectSettings.KEY_UID, uid.toString());
        return uid;
    }
}

From source file:cross.ObjectFactory.java

@Override
public void configure(final Configuration cfg) {
    this.cfg = cfg;
    String[] contextLocations = null;
    if (this.cfg.containsKey(CONTEXT_LOCATION_KEY)) {
        log.debug("Using user-defined location: {}", (Object[]) this.cfg.getStringArray(CONTEXT_LOCATION_KEY));
        contextLocations = cfg.getStringArray(CONTEXT_LOCATION_KEY);
    }//from w  w  w  . ja v a 2  s  . c  o m
    if (contextLocations == null) {
        log.debug("No pipeline configuration found! Please define! Example: -c cfg/pipelines/chroma.mpl");
        return;
    }
    log.debug("Using context locations: {}", Arrays.toString(contextLocations));
    try {
        if (cfg.containsKey("maltcms.home")) {
            File f = new File(new File(cfg.getString("maltcms.home")),
                    "cfg/pipelines/xml/workflowDefaults.xml");
            if (f.exists()) {
                log.info("Using workflow defaults at: {}", f);
                cfg.setProperty("cross.applicationContext.workflowDefaults",
                        cfg.getString("cross.applicationContext.workflowDefaults.file"));
            }
        } else {
            log.info("Using workflow defaults from classpath.");
        }
        String[] defaultLocations = cfg.getStringArray("cross.applicationContext.defaultLocations");
        log.debug("Using default context locations: {}", Arrays.toString(defaultLocations));
        LinkedList<String> applicationContextLocations = new LinkedList<>(Arrays.asList(defaultLocations));
        applicationContextLocations.addAll(Arrays.asList(contextLocations));
        context = new DefaultApplicationContextFactory(applicationContextLocations, this.cfg)
                .createApplicationContext();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

public void storeCustomProperties(Configuration pConfig) {
    pConfig.setProperty(getPropertyPrefix() + ".menu.visible", centerPanel.isMenuVisible());
    pConfig.setProperty(getPropertyPrefix() + ".alwaysOnTop", jAlwaysOnTopBox.isSelected());

    PropertyHelper.storeTableProperties(jResultTable, pConfig, getPropertyPrefix());
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests whether the auto save mechanism is triggered by changes at a
 * subnode configuration./*  www.  j  av  a 2 s.c  om*/
 */
@Test
public void testAutoSaveWithSubnodeConfig() throws ConfigurationException {
    final String newValue = "I am autosaved";
    conf.setFile(testSaveConf);
    conf.setAutoSave(true);
    Configuration sub = conf.configurationAt("element2.subelement");
    sub.setProperty("subsubelement", newValue);
    assertEquals("Change not visible to parent", newValue, conf.getString("element2.subelement.subsubelement"));
    XMLConfiguration conf2 = new XMLConfiguration(testSaveConf);
    assertEquals("Change was not saved", newValue, conf2.getString("element2.subelement.subsubelement"));
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpServiceConfig.java

/**
 * Checks if protocols are defined in the ribbon "listOfServers" properties, which is not supported by ribbon itself.
 * If this is the case, remove them and set our custom "http.protocol" property instead to the protocol, if
 * it is set to "auto".//from  www .j  a v a2 s  .com
 */
private void applyRibbonHostsProcotol(String serviceId) {
    Configuration archaiusConfig = ArchaiusConfig.getConfiguration();

    String[] listOfServers = archaiusConfig.getStringArray(serviceId + RIBBON_PARAM_LISTOFSERVERS);
    String protocolForAllServers = archaiusConfig.getString(serviceId + HTTP_PARAM_PROTOCOL);

    // get protocols defined in servers
    Set<String> protocolsFromListOfServers = Arrays.stream(listOfServers)
            .filter(server -> StringUtils.contains(server, "://"))
            .map(server -> StringUtils.substringBefore(server, "://")).collect(Collectors.toSet());

    // skip further processing of no protocols defined
    if (protocolsFromListOfServers.isEmpty()) {
        return;
    }

    // ensure that only one protocol is defined. if not use the first one and write a warning to the log files.
    String protocol = new TreeSet<String>(protocolsFromListOfServers).iterator().next();
    if (protocolsFromListOfServers.size() > 1) {
        log.warn("Different protocols are defined for property {}: {}. Only protocol '{}' is used.",
                RIBBON_HOSTS_PROPERTY, StringUtils.join(listOfServers, LIST_SEPARATOR), protocol);
    }

    // if http protocol is not set to "auto" write a warning as well, because protocol is defined in server list as well
    if (!(StringUtils.equals(protocolForAllServers, RequestUtil.PROTOCOL_AUTO)
            || StringUtils.equals(protocolForAllServers, protocol))) {
        log.warn(
                "Protocol '{}' is defined for property {}: {}, but an other protocol is defined in the server list: {}. Only protocol '{}' is used.",
                protocolForAllServers, PROTOCOL_PROPERTY, StringUtils.join(listOfServers, LIST_SEPARATOR),
                protocol);
    }

    // remove protocol from list of servers and store default protocol
    List<String> listOfServersWithoutProtocol = Arrays.stream(listOfServers)
            .map(server -> StringUtils.substringAfter(server, "://")).collect(Collectors.toList());
    archaiusConfig.setProperty(serviceId + RIBBON_PARAM_LISTOFSERVERS,
            StringUtils.join(listOfServersWithoutProtocol, LIST_SEPARATOR));
    archaiusConfig.setProperty(serviceId + HTTP_PARAM_PROTOCOL, protocol);
}

From source file:ninja.utils.NinjaPropertiesImplTool.java

/**
 * This method checks that your configurations have set a 
 * application.secret=23r213r12r123/*from w  w  w  .j a v  a 2s  . c  o m*/
 * 
 * If application.secret is missing or is empty it will do the following:
 * - In dev and test mode it'll generate a new application secret and write the secret
 *   to both src/main/java/conf/application.conf and the classes dir were the compiled stuff
 *   goes.
 * - In prod it will throw a runtime exception and stop the server.
 */
public static void checkThatApplicationSecretIsSet(boolean isProd, String baseDirWithoutTrailingSlash,
        PropertiesConfiguration defaultConfiguration, Configuration compositeConfiguration) {

    String applicationSecret = compositeConfiguration.getString(NinjaConstant.applicationSecret);

    if (applicationSecret == null || applicationSecret.isEmpty()) {

        // If in production we stop the startup process. It simply does not make
        // sense to run in production if the secret is not set.
        if (isProd) {
            String errorMessage = "Fatal error. Key application.secret not set. Please fix that.";
            logger.error(errorMessage);
            throw new RuntimeException(errorMessage);
        }

        logger.info("Key application.secret not set. Generating new one and setting in conf/application.conf.");

        // generate new secret
        String secret = SecretGenerator.generateSecret();

        // set in overall composite configuration => this enables this instance to 
        // start immediately. Otherwise we would have another build cycle.
        compositeConfiguration.setProperty(NinjaConstant.applicationSecret, secret);

        // defaultConfiguration is: conf/application.conf (not prefixed)
        defaultConfiguration.setProperty(NinjaConstant.applicationSecret, secret);

        try {

            // STEP 1: Save in source directories:
            // save to compiled version => in src/main/target/
            String pathToApplicationConfInSrcDir = baseDirWithoutTrailingSlash + File.separator + "src"
                    + File.separator + "main" + File.separator + "java" + File.separator
                    + NinjaProperties.CONF_FILE_LOCATION_BY_CONVENTION;
            Files.createParentDirs(new File(pathToApplicationConfInSrcDir));
            // save to source
            defaultConfiguration.save(pathToApplicationConfInSrcDir);

            // STEP 2: Save in classes dir (target/classes or similar).
            // save in target directory (compiled version aka war aka classes dir)
            defaultConfiguration.save();

        } catch (ConfigurationException e) {
            logger.error("Error while saving new secret to application.conf.", e);
        } catch (IOException e) {
            logger.error("Error while saving new secret to application.conf.", e);
        }

    }

}

From source file:ninja.utils.NinjaPropertiesImplToolTest.java

@Test
public void testNothingHappensWhenApplicationSecretIsThere() throws Exception {

    PropertiesConfiguration defaultConfiguration = new PropertiesConfiguration();
    Configuration compositeConfiguration = new PropertiesConfiguration();
    compositeConfiguration.setProperty(NinjaConstant.applicationSecret, "secret");

    String uuid = UUID.randomUUID().toString();

    String baseDirWithoutTrailingSlash = "/tmp/ninja-test-" + uuid;

    boolean isProd = true;

    // works in prod mode
    NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd, baseDirWithoutTrailingSlash,
            defaultConfiguration, compositeConfiguration);
    assertFalse(new File(baseDirWithoutTrailingSlash + "src/main/java/conf/application.conf").exists());

    isProd = false;//w ww . j  a  va  2  s.  co m

    // also works in the other modes:
    NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd, baseDirWithoutTrailingSlash,
            defaultConfiguration, compositeConfiguration);

    assertFalse(new File(baseDirWithoutTrailingSlash + "src/main/java/conf/application.conf").exists());

    FileUtils.deleteDirectory(new File(baseDirWithoutTrailingSlash));

}

From source file:org.acmsl.queryj.api.placeholders.AbstractFillTemplateChainWrapper.java

/**
 * Provides the template placeholders within a {@link QueryJCommand}.
 * @param relevantOnly to include only the relevant ones: the ones that are necessary to
 * be able to find out if two template realizations are equivalent. Usually,
 * generation timestamps, documentation, etc. can be considered not relevant.
 * @param handlers the {@link FillHandler}s.
 * @return the {@link QueryJCommand}.//from  w w  w. j a  va  2s . com
 * @throws QueryJBuildException if the placeholders are unavailable.
 */
@NotNull
protected QueryJCommand providePlaceholders(final boolean relevantOnly,
        @NotNull final List<FillHandler<?>> handlers) throws QueryJBuildException {
    @NotNull
    final QueryJCommand result;

    @NotNull
    final Configuration t_Configuration = new SerializablePropertiesConfiguration();

    for (@NotNull
    final FillHandler<?> handler : handlers) {
        if ((!relevantOnly) || (!(handler instanceof NonRelevantFillHandler))) {
            t_Configuration.setProperty(handler.getPlaceHolder(), handler.getValue());
        } else {
            t_Configuration.setProperty(handler.getPlaceHolder(), "");
        }
    }

    result = new ConfigurationQueryJCommandImpl(t_Configuration,
            UniqueLogFactory.getLog(AbstractFillTemplateChainWrapper.class));

    return result;
}

From source file:org.acmsl.queryj.ConfigurationQueryJCommandImpl.java

/**
 * Specifies the setting for given key.// w  w  w .j ava  2  s .  c o  m
 * @param key the key.
 * @param value the value for such key.
 * @param configuration the {@link Configuration configuration} settings.
 * @param <T> the type.
 */
protected <T> void setSetting(@NotNull final String key, @Nullable final T value,
        @NotNull final Configuration configuration) {
    configuration.setProperty(key, value);
}