org.apache.commons.configuration2.HierarchicalConfiguration Java Examples
The following examples show how to use
org.apache.commons.configuration2.HierarchicalConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether the entity resolver is initialized with other XML-related * properties. */ @Test public void testConfigureEntityResolverWithProperties() throws ConfigurationException { final HierarchicalConfiguration<ImmutableNode> config = new BaseHierarchicalConfiguration(); config.addProperty("header.entity-resolver[@config-class]", EntityResolverWithPropertiesTestImpl.class.getName()); final XMLBuilderParametersImpl xmlParams = new XMLBuilderParametersImpl(); final FileSystem fs = EasyMock.createMock(FileSystem.class); final String baseDir = ConfigurationAssert.OUT_DIR_NAME; xmlParams.setBasePath(baseDir); xmlParams.setFileSystem(fs); builder.configureEntityResolver(config, xmlParams); final EntityResolverWithPropertiesTestImpl resolver = (EntityResolverWithPropertiesTestImpl) xmlParams .getEntityResolver(); assertSame("File system not set", fs, resolver.getFileSystem()); assertSame("Base directory not set", baseDir, resolver.getBaseDir()); }
Example #2
Source File: AssetProcessingConfigReaderImpl.java From studio with GNU General Public License v3.0 | 6 votes |
private Map<String, String > getProcessorParams(HierarchicalConfiguration processorConfig) { Map<String, String> params = new HashMap<>(); Iterator<String> keysIter = processorConfig.getKeys(); String paramsPrefix = PROCESSOR_PARAMS_CONFIG_KEY + "."; while (keysIter.hasNext()) { String key = keysIter.next(); if (key.startsWith(paramsPrefix)) { String paramName = StringUtils.substringAfter(key, paramsPrefix); String paramValue = processorConfig.getString(key); params.put(paramName, paramValue); } } return params; }
Example #3
Source File: SMTPServerFactory.java From james-project with Apache License 2.0 | 6 votes |
@Override protected List<AbstractConfigurableAsyncServer> createServers(HierarchicalConfiguration<ImmutableNode> config) throws Exception { List<AbstractConfigurableAsyncServer> servers = new ArrayList<>(); List<HierarchicalConfiguration<ImmutableNode>> configs = config.configurationsAt("smtpserver"); for (HierarchicalConfiguration<ImmutableNode> serverConfig: configs) { SMTPServer server = createServer(); server.setDnsService(dns); server.setProtocolHandlerLoader(loader); server.setFileSystem(fileSystem); server.setHashWheelTimer(hashedWheelTimer); server.configure(serverConfig); servers.add(server); } return servers; }
Example #4
Source File: AbstractDeployer.java From studio with GNU General Public License v3.0 | 6 votes |
protected void doCreateTarget(String site, String environment, String searchEngine, String template, boolean replace, boolean disableDeployCron, String localRepoPath, String repoUrl, HierarchicalConfiguration<ImmutableNode> additionalParams) throws IllegalStateException, RestClientException { String requestUrl = getCreateTargetUrl(); Map<String, Object> requestBody = getCreateTargetRequestBody(site, environment, searchEngine, template, replace, disableDeployCron, localRepoPath, repoUrl, additionalParams); try { RequestEntity<Map<String, Object>> requestEntity = RequestEntity.post(new URI(requestUrl)) .contentType(MediaType.APPLICATION_JSON) .body(requestBody); logger.debug("Calling create target API: {0}", requestEntity); restTemplate.exchange(requestEntity, Map.class); } catch (URISyntaxException e) { throw new IllegalStateException("Invalid format of create target URL: " + requestUrl, e); } }
Example #5
Source File: TestHierarchicalConfigurationEvents.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether manipulations of a connected sub configuration trigger correct * events. */ @Test public void testSubConfigurationChangedEventConnected() { final HierarchicalConfiguration<ImmutableNode> sub = ((BaseHierarchicalConfiguration) config) .configurationAt(EXIST_PROPERTY, true); sub.addProperty("newProp", "newValue"); checkSubnodeEvent( listener.nextEvent(ConfigurationEvent.SUBNODE_CHANGED), true); checkSubnodeEvent( listener.nextEvent(ConfigurationEvent.SUBNODE_CHANGED), false); listener.done(); }
Example #6
Source File: LMTPServerFactory.java From james-project with Apache License 2.0 | 6 votes |
@Override protected List<AbstractConfigurableAsyncServer> createServers(HierarchicalConfiguration<ImmutableNode> config) throws Exception { List<AbstractConfigurableAsyncServer> servers = new ArrayList<>(); List<HierarchicalConfiguration<ImmutableNode>> configs = config.configurationsAt("lmtpserver"); for (HierarchicalConfiguration<ImmutableNode> serverConfig: configs) { LMTPServer server = createServer(); server.setFileSystem(fileSystem); server.setHashWheelTimer(hashedWheelTimer); server.setProtocolHandlerLoader(loader); server.configure(serverConfig); servers.add(server); } return servers; }
Example #7
Source File: AbstractStateCompositeProcessor.java From james-project with Apache License 2.0 | 6 votes |
@PostConstruct public void init() throws Exception { List<HierarchicalConfiguration<ImmutableNode>> processorConfs = config.configurationsAt("processor"); for (HierarchicalConfiguration<ImmutableNode> processorConf : processorConfs) { String processorName = processorConf.getString("[@state]"); // if the "child" processor has no jmx config we just use the one of // the composite if (!processorConf.containsKey("[@enableJmx]")) { processorConf.addProperty("[@enableJmx]", enableJmx); } processors.put(processorName, createMailProcessor(processorName, processorConf)); } if (enableJmx) { this.jmxListener = new JMXStateCompositeProcessorListener(this); addListener(jmxListener); } // check if all needed processors are configured checkProcessors(); }
Example #8
Source File: ConfigurationScriptJobResolver.java From engine with GNU General Public License v3.0 | 6 votes |
protected JobContext getJob(SiteContext siteContext, HierarchicalConfiguration jobConfig) { String scriptPath = jobConfig.getString(PATH_KEY); String cronExpression = jobConfig.getString(CRON_EXPRESSION_KEY); if (StringUtils.isNotEmpty(scriptPath) && StringUtils.isNotEmpty(cronExpression)) { if (siteContext.getStoreService().exists(siteContext.getContext(), scriptPath)) { return SchedulingUtils.createJobContext(siteContext, scriptPath, cronExpression, disableVariableRestrictions? servletContext: null); } else { throw new SchedulingException("Script job " + scriptPath + " for site '" + siteContext.getSiteName() + "' not found"); } } else { return null; } }
Example #9
Source File: UiServiceInternalImpl.java From studio with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public List<MenuItem> getGlobalMenu(Set<String> permissions) throws ServiceLayerException { if (CollectionUtils.isNotEmpty(permissions)) { HierarchicalConfiguration menuConfig = getGlobalMenuConfig(); List<MenuItem> menuItems = new ArrayList<>(); // TODO: Move this config to ConfigurationService List<HierarchicalConfiguration> itemsConfig = menuConfig.configurationsAt(MENU_ITEMS_CONFIG_KEY); if (CollectionUtils.isNotEmpty(itemsConfig)) { for (HierarchicalConfiguration itemConfig : itemsConfig) { String requiredPermission = getRequiredStringProperty(itemConfig, PERMISSION_CONFIG_KEY); if (requiredPermission.equals(ANY_PERMISSION_WILDCARD) || permissions.contains(requiredPermission)) { MenuItem item = new MenuItem(); item.setId(getRequiredStringProperty(itemConfig, ID_CONFIG_KEY)); item.setLabel(getRequiredStringProperty(itemConfig, LABEL_CONFIG_KEY)); item.setIcon(getRequiredStringProperty(itemConfig, ICON_CONFIG_KEY)); menuItems.add(item); } } } else { throw new ConfigurationException("No menu items found in global menu config"); } return menuItems; } else { return null; } }
Example #10
Source File: ReadOnlyUsersLDAPRepositoryTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void configureShouldThrowOnNonBooleanValueForSupportsVirtualHosting() { HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); configuration.addProperty(SUPPORTS_VIRTUAL_HOSTING, "bad"); ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(new SimpleDomainList()); assertThatThrownBy(() -> usersLDAPRepository.configure(configuration)) .isInstanceOf(ConversionException.class); }
Example #11
Source File: CombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Processes custom {@link Lookup} objects that might be declared in the * definition configuration. Each {@code Lookup} object is registered at the * definition configuration and at the result configuration. It is also * added to all child configurations added to the resulting combined * configuration. * * @param defConfig the definition configuration * @param resultConfig the resulting configuration * @throws ConfigurationException if an error occurs */ protected void registerConfiguredLookups( final HierarchicalConfiguration<?> defConfig, final Configuration resultConfig) throws ConfigurationException { final Map<String, Lookup> lookups = new HashMap<>(); final List<? extends HierarchicalConfiguration<?>> nodes = defConfig.configurationsAt(KEY_CONFIGURATION_LOOKUPS); for (final HierarchicalConfiguration<?> config : nodes) { final XMLBeanDeclaration decl = new XMLBeanDeclaration(config); final String key = config.getString(KEY_LOOKUP_KEY); final Lookup lookup = (Lookup) fetchBeanHelper().createBean(decl); lookups.put(key, lookup); } if (!lookups.isEmpty()) { final ConfigurationInterpolator defCI = defConfig.getInterpolator(); if (defCI != null) { defCI.registerLookups(lookups); } resultConfig.getInterpolator().registerLookups(lookups); } }
Example #12
Source File: TemplateRenameUpgradeOperation.java From studio with GNU General Public License v3.0 | 5 votes |
@Override public void doInit(HierarchicalConfiguration<ImmutableNode> config) { super.doInit(config); basePath = config.getString(CONFIG_KEY_BASE_PATH); oldPath = removeStart(oldPath, File.separator); newPath = removeStart(newPath, File.separator); }
Example #13
Source File: FetchScheduler.java From james-project with Apache License 2.0 | 5 votes |
@PostConstruct public void init() throws Exception { enabled = conf.getBoolean("[@enabled]", false); if (enabled) { int numThreads = conf.getInt("threads", 5); String jmxName = conf.getString("jmxName", "fetchmail"); String jmxPath = "org.apache.james:type=component,name=" + jmxName + ",sub-type=threadpool"; /* The scheduler service that is used to trigger fetch tasks. */ ScheduledExecutorService scheduler = new JMXEnabledScheduledThreadPoolExecutor(numThreads, jmxPath, "scheduler"); queue = queueFactory.createQueue(MailQueueFactory.SPOOL); List<HierarchicalConfiguration<ImmutableNode>> fetchConfs = conf.configurationsAt("fetch"); for (HierarchicalConfiguration<ImmutableNode> fetchConf : fetchConfs) { // read configuration Long interval = fetchConf.getLong("interval"); FetchMail fetcher = new FetchMail(); fetcher.setDNSService(dns); fetcher.setUsersRepository(urepos); fetcher.setMailQueue(queue); fetcher.setDomainList(domainList); fetcher.configure(fetchConf); // initialize scheduling schedulers.add(scheduler.scheduleWithFixedDelay(fetcher, 0, interval, TimeUnit.MILLISECONDS)); } LOGGER.info("FetchMail Started"); } else { LOGGER.info("FetchMail Disabled"); } }
Example #14
Source File: TestBaseConfigurationBuilderProvider.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Creates a configuration declaration based on the given configuration. * * @param declConfig the configuration for the declaration * @return the declaration */ private ConfigurationDeclaration createDeclaration( final HierarchicalConfiguration<?> declConfig) { final CombinedConfigurationBuilder parentBuilder = new CombinedConfigurationBuilder() { @Override protected void initChildBuilderParameters( final BuilderParameters params) { // set a property value; this should be overridden by // child builders if (params instanceof BasicBuilderParameters) { ((BasicBuilderParameters) params) .setListDelimiterHandler(DisabledListDelimiterHandler.INSTANCE); } } }; final ConfigurationDeclaration decl = new ConfigurationDeclaration(parentBuilder, declConfig) { @Override protected Object interpolate(final Object value) { return value; } }; return decl; }
Example #15
Source File: PreDeletionHooksConfigurationTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void fromShouldReturnNoneWhenEmpty() throws Exception { HierarchicalConfiguration<ImmutableNode> configuration = new BaseHierarchicalConfiguration(); assertThat(PreDeletionHooksConfiguration.from(configuration)) .isEqualTo(PreDeletionHooksConfiguration.none()); }
Example #16
Source File: StudioBlobStoreResolverImpl.java From studio with GNU General Public License v3.0 | 5 votes |
@Override public BlobStore getByPaths(String site, String... paths) throws ServiceLayerException, ConfigurationException { logger.debug("Looking blob store for paths {} for site {}", Arrays.toString(paths), site); HierarchicalConfiguration config = getConfiguration(new ConfigurationProviderImpl(site)); if (config != null) { BlobStore blobStore = findStore(config, store -> paths[0].matches(store.getString(CONFIG_KEY_PATTERN))); // We have to compare each one to know if the exception should be thrown if (blobStore != null && !Stream.of(paths).allMatch(blobStore::isCompatible)) { throw new ServiceLayerException("Unsupported operation for paths " + Arrays.toString(paths)); } return blobStore; } return null; }
Example #17
Source File: DefaultUpgradePipelineFactoryImpl.java From studio with GNU General Public License v3.0 | 5 votes |
protected HierarchicalConfiguration loadUpgradeConfiguration() throws UpgradeException { YamlConfiguration configuration = new YamlConfiguration(); try (InputStream is = configurationFile.getInputStream()) { configuration.read(is); } catch (Exception e) { throw new UpgradeException("Error reading configuration file", e); } return configuration; }
Example #18
Source File: AssetProcessingConfigReaderImpl.java From studio with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private List<HierarchicalConfiguration> getRequiredConfigurationsAt(HierarchicalConfiguration config, String key) throws AssetProcessingConfigurationException { List<HierarchicalConfiguration> configs = config.configurationsAt(key); if (CollectionUtils.isEmpty(configs)) { throw new AssetProcessingConfigurationException("Missing required property '" + key + "'"); } else { return configs; } }
Example #19
Source File: SiteAwareCORSFilter.java From engine with GNU General Public License v3.0 | 5 votes |
@Override public boolean isDisableCORS() { SiteContext siteContext = SiteContext.getCurrent(); HierarchicalConfiguration config = siteContext.getConfig(); try { HierarchicalConfiguration corsConfig = config.configurationAt(CONFIG_KEY); if (corsConfig != null) { return !corsConfig.getBoolean(ENABLE_KEY, false); } } catch (Exception e) { logger.debug("Site '{}' has no CORS configuration", siteContext.getSiteName()); } return true; }
Example #20
Source File: FileConfigurationProviderTest.java From james-project with Apache License 2.0 | 5 votes |
@Test public void getConfigurationShouldLoadCorrespondingXMLFileWhenAPathIsProvidedPart() throws Exception { HierarchicalConfiguration<ImmutableNode> hierarchicalConfiguration = configurationProvider.getConfiguration( String.join(CONFIG_SEPARATOR, ROOT_CONFIG_KEY, CONFIG_KEY_4, CONFIG_KEY_5)); assertThat(hierarchicalConfiguration.getKeys()) .toIterable() .containsOnly(CONFIG_KEY_2); assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_3); }
Example #21
Source File: AssetProcessingConfigReaderImpl.java From studio with GNU General Public License v3.0 | 5 votes |
@Override public List<ProcessorPipelineConfiguration> readConfig(InputStream in) throws AssetProcessingConfigurationException { HierarchicalConfiguration config; try { config = ConfigUtils.readXmlConfiguration(in); } catch (ConfigurationException e) { throw new AssetProcessingConfigurationException("Unable to read XML configuration file", e); } return readConfig(config); }
Example #22
Source File: ReadOnlyUsersLDAPRepositoryTest.java From james-project with Apache License 2.0 | 5 votes |
private static ReadOnlyUsersLDAPRepository startUsersRepository(HierarchicalConfiguration<ImmutableNode> ldapRepositoryConfiguration, DomainList domainList) throws Exception { ReadOnlyUsersLDAPRepository ldapRepository = new ReadOnlyUsersLDAPRepository(domainList); ldapRepository.configure(ldapRepositoryConfiguration); ldapRepository.init(); return ldapRepository; }
Example #23
Source File: IndexerConfigurationBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class); try { HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration("indexer"); String provider = config.getString("provider", "lazyIndex"); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; String indexer = null; String reIndexer = null; if (provider.equalsIgnoreCase("lazyIndex")) { indexer = "lazyIndex"; reIndexer = "fake-reindexer"; } else if (provider.equalsIgnoreCase("elasticsearch")) { indexer = "elasticsearch-listener"; reIndexer = "reindexer-impl"; } else if (provider.equalsIgnoreCase("luceneIndex")) { indexer = "luceneIndex"; reIndexer = "fake-reindexer"; } if (indexer == null) { throw new ConfigurationException("Indexer provider " + provider + " not supported!"); } registry.registerAlias(indexer, "indexer"); registry.registerAlias(reIndexer, "reindexer"); } catch (ConfigurationException e) { throw new FatalBeanException("Unable to config the indexer", e); } }
Example #24
Source File: ReadOnlyUsersLDAPRepositoryTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void supportVirtualHostingShouldReturnFalseWhenReportedInConfig() throws Exception { HierarchicalConfiguration<ImmutableNode> configuration = ldapRepositoryConfiguration(ldapContainer); configuration.addProperty(SUPPORTS_VIRTUAL_HOSTING, "false"); ReadOnlyUsersLDAPRepository usersLDAPRepository = new ReadOnlyUsersLDAPRepository(new SimpleDomainList()); usersLDAPRepository.configure(configuration); assertThat(usersLDAPRepository.supportVirtualHosting()).isFalse(); }
Example #25
Source File: ConfigurationBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 5 votes |
/** * Parse the configuration file and depending on it register the beans */ @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class); // loop over the beans for (String name : beans.keySet()) { try { HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration(name); // Get the configuration for the class String repClass = config.getString("[@class]"); // Create the definition and register it BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(repClass).getBeanDefinition(); registry.registerBeanDefinition(name, def); String aliases = beans.get(name); String[] aliasArray = aliases.split(","); // check if we need to register some aliases for this bean if (aliasArray != null) { for (String anAliasArray : aliasArray) { String alias = anAliasArray.trim(); if (alias.length() > 0) { registry.registerAlias(name, anAliasArray); } } } } catch (ConfigurationException e) { throw new FatalBeanException("Unable to parse configuration for bean " + name, e); } } }
Example #26
Source File: LanguageSpecConfigService.java From spoofax with Apache License 2.0 | 5 votes |
@Override protected ConfigRequest<ILanguageSpecConfig> toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) { final ProjectConfig projectConfig = new ProjectConfig(config); final LanguageSpecConfig languageSpecConfig = new LanguageSpecConfig(config, projectConfig); final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile); final Collection<IMessage> messages = languageSpecConfig.validate(mb); return new ConfigRequest<>(languageSpecConfig, messages); }
Example #27
Source File: FacebookConnectionFactoryConfigParser.java From engine with GNU General Public License v3.0 | 5 votes |
@Override public ConnectionFactory<Facebook> parse(HierarchicalConfiguration config) throws ConfigurationException { String appId = config.getString(FACEBOOK_CONNECTION_FACTORY_APP_ID_KEY); String appSecret = config.getString(FACEBOOK_CONNECTION_FACTORY_APP_SECRET_KEY); if (StringUtils.isNotEmpty(appId) && StringUtils.isNotEmpty(appSecret)) { return createFacebookConnectionFactory(appId, appSecret); } else { return null; } }
Example #28
Source File: FileConfigurationProvider.java From james-project with Apache License 2.0 | 5 votes |
private HierarchicalConfiguration<ImmutableNode> selectHierarchicalConfigPart(HierarchicalConfiguration<ImmutableNode> config, Iterable<String> configsPathParts) { HierarchicalConfiguration<ImmutableNode> currentConfig = config; for (String nextPathPart : configsPathParts) { currentConfig = currentConfig.configurationAt(nextPathPart); } return currentConfig; }
Example #29
Source File: LanguageSpecConfigService.java From spoofax with Apache License 2.0 | 5 votes |
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ILanguageSpecConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build(null); } return ((IConfig) config).getConfig(); }
Example #30
Source File: ConfigAwareAuthenticationFailureHandler.java From engine with GNU General Public License v3.0 | 5 votes |
protected String determineFailureUrl() { HierarchicalConfiguration siteConfig = ConfigUtils.getCurrentConfig(); if (siteConfig != null && siteConfig.containsKey(LOGIN_FAILURE_URL_KEY)) { return siteConfig.getString(LOGIN_FAILURE_URL_KEY); } return defaultFailureUrl; }