Example usage for org.apache.commons.configuration SubnodeConfiguration getBoolean

List of usage examples for org.apache.commons.configuration SubnodeConfiguration getBoolean

Introduction

In this page you can find the example usage for org.apache.commons.configuration SubnodeConfiguration getBoolean.

Prototype

public boolean getBoolean(String key, boolean defaultValue) 

Source Link

Usage

From source file:ee.ria.xroad.signer.tokenmanager.module.ModuleConf.java

private static Boolean getBoolean(SubnodeConfiguration section, String key, Boolean defaultValue) {
    try {/*from   w  w  w  . j a  va 2s.c om*/
        return section.getBoolean(key, defaultValue);
    } catch (ConversionException e) {
        throw new ConversionException(String.format("Invalid value of '%s' for module (%s), skipping...", key,
                section.getSubnodeKey()), e);
    }
}

From source file:ee.ria.xroad.signer.tokenmanager.module.ModuleConf.java

private static void parseSection(String uid, SubnodeConfiguration section) {
    boolean enabled = section.getBoolean(ENABLED_PARAM, true);

    if (SOFTKEY_TYPE.equalsIgnoreCase(uid)) {
        if (!enabled) {
            MODULES.remove(SoftwareModuleType.TYPE);
        }//from   ww  w  .  j ava2s.  co m

        return;
    }

    if (!enabled) {
        return;
    }

    String library = section.getString("library");

    if (StringUtils.isBlank(library)) {
        log.error("No pkcs#11 library specified for module ({}), skipping...", uid);

        return;
    }

    boolean verifyPin = getBoolean(section, SIGN_VERIFY_PIN_PARAM, false);
    boolean batchSigning = getBoolean(section, BATCH_SIGNING_ENABLED_PARAM, true);
    boolean readOnly = getBoolean(section, READ_ONLY_PARAM, false);
    String tokenIdFormat = section.getString(TOKEN_ID_FORMAT_PARAM);

    if (StringUtils.isBlank(tokenIdFormat)) {
        tokenIdFormat = DEFAULT_TOKEN_ID_FORMAT;
    }

    String signMechanismName = section.getString(SIGN_MECHANISM_PARAM);

    if (StringUtils.isBlank(signMechanismName)) {
        signMechanismName = DEFAULT_SIGN_MECHANISM_NAME;
    }

    Long signMechanism = getSupportedSignMechanismCode(signMechanismName);

    if (signMechanism == null) {
        log.error("Not supported sign mechanism ({}) specified for module ({}), skipping...", signMechanismName,
                uid);

        return;
    }

    PubKeyAttributes pubKeyAttributes = loadPubKeyAttributes(section);
    PrivKeyAttributes privKeyAttributes = loadPrivKeyAttributes(section);

    log.trace(
            "Read module configuration (UID = {}, library = {}, tokenIdFormat = {}"
                    + ", pinVerificationPerSigning = {}, batchSigning = {}, signMechanism = {}"
                    + ", pubKeyAttributes = {}, privKeyAttributes = {})",
            uid, library, tokenIdFormat, verifyPin, batchSigning, signMechanismName, pubKeyAttributes,
            privKeyAttributes);

    if (MODULES.containsKey(uid)) {
        log.warn("Module information already defined for {}, skipping...", uid);

        return;
    }

    MODULES.put(uid, new HardwareModuleType(uid, library, tokenIdFormat, verifyPin, batchSigning, readOnly,
            signMechanismName, privKeyAttributes, pubKeyAttributes));
}

From source file:net.datenwerke.sandbox.util.SandboxParser.java

