List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getBoolean
public boolean getBoolean(String key)
From source file:org.apache.james.fetchmail.FetchMail.java
/** * Method configure parses and validates the Configuration data and creates * a new <code>ParsedConfiguration</code>, an <code>Account</code> for each * configured static account and a//from www .jav a 2 s .c o m * <code>ParsedDynamicAccountParameters</code> for each dynamic account. * * @see org.apache.james.lifecycle.api.Configurable#configure(HierarchicalConfiguration) */ public void configure(HierarchicalConfiguration configuration) throws ConfigurationException { // Set any Session parameters passed in the Configuration setSessionParameters(configuration); // Create the ParsedConfiguration used in the delegation chain ParsedConfiguration parsedConfiguration = new ParsedConfiguration(configuration, logger, getLocalUsers(), getDNSService(), getDomainList(), getMailQueue()); setParsedConfiguration(parsedConfiguration); // Setup the Accounts List<HierarchicalConfiguration> allAccounts = configuration.configurationsAt("accounts"); if (allAccounts.size() < 1) throw new ConfigurationException("Missing <accounts> section."); if (allAccounts.size() > 1) throw new ConfigurationException("Too many <accounts> sections, there must be exactly one"); HierarchicalConfiguration accounts = allAccounts.get(0); if (!accounts.getKeys().hasNext()) throw new ConfigurationException("Missing <account> section."); int i = 0; // Create an Account for every configured account for (ConfigurationNode accountsChild : accounts.getRoot().getChildren()) { String accountsChildName = accountsChild.getName(); List<HierarchicalConfiguration> accountsChildConfig = accounts.configurationsAt(accountsChildName); HierarchicalConfiguration conf = accountsChildConfig.get(i); if ("alllocal".equals(accountsChildName)) { // <allLocal> is dynamic, save the parameters for accounts to // be created when the task is triggered getParsedDynamicAccountParameters().add(new ParsedDynamicAccountParameters(i, conf)); continue; } if ("account".equals(accountsChildName)) { // Create an Account for the named user and // add it to the list of static accounts getStaticAccounts().add(new Account(i, parsedConfiguration, conf.getString("[@user]"), conf.getString("[@password]"), conf.getString("[@recipient]"), conf.getBoolean("[@ignorercpt-header]"), conf.getString("[@customrcpt-header]", ""), getSession())); continue; } throw new ConfigurationException("Illegal token: <" + accountsChildName + "> in <accounts>"); } i++; }
From source file:org.apache.james.fetchmail.ParsedConfiguration.java
protected void configure(HierarchicalConfiguration conf) throws ConfigurationException { setHost(conf.getString("host")); setFetchTaskName(conf.getString("[@name]")); setJavaMailProviderName(conf.getString("javaMailProviderName")); setJavaMailFolderName(conf.getString("javaMailFolderName")); setRecurse(conf.getBoolean("recursesubfolders")); HierarchicalConfiguration recipientNotFound = conf.configurationAt("recipientnotfound"); setDeferRecipientNotFound(recipientNotFound.getBoolean("[@defer]")); setRejectRecipientNotFound(recipientNotFound.getBoolean("[@reject]")); setLeaveRecipientNotFound(recipientNotFound.getBoolean("[@leaveonserver]")); setMarkRecipientNotFoundSeen(recipientNotFound.getBoolean("[@markseen]")); setDefaultDomainName(conf.getString("defaultdomain", "localhost")); setFetchAll(conf.getBoolean("fetchall")); HierarchicalConfiguration fetched = conf.configurationAt("fetched"); setLeave(fetched.getBoolean("[@leaveonserver]")); setMarkSeen(fetched.getBoolean("[@markseen]")); HierarchicalConfiguration remoterecipient = conf.configurationAt("remoterecipient"); setRejectRemoteRecipient(remoterecipient.getBoolean("[@reject]")); setLeaveRemoteRecipient(remoterecipient.getBoolean("[@leaveonserver]")); setMarkRemoteRecipientSeen(remoterecipient.getBoolean("[@markseen]")); HierarchicalConfiguration blacklist = conf.configurationAt("blacklist"); setBlacklist(conf.getString("blacklist", "")); setRejectBlacklisted(blacklist.getBoolean("[@reject]")); setLeaveBlacklisted(blacklist.getBoolean("[@leaveonserver]")); setMarkBlacklistedSeen(blacklist.getBoolean("[@markseen]")); HierarchicalConfiguration userundefined = conf.configurationAt("userundefined"); setRejectUserUndefined(userundefined.getBoolean("[@reject]")); setLeaveUserUndefined(userundefined.getBoolean("[@leaveonserver]")); setMarkUserUndefinedSeen(userundefined.getBoolean("[@markseen]")); HierarchicalConfiguration undeliverable = conf.configurationAt("undeliverable"); setLeaveUndeliverable(undeliverable.getBoolean("[@leaveonserver]")); setMarkUndeliverableSeen(undeliverable.getBoolean("[@markseen]")); if (conf.getKeys("remotereceivedheader").hasNext()) { HierarchicalConfiguration remotereceivedheader = conf.configurationAt("remotereceivedheader"); setRemoteReceivedHeaderIndex(remotereceivedheader.getInt("[@index]")); setRejectRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@reject]")); setLeaveRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@leaveonserver]")); setMarkRemoteReceivedHeaderInvalidSeen(remotereceivedheader.getBoolean("[@markseen]")); }//from w w w . ja v a 2s . com if (conf.getKeys("maxmessagesize").hasNext()) { HierarchicalConfiguration maxmessagesize = conf.configurationAt("maxmessagesize"); setMaxMessageSizeLimit(maxmessagesize.getInt("[@limit]") * 1024); setRejectMaxMessageSizeExceeded(maxmessagesize.getBoolean("[@reject]")); setLeaveMaxMessageSizeExceeded(maxmessagesize.getBoolean("[@leaveonserver]")); setMarkMaxMessageSizeExceededSeen(maxmessagesize.getBoolean("[@markseen]")); } if (getLogger().isDebugEnabled()) { getLogger().info("Configured FetchMail fetch task " + getFetchTaskName()); } }
From source file:org.codesearch.commons.configuration.xml.XmlConfigurationReader.java
/** * retrieves all required data about the given repository from the * configuration via the HierarchicalConfiguration and returns it as a * RepositoryDto/*from w w w . j av a 2 s . c o m*/ */ @SuppressWarnings("unchecked") private RepositoryDto loadRepository(HierarchicalConfiguration hc) throws InvalidConfigurationException { RepositoryDto repo; //mandatory field String name = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_NAME); // retrieve the repository blacklisted filenames and add all global filenames List<String> blacklistEntries = hc.getList(XmlConfigurationReaderConstants.REPOSITORY_BLACKLIST); if (blacklistEntries == null) { blacklistEntries = new LinkedList<String>(); } blacklistEntries.addAll(getGlobalBlacklistEntries()); // retrieve the repository whitelisted filenames and add all global filenames List<String> whitelistFileNames = hc .getList(XmlConfigurationReaderConstants.REPOSITORY_WHITELIST_FILENAMES); if (whitelistFileNames == null) { whitelistFileNames = new LinkedList<String>(); } whitelistFileNames.addAll(getGlobalWhitelistEntries()); String repoGroupString = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_GROUPS); List<String> repositoryGroups = Arrays.asList(repoGroupString.split(" ")); // retrieve the used authentication system and fill it with the required data AuthenticationType usedAuthentication = null; String authenticationType = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA); if (authenticationType == null || authenticationType.trim().isEmpty() || authenticationType.equals("none")) { usedAuthentication = new NoAuthentication(); } else if (authenticationType.equals("basic")) { String username = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA_USERNAME); String password = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA_PASSWORD); usedAuthentication = new BasicAuthentication(username, password); } else if (authenticationType.equals("ssh")) { String sshFilePath = hc .getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA_SSH_FILE_PATH); String username = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA_USERNAME); String password = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA_PASSWORD); String port = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_AUTHENTICATION_DATA_PORT); usedAuthentication = new SshAuthentication(username, password, port, sshFilePath); } String versionControlSystem = hc.getString(XmlConfigurationReaderConstants.REPOSITORY_VCS); repo = new RepositoryDto(name, hc.getString(XmlConfigurationReaderConstants.REPOSITORY_URL), usedAuthentication, hc.getBoolean(XmlConfigurationReaderConstants.REPOSITORY_CODE_NAVIGATION_ENABLED), versionControlSystem, blacklistEntries, whitelistFileNames, repositoryGroups); LOG.info("Read repository: " + repo.getName()); return repo; }
From source file:org.lable.oss.dynamicconfig.serialization.yaml.YamlDeserializerTest.java
@Test public void testLoad() throws ConfigurationException, IOException, ClassNotFoundException { HierarchicalConfigurationDeserializer deserializer = new YamlDeserializer(); HierarchicalConfiguration config = deserializer.deserialize(IOUtils.toInputStream(testYaml)); // Type checking. assertThat(config.getString("type.string"), is("Okay")); List list = config.getList("type.listOfStrings"); for (Object o : list) { assertThat(o, instanceOf(String.class)); }// ww w. j a v a 2s .c o m assertThat(list.size(), is(3)); assertThat(list.get(0), is("One")); assertThat(list.get(1), is("Two")); assertThat(list.get(2), is("")); assertThat(config.getBoolean("type.booleanFalse"), is(false)); assertThat(config.getBoolean("type.booleanTrue"), is(true)); list = config.getList("type.listOfIntegers"); for (Object o : list) { assertThat(o, instanceOf(Integer.class)); } assertThat(list.size(), is(5)); assertThat(list.get(0), is(1)); assertThat(list.get(4), is(-1)); assertThat(config.getLong("type.long"), is(1000000000000L)); // Tree model assertThat(config.getString("tree.branchL1a.branchL2a.branchL3a"), is("leaf_a")); assertThat(config.getString("tree.branchL1a.branchL2b.branchL3h"), is("leaf_h")); // Trim, because this value is defined as a multi-line value. assertThat(config.getString("tree.branchL1a.branchL2b.branchL3i").trim(), is("leaf_i")); }
From source file:org.restcomm.connect.extension.controller.ExtensionBootstrapper.java
public void start() throws ClassNotFoundException, IllegalAccessException, InstantiationException { List<HierarchicalConfiguration> exts = ((XMLConfiguration) configuration) .configurationsAt("extensions.extension"); for (HierarchicalConfiguration ext : exts) { String name = ext.getString("[@name]"); String className = ext.getString("class"); boolean enabled = ext.getBoolean("enabled"); if (enabled) { try { Class<RestcommExtensionGeneric> klass = (Class<RestcommExtensionGeneric>) Class .forName(className); RestcommExtensionGeneric extension = klass.newInstance(); extension.init(this.context); //Store it in the context using the extension name context.setAttribute(name, extension); ExtensionController.getInstance().registerExtension(extension); if (logger.isInfoEnabled()) { logger.info("Stated Extension: " + name); }/* w ww. j a va2 s.c o m*/ } catch (Exception e) { if (logger.isInfoEnabled()) { logger.info("Exception during initialization of extension \"" + name + "\", exception: " + e.getStackTrace()); } } } } }
From source file:org.zaproxy.zap.extension.script.ScriptParam.java
@Override protected void parse() { defaultScript = getConfig().getString(PARAM_DEFAULT_SCRIPT, ""); defaultDir = getConfig().getString(PARAM_DEFAULT_DIR, ""); try {//from ww w .j a v a 2s. co m List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()) .configurationsAt(ALL_SCRIPTS_KEY); this.scripts = new HashSet<>(fields.size()); List<String> tempListNames = new ArrayList<>(fields.size()); for (HierarchicalConfiguration sub : fields) { String name = sub.getString(SCRIPT_NAME_KEY, ""); try { if (!"".equals(name) && !tempListNames.contains(name)) { tempListNames.add(name); File file = new File(sub.getString(SCRIPT_FILE_KEY)); if (!file.exists()) { logger.error("Script '" + file.getAbsolutePath() + "' does not exist"); continue; } ScriptWrapper script = new ScriptWrapper(sub.getString(SCRIPT_NAME_KEY), sub.getString(SCRIPT_DESC_KEY), sub.getString(SCRIPT_ENGINE_KEY), sub.getString(SCRIPT_TYPE_KEY), sub.getBoolean(SCRIPT_ENABLED_KEY), file); script.setLoadOnStart(true); // Because it was saved ;) scripts.add(script); } } catch (Exception e) { logger.error("Error while loading the script: " + name, e); } } } catch (Exception e) { logger.error("Error while loading the scripts: " + e.getMessage(), e); } try { this.scriptDirs = new ArrayList<File>(); for (Object dirName : getConfig().getList(SCRIPT_DIRS)) { File f = new File((String) dirName); if (!f.exists() || !f.isDirectory()) { logger.error("Not a valid script directory: " + dirName); } else { scriptDirs.add(f); } } } catch (Exception e) { logger.error("Error while loading the script dirs: " + e.getMessage(), e); } confirmRemoveDir = getConfig().getBoolean(SCRIPT_CONFIRM_REMOVE_DIR, true); }