List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getStringArray
public String[] getStringArray(String key)
From source file:org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer.java
/** * @see//from w ww. jav a 2 s .c om * org.apache.james.lifecycle.api.Configurable * #configure(org.apache.commons.configuration.HierarchicalConfiguration) */ public final void configure(HierarchicalConfiguration config) throws ConfigurationException { enabled = config.getBoolean("[@enabled]", true); final Logger logger = getLogger(); if (!enabled) { logger.info(getServiceType() + " disabled by configuration"); return; } String listen[] = config.getString("bind", "0.0.0.0:" + getDefaultPort()).split(","); List<InetSocketAddress> bindAddresses = new ArrayList<InetSocketAddress>(); for (String aListen : listen) { String bind[] = aListen.split(":"); InetSocketAddress address; String ip = bind[0].trim(); int port = Integer.parseInt(bind[1].trim()); if (!ip.equals("0.0.0.0")) { try { ip = InetAddress.getByName(ip).getHostName(); } catch (UnknownHostException unhe) { throw new ConfigurationException( "Malformed bind parameter in configuration of service " + getServiceType(), unhe); } } address = new InetSocketAddress(ip, port); String infoBuffer = getServiceType() + " bound to: " + ip + ":" + port; logger.info(infoBuffer); bindAddresses.add(address); } setListenAddresses(bindAddresses.toArray(new InetSocketAddress[bindAddresses.size()])); jmxName = config.getString("jmxName", getDefaultJMXName()); int ioWorker = config.getInt("ioWorkerCount", DEFAULT_IO_WORKER_COUNT); setIoWorkerCount(ioWorker); maxExecutorThreads = config.getInt("maxExecutorCount", DEFAULT_MAX_EXECUTOR_COUNT); configureHelloName(config); setTimeout(config.getInt(TIMEOUT_NAME, DEFAULT_TIMEOUT)); StringBuilder infoBuffer = new StringBuilder(64).append(getServiceType()) .append(" handler connection timeout is: ").append(getTimeout()); logger.info(infoBuffer.toString()); setBacklog(config.getInt(BACKLOG_NAME, DEFAULT_BACKLOG)); infoBuffer = new StringBuilder(64).append(getServiceType()).append(" connection backlog is: ") .append(getBacklog()); logger.info(infoBuffer.toString()); String connectionLimitString = config.getString("connectionLimit", null); if (connectionLimitString != null) { try { connectionLimit = new Integer(connectionLimitString); } catch (NumberFormatException nfe) { logger.error("Connection limit value is not properly formatted.", nfe); } if (connectionLimit < 0) { logger.error("Connection limit value cannot be less than zero."); throw new ConfigurationException("Connection limit value cannot be less than zero."); } else if (connectionLimit > 0) { infoBuffer = new StringBuilder(128).append(getServiceType()).append(" will allow a maximum of ") .append(connectionLimitString).append(" connections."); logger.info(infoBuffer.toString()); } } String connectionLimitPerIP = config.getString("connectionLimitPerIP", null); if (connectionLimitPerIP != null) { try { connPerIP = Integer.parseInt(connectionLimitPerIP); } catch (NumberFormatException nfe) { logger.error("Connection limit per IP value is not properly formatted.", nfe); } if (connPerIP < 0) { logger.error("Connection limit per IP value cannot be less than zero."); throw new ConfigurationException("Connection limit value cannot be less than zero."); } else if (connPerIP > 0) { infoBuffer = new StringBuilder(128).append(getServiceType()).append(" will allow a maximum of ") .append(connPerIP).append(" per IP connections for ").append(getServiceType()); logger.info(infoBuffer.toString()); } } useStartTLS = config.getBoolean("tls.[@startTLS]", false); useSSL = config.getBoolean("tls.[@socketTLS]", false); if (useSSL && useStartTLS) throw new ConfigurationException("startTLS is only supported when using plain sockets"); if (useStartTLS || useSSL) { enabledCipherSuites = config.getStringArray("tls.supportedCipherSuites.cipherSuite"); keystore = config.getString("tls.keystore", null); if (keystore == null) { throw new ConfigurationException("keystore needs to get configured"); } secret = config.getString("tls.secret", ""); x509Algorithm = config.getString("tls.algorithm", defaultX509algorithm); } doConfigure(config); }
From source file:org.apache.james.rrt.file.XMLRecipientRewriteTable.java
@Override protected void doConfigure(HierarchicalConfiguration arg0) throws ConfigurationException { String[] mapConf = arg0.getStringArray("mapping"); mappings = Maps.newHashMap();//from w w w . j a v a 2s . co m if (mapConf != null && mapConf.length > 0) { for (String aMapConf : mapConf) { mappings.putAll(RecipientRewriteTableUtil.getXMLMappings(aMapConf)); } } else { throw new ConfigurationException("No mapping configured"); } }
From source file:org.apache.james.smtpserver.fastfail.DNSRBLHandler.java
@Override public void init(Configuration config) throws ConfigurationException { boolean validConfig = false; HierarchicalConfiguration handlerConfiguration = (HierarchicalConfiguration) config; ArrayList<String> rblserverCollection = new ArrayList<String>(); Collections.addAll(rblserverCollection, handlerConfiguration.getStringArray("rblservers.whitelist")); if (rblserverCollection.size() > 0) { setWhitelist(rblserverCollection.toArray(new String[rblserverCollection.size()])); rblserverCollection.clear();//www . j a v a2s .c o m validConfig = true; } Collections.addAll(rblserverCollection, handlerConfiguration.getStringArray("rblservers.blacklist")); if (rblserverCollection.size() > 0) { setBlacklist(rblserverCollection.toArray(new String[rblserverCollection.size()])); rblserverCollection.clear(); validConfig = true; } // Throw an ConfiigurationException on invalid config if (!validConfig) { throw new ConfigurationException("Please configure whitelist or blacklist"); } setGetDetail(handlerConfiguration.getBoolean("getDetail", false)); }
From source file:org.apache.james.user.ldap.ReadOnlyLDAPGroupRestriction.java
/** * Initialises an instance from the contents of a * <code><restriction><code> configuration XML * element./*from www . j a v a2 s .c o m*/ * * @param configuration The avalon configuration instance that encapsulates the * contents of the <code><restriction><code> XML element. * @throws org.apache.commons.configuration.ConfigurationException * If an error occurs extracting values from the configuration * element. */ public ReadOnlyLDAPGroupRestriction(HierarchicalConfiguration configuration) { groupDNs = new ArrayList<String>(); if (configuration != null) { memberAttribute = configuration.getString("[@memberAttribute]"); if (configuration.getKeys("group").hasNext()) { Collections.addAll(groupDNs, configuration.getStringArray("group")); } } }
From source file:org.apache.james.utils.InMemoryMailRepositoryStore.java
private void readConfigurationEntry(HierarchicalConfiguration repositoryConfiguration) throws ConfigurationException { String className = repositoryConfiguration.getString("[@class]"); MailRepositoryProvider usedMailRepository = mailRepositories.stream() .filter(mailRepositoryProvider -> mailRepositoryProvider.canonicalName().equals(className)) .findAny().orElseThrow(() -> new ConfigurationException( "MailRepository " + className + " has not been registered")); for (String protocol : repositoryConfiguration.getStringArray("protocols.protocol")) { protocolToRepositoryProvider.put(protocol, usedMailRepository); registerRepositoryDefaultConfiguration(repositoryConfiguration, protocol); }//from w w w. ja va2 s .c o m }
From source file:org.onosproject.drivers.cisco.XmlParserCisco.java
private static List<VlanId> getVlansForTrunk(HierarchicalConfiguration intfConfig) { if (intfConfig.containsKey(TRUNK_VLAN_KEY)) { return parseVlans(intfConfig.getStringArray(TRUNK_VLAN_KEY)); }//from ww w . j a v a2 s . c o m return null; }
From source file:org.zaproxy.zap.control.AddOnLoader.java
private static Map<AddOn, List<String>> loadAddOnsRunState(AddOnCollection addOnCollection) { List<HierarchicalConfiguration> savedAddOns = ((HierarchicalConfiguration) Model.getSingleton() .getOptionsParam().getConfig()).configurationsAt(ADDONS_RUNNABLE_KEY); Map<AddOn, List<String>> runnableAddOns = new HashMap<>(); for (HierarchicalConfiguration savedAddOn : savedAddOns) { AddOn addOn = addOnCollection.getAddOn(savedAddOn.getString(ADDON_RUNNABLE_ID_KEY, "")); if (addOn == null) { // No longer exists, skip it. continue; }/* w w w.ja v a 2s . co m*/ int version = savedAddOn.getInt(ADDON_RUNNABLE_VERSION_KEY, -1); if (version == -1 || addOn.getFileVersion() != version) { // No version or not the same version, skip it. continue; } List<String> runnableExtensions = new ArrayList<>(); List<String> currentExtensions = addOn.getExtensionsWithDeps(); for (String savedExtension : savedAddOn.getStringArray(ADDON_RUNNABLE_ALL_EXTENSIONS_KEY)) { if (currentExtensions.contains(savedExtension)) { runnableExtensions.add(savedExtension); } } runnableAddOns.put(addOn, runnableExtensions); } return runnableAddOns; }
From source file:org.zaproxy.zap.control.BaseZapAddOnXmlData.java
protected List<String> getStrings(HierarchicalConfiguration zapAddOnXml, String element, String elementName) { String[] fields = zapAddOnXml.getStringArray(element); if (fields.length == 0) { return Collections.emptyList(); }/*from w ww . jav a2 s .co m*/ ArrayList<String> strings = new ArrayList<>(fields.length); for (String field : fields) { if (!field.isEmpty()) { strings.add(field); } else { LOGGER.warn("Ignoring empty \"" + elementName + "\" entry in add-on \"" + name + "\"."); } } if (strings.isEmpty()) { return Collections.emptyList(); } strings.trimToSize(); return strings; }