public void configureSandboxService(SandboxService sandboxService, Configuration config) {
    if (!(config instanceof HierarchicalConfiguration))
        throw new IllegalArgumentException("Expected HierarchicalConfiguration format");

    HierarchicalConfiguration conf = (HierarchicalConfiguration) config;

    /* general properties */
    SubnodeConfiguration properties = null;
    try {// w  ww  . j  a  v a  2 s . com
        properties = conf.configurationAt("security.properties");
    } catch (IllegalArgumentException e) {
    }
    if (null != properties) {
        /* remote */
        boolean remoteConfig = properties.getBoolean("remote.configureService", false);
        if (remoteConfig) {
            boolean remote = properties.getBoolean("remote[@enable]", false);
            if (remote) {
                Integer poolsize = properties.getInteger("remote.jvm[@poolsize]", 2);
                Integer freelancersize = properties.getInteger("remote.jvm[@freelancersize]", 2);

                String vmArgs = properties.getString("remote.jvm.vmargs", null);
                Integer rmiMinPort = properties.getInteger("remote.jvm.rmi[@minport]", 10000);
                Integer rmiMaxPort = properties.getInteger("remote.jvm.rmi[@maxport]", 10200);

                sandboxService.shutdownJvmPool();
                JvmPoolImpl jvmPoolImpl = new JvmPoolImpl(
                        new JvmPoolConfigImpl(poolsize, freelancersize, new JvmInstantiatorImpl(rmiMinPort,
                                rmiMaxPort, null != vmArgs && "".equals(vmArgs.trim()) ? null : vmArgs)));
                sandboxService.initJvmPool(jvmPoolImpl);
            } else {
                sandboxService.shutdownJvmPool();
            }
        }

        /* daemons */
        Integer monitorCheckInterval = properties.getInteger("monitor[@checkinterval]", 10);
        sandboxService.setMonitorDaemonCheckInterval(monitorCheckInterval);
        Integer monitorWatchdogCheckInterval = properties.getInteger("monitor[@watchdogCheckinterval]", 10000);
        sandboxService.setMonitorWatchdogCheckInterval(monitorWatchdogCheckInterval);

        /* codesource */
        boolean enableCodesource = properties.getBoolean("codesource[@enable]", false);
        sandboxService.setCodesourceSecurityChecks(enableCodesource);
    }

    /* sandboxes */
    parse(config);
    for (Entry<String, SandboxContext> e : getRestrictionSets().entrySet())
        sandboxService.registerContext(e.getKey(), e.getValue());
}

From source file:edu.stolaf.cs.wmrserver.TransformProcessor.java

/**
 * Internal implementation of #prepareMapperPackage() and
 * #prepareReducerPackage() that works for either, determined by the
 * transformType argument.// w  ww.ja v  a 2  s .  co  m
 */
protected File prepareTransformPackage(TransformType transformType, String transformSource, String language)
        throws IOException, ValidationException, CompilationException {
    // Get the given language's configuration, checking whether the language
    // exists in the configuration in the first place
    SubnodeConfiguration languageConf;
    try {
        languageConf = m_wmrConfig.configurationAt(language);
    } catch (IllegalArgumentException ex) {
        throw new ValidationException("Specified source code language is not recognized.", language);
    }

    // Get the transform type in string form ("mapper" or "reducer") for use
    // in messages, etc.
    String transformTypeString = transformType.toString().toLowerCase();

    // Wrap source in library code as appropriate
    transformSource = wrap(languageConf, transformTypeString, transformSource);

    // Create temp directory to store transform package
    File jobTempDir = getJobTempDir();
    File jobTransformDir = new File(jobTempDir, transformTypeString);
    if (!jobTransformDir.mkdir()) {
        throw new IOException("Could not create " + transformTypeString + " temporary directory:\n"
                + jobTransformDir.toString());
    }

    // Write processed transform source to disk
    String scriptExtension = languageConf.getString("extension", "");
    if (!scriptExtension.isEmpty())
        scriptExtension = "." + scriptExtension;
    File transformFile = writeTransformSource(transformTypeString, jobTransformDir, scriptExtension,
            transformSource);

    // Copy extra library files unless otherwise specified
    boolean copyLibraryFiles = languageConf.getBoolean("copyLibraryFiles", true);
    if (copyLibraryFiles) {
        copyLibraryFiles(languageConf, jobTransformDir);
    }

    // Compile if specified
    File srcTransformFile = transformFile;
    transformFile = compile(languageConf, transformTypeString, transformFile, jobTransformDir);
    if (!transformFile.equals(srcTransformFile))
        srcTransformFile.delete();

    // Return the path to the final transform file, relativized to the temp dir
    return relativizeFile(transformFile, getJobTempDir());
}

From source file:edu.kit.dama.scheduler.servlet.JobSchedulerInitializerListener.java

/**
 * Load configuration from XML-File//from  w  w  w  .  j a  v  a2 s. c om
 */
private void loadConfiguration() {

    URL configURL;
    HierarchicalConfiguration hc;

    try {
        configURL = DataManagerSettings.getConfigurationURL();
        LOGGER.debug("Loading configuration from {}", configURL);
        hc = new HierarchicalConfiguration(new XMLConfiguration(configURL));
        LOGGER.debug("Configuration successfully loaded");
    } catch (ConfigurationException ex) {
        // error in configuration
        // reason see debug log message:
        LOGGER.warn("Failed to load configuration, using default values.", ex);
        loadDefaultConfiguration();
        return;
    }

    SubnodeConfiguration configurationAt = hc.configurationAt(CONFIG_ROOT);

    if (configurationAt != null) {

        String jobStoreDriverParam = null;
        try {
            jobStoreDriverParam = configurationAt.getString(JOB_STORE_DRIVER, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_DRIVER);
        }
        if (jobStoreDriverParam != null) {
            jobStoreDriver = jobStoreDriverParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_DRIVER,
                    DEFAULT_JOB_STORE_DRIVER);
            jobStoreDriver = DEFAULT_JOB_STORE_DRIVER;
        }

        String jobStoreConnectionStringParam = null;
        try {
            jobStoreConnectionStringParam = configurationAt.getString(JOB_STORE_CONNECTION_STRING, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_CONNECTION_STRING);
        }
        if (jobStoreConnectionStringParam != null) {
            jobStoreConnectionString = jobStoreConnectionStringParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_CONNECTION_STRING,
                    DEFAULT_JOB_STORE_CONNECTION_STRING);
            jobStoreConnectionString = DEFAULT_JOB_STORE_CONNECTION_STRING;
        }

        String jobStoreUserParam = null;
        try {
            jobStoreUserParam = configurationAt.getString(JOB_STORE_USER, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_USER);
        }
        if (jobStoreUserParam != null) {
            jobStoreUser = jobStoreUserParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_USER, DEFAULT_JOB_STORE_USER);
            jobStoreUser = DEFAULT_JOB_STORE_USER;
        }
        String jobStorePasswordParam = null;
        try {
            jobStorePasswordParam = configurationAt.getString(JOB_STORE_PASSWORD, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_PASSWORD);
        }
        if (jobStoreUserParam != null) {
            jobStorePassword = jobStorePasswordParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_PASSWORD,
                    DEFAULT_JOB_STORE_PASSWORD);
            jobStorePassword = DEFAULT_JOB_STORE_PASSWORD;
        }

        Boolean waitOnShutdownParam = null;
        try {
            waitOnShutdownParam = configurationAt.getBoolean(CONFIG_WAIT_ON_SHUTDOWN, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", CONFIG_WAIT_ON_SHUTDOWN);
        }
        if (waitOnShutdownParam != null) {
            waitOnShutdown = waitOnShutdownParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_WAIT_ON_SHUTDOWN,
                    DEFAULT_WAIT_ON_SHUTDOWN);
            waitOnShutdown = DEFAULT_WAIT_ON_SHUTDOWN;
        }

        Boolean addDefaultSchedulesParam = null;
        try {
            addDefaultSchedulesParam = configurationAt.getBoolean(ADD_DEFAULT_SCHEDULES, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", ADD_DEFAULT_SCHEDULES);
        }
        if (addDefaultSchedulesParam != null) {
            addDefaultSchedules = addDefaultSchedulesParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", ADD_DEFAULT_SCHEDULES,
                    DEFAULT_ADD_DEFAULT_SCHEDULES);
            addDefaultSchedules = DEFAULT_ADD_DEFAULT_SCHEDULES;
        }

        Integer startDelaySecondsParam = null;
        try {
            startDelaySecondsParam = configurationAt.getInteger(CONFIG_START_DELAY_SECONDS, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", CONFIG_START_DELAY_SECONDS);
        }
        if (startDelaySecondsParam != null) {
            startDelaySeconds = startDelaySecondsParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_START_DELAY_SECONDS,
                    DEFAULT_START_DELAY_SECONDS);
            startDelaySeconds = DEFAULT_START_DELAY_SECONDS;
        }
    } else {
        LOGGER.info("No scheduler configuration node found in datamanager config. Using default values.");
    }
}

From source file:org.jboss.pressgang.ccms.contentspec.client.Client.java

/**
 * Read the Zanata Server settings from a INI Configuration file.
 *
 * @param configReader The initialized configuration reader to read
 *                     the server configuration from file.
 * @return True if everything was read in correctly otherwise false.
 *//*ww  w. ja va2 s .c om*/
@SuppressWarnings("unchecked")
protected boolean readZanataDetailsFromConfig(final HierarchicalINIConfiguration configReader) {
    // Read in the zanata server information
    final Map<String, ZanataServerConfiguration> zanataServers = new HashMap<String, ZanataServerConfiguration>();

    // Read in and process the servers
    if (!configReader.getRootNode().getChildren("zanata").isEmpty()) {
        final SubnodeConfiguration serversNode = configReader.getSection("zanata");
        for (final Iterator<String> it = serversNode.getKeys(); it.hasNext();) {
            final String key = it.next();

            // Find the prefix (aka server name) on urls
            if (key.endsWith(".url")) {
                String prefix = key.substring(0, key.length() - ".url".length());

                final String name = prefix.substring(0, prefix.length() - 1);
                final String url = serversNode.getString(prefix + ".url");
                final String username = serversNode.getString(prefix + ".username");
                final String token = serversNode.getString(prefix + ".key");
                final boolean cache = serversNode.getBoolean(prefix + ".cache", true);

                // Check that a url was specified
                if (url == null) {
                    command.printError(ClientUtilities.getMessage("NO_ZANATA_SERVER_URL_MSG", name), false);
                    return false;
                }

                // Create the Server Configuration
                final ZanataServerConfiguration serverConfig = new ZanataServerConfiguration();
                serverConfig.setName(name);
                serverConfig.setUrl(url);
                serverConfig.setUsername(username);
                serverConfig.setToken(token);
                serverConfig.setCache(cache);

                zanataServers.put(name, serverConfig);
            }
        }
    }

    // Setup the default zanata server
    if (zanataServers.containsKey(Constants.DEFAULT_SERVER_NAME)
            && !zanataServers.get(Constants.DEFAULT_SERVER_NAME).getUrl().matches("^(http://|https://).*")) {
        if (!zanataServers.containsKey(zanataServers.get(Constants.DEFAULT_SERVER_NAME).getUrl())) {
            command.printError(ClientUtilities.getMessage("NO_ZANATA_SERVER_FOUND_FOR_DEFAULT_SERVER_MSG"),
                    false);
            return false;
        } else {
            final ZanataServerConfiguration defaultConfig = zanataServers.get(Constants.DEFAULT_SERVER_NAME);
            final ZanataServerConfiguration config = zanataServers.get(defaultConfig.getUrl());
            defaultConfig.setUrl(config.getUrl());
            defaultConfig.setUsername(config.getUsername());
            defaultConfig.setToken(config.getToken());
            defaultConfig.setUsername(config.getUsername());
            defaultConfig.setCache(config.useCache());
        }
    }

    clientConfig.setZanataServers(zanataServers);
    return true;
}

From source file:org.midonet.config.providers.HierarchicalConfigurationProvider.java

@Override
public boolean getValue(String group, String key, boolean defaultValue) {
    try {/* ww  w.ja  v  a 2  s .c o  m*/
        SubnodeConfiguration subConfig = config.configurationAt(group);
        return subConfig.getBoolean(key, defaultValue);
    } catch (Throwable ex) {
        // fail properly if the configuration is missing this group
        return defaultValue;
    }
}