Java Code Examples for org.apache.commons.configuration2.HierarchicalConfiguration#configurationsAt()

The following examples show how to use org.apache.commons.configuration2.HierarchicalConfiguration#configurationsAt() . 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: POP3ServerFactory.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AbstractConfigurableAsyncServer> createServers(HierarchicalConfiguration<ImmutableNode> config) throws Exception {

    List<AbstractConfigurableAsyncServer> servers = new ArrayList<>();
    List<HierarchicalConfiguration<ImmutableNode>> configs = config.configurationsAt("pop3server");
    
    for (HierarchicalConfiguration<ImmutableNode> serverConfig: configs) {
        POP3Server server = createServer();
        server.setProtocolHandlerLoader(loader);
        server.setFileSystem(fileSystem);
        server.setHashWheelTimer(hashedWheelTimer);
        server.configure(serverConfig);
        servers.add(server);
    }

    return servers;
    
}
 
Example 2
Source File: HttpProxyFilter.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes, unchecked")
protected String getTargetUrl(SiteContext siteContext, String requestUri) {
    HierarchicalConfiguration proxyConfig = siteContext.getProxyConfig();

    if (proxyConfig == null) {
        throw new HttpProxyException("No proxy configuration found for site " + siteContext.getSiteName());
    }

    List<HierarchicalConfiguration> servers = proxyConfig.configurationsAt(CONFIG_KEY_SERVERS);
    for (HierarchicalConfiguration server : servers) {
        List<String> patterns = server.getList(String.class, CONFIG_KEY_PATTERNS);
        if (RegexUtils.matchesAny(requestUri, patterns)) {
            logger.debug("Found matching server {} for proxy request {}",
                    server.getString(CONFIG_KEY_ID), requestUri);
            return server.getString(CONFIG_KEY_URL);
        }
    }

    // should never happen (unless there is an issue with the config)
    throw new IllegalStateException("Invalid proxy configuration for site " + siteContext.getSiteName() +
            ", no matching server found for request " + requestUri);
}
 
Example 3
Source File: IMAPServerFactory.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override

    protected List<AbstractConfigurableAsyncServer> createServers(HierarchicalConfiguration<ImmutableNode> config) throws Exception {
        List<AbstractConfigurableAsyncServer> servers = new ArrayList<>();
        List<HierarchicalConfiguration<ImmutableNode>> configs = config.configurationsAt("imapserver");
        
        for (HierarchicalConfiguration<ImmutableNode> serverConfig: configs) {
            IMAPServer server = createServer();
            server.setFileSystem(fileSystem);
            server.setHashWheelTimer(hashedWheelTimer);
            server.configure(serverConfig);
            servers.add(server);
        }

        return servers;
        
    }
 
Example 4
Source File: LMTPServerFactory.java    From james-project with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: GlobalRepoUpgradeOperation.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void doInit(final HierarchicalConfiguration<ImmutableNode> config) {
    overwrite = config.getBoolean(CONFIG_KEY_OVERWRITE, true);
    List<HierarchicalConfiguration<ImmutableNode>> fileMappings = config.configurationsAt(CONFIG_KEY_FILES);
    for (HierarchicalConfiguration<ImmutableNode> fileMapping : fileMappings) {
        String src = fileMapping.getString(CONFIG_KEY_SRC);
        String dest = fileMapping.getString(CONFIG_KEY_DEST);

        if (StringUtils.isEmpty(src)) {
            throw new IllegalStateException("'" + CONFIG_KEY_SRC + "' config key not specified");
        }
        if (StringUtils.isEmpty(dest)) {
            throw new IllegalStateException("'" + CONFIG_KEY_DEST + "' config key not specified");
        }

        files.put(loadResource(src), dest);
    }
}
 
Example 6
Source File: AssetProcessingConfigReaderImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<ProcessorPipelineConfiguration> readConfig(HierarchicalConfiguration config) throws AssetProcessingConfigurationException {
    List<HierarchicalConfiguration> pipelinesConfig = config.configurationsAt(PIPELINES_CONFIG_KEY);
    if (CollectionUtils.isNotEmpty(pipelinesConfig)) {
        List<ProcessorPipelineConfiguration> mappedPipelinesConfig = new ArrayList<>(pipelinesConfig.size());

        for (HierarchicalConfiguration pipelineConfig : pipelinesConfig) {
            mappedPipelinesConfig.add(readPipelineConfig(pipelineConfig));
        }

        return mappedPipelinesConfig;
    } else {
        return Collections.emptyList();
    }
}
 
Example 7
Source File: ConfigAwareSecurityMetadataSource.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Collection<ConfigAttribute> getAttributes(final Object object) throws IllegalArgumentException {
    Callback<SecurityMetadataSource> callback = () -> {
        HierarchicalConfiguration siteConfig = ConfigUtils.getCurrentConfig();
        if (siteConfig != null) {
            List<HierarchicalConfiguration> restrictionsConfig = siteConfig.configurationsAt(URL_RESTRICTION_KEY);
            if (CollectionUtils.isNotEmpty(restrictionsConfig)) {
                LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> map = new LinkedHashMap<>();
                for (HierarchicalConfiguration restrictionConfig : restrictionsConfig) {
                    String url = restrictionConfig.getString(URL_RESTRICTION_URL_KEY);
                    String expression = restrictionConfig.getString(URL_RESTRICTION_EXPRESSION_KEY);
                    if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(expression)) {
                        AntPathRequestMatcher matcher = new AntPathRequestMatcher(url);
                        map.put(matcher, singleton(new SecurityConfig(expression)));
                    }
                }
                return new ExpressionBasedFilterInvocationSecurityMetadataSource(map,
                    new DefaultWebSecurityExpressionHandler());
            }
        }
        return new DefaultFilterInvocationSecurityMetadataSource(new LinkedHashMap<>());
    };

    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        SecurityMetadataSource metadataSource =
            cacheTemplate.getObject(siteContext.getContext(), callback, URL_RESTRICTIONS_CACHE_KEY);

        return metadataSource.getAttributes(object);
    }
    return null;
}
 
Example 8
Source File: ConfigurationScriptJobResolver.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<JobContext> resolveJobs(SiteContext siteContext) throws SchedulingException {
    HierarchicalConfiguration config = siteContext.getConfig();
    List<JobContext> jobContexts = new ArrayList<>();

    if (config != null) {
        List<HierarchicalConfiguration> jobFoldersConfig = config.configurationsAt(JOB_FOLDER_KEY);
        if (CollectionUtils.isNotEmpty(jobFoldersConfig)) {
            for (HierarchicalConfiguration jobFolderConfig : jobFoldersConfig) {
                List<JobContext> folderJobContexts = getJobsUnderFolder(siteContext, jobFolderConfig);
                if (CollectionUtils.isNotEmpty(folderJobContexts)) {
                    jobContexts.addAll(folderJobContexts);
                }
            }
        }

        List<HierarchicalConfiguration> jobsConfig = config.configurationsAt(JOB_KEY);
        if (CollectionUtils.isNotEmpty(jobsConfig)) {
            for (HierarchicalConfiguration jobConfig : jobsConfig) {
                JobContext jobContext = getJob(siteContext, jobConfig);
                if (jobContext != null) {
                    jobContexts.add(jobContext);
                }
            }
        }
    }

    return jobContexts;
}
 
Example 9
Source File: UiServiceInternalImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@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: DefaultUpgradePipelineFactoryImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public UpgradePipeline getPipeline(VersionProvider versionProvider) throws UpgradeException {
    String currentVersion = versionProvider.getCurrentVersion();
    if (SKIP.equals(currentVersion)) {
        // Return an empty pipeline to avoid errors & warnings in the log
        return new DefaultUpgradePipelineImpl();
    }
    List<UpgradeOperation> operations = new LinkedList<>();
    HierarchicalConfiguration config = loadUpgradeConfiguration();
    List<HierarchicalConfiguration> pipeline = config.configurationsAt(pipelinePrefix + "." + pipelineName);

    String nextVersion = currentVersion;
    for(HierarchicalConfiguration release : pipeline) {
        String sourceVersion = release.getString(CONFIG_KEY_CURRENT_VERSION);
        String targetVersion = release.getString(CONFIG_KEY_NEXT_VERSION);
        if(sourceVersion.equals(nextVersion)) {
            List<HierarchicalConfiguration> operationsConfig = release.configurationsAt(CONFIG_KEY_OPERATIONS);
            for(HierarchicalConfiguration operationConfig : operationsConfig) {
                UpgradeOperation operation =
                    appContext.getBean(operationConfig.getString(CONFIG_KEY_TYPE), UpgradeOperation.class);
                operation.init(sourceVersion, targetVersion, operationConfig);
                operations.add(operation);
            }
            nextVersion = targetVersion;
        }
    }
    return createPipeline(pipelineName, operations);
}
 
Example 11
Source File: AssetProcessingConfigReaderImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: ListenersConfiguration.java    From james-project with Apache License 2.0 5 votes vote down vote up
public static ListenersConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) {
    List<HierarchicalConfiguration<ImmutableNode>> listeners = configuration.configurationsAt("listener");

    return new ListenersConfiguration(listeners
        .stream()
        .map(ListenerConfiguration::from)
        .collect(Guavate.toImmutableList()));
}
 
Example 13
Source File: PreDeletionHooksConfiguration.java    From james-project with Apache License 2.0 5 votes vote down vote up
public static PreDeletionHooksConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException {
    List<HierarchicalConfiguration<ImmutableNode>> entries = configuration.configurationsAt(CONFIGURATION_ENTRY_NAME);

    return new PreDeletionHooksConfiguration(entries
        .stream()
        .map(Throwing.function(PreDeletionHookConfiguration::from).sneakyThrow())
        .collect(Guavate.toImmutableList()));
}
 
Example 14
Source File: MailRepositoryStoreConfiguration.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static List<HierarchicalConfiguration<ImmutableNode>> retrieveRegisteredClassConfiguration(HierarchicalConfiguration<ImmutableNode> configuration) {
    try {
        return configuration.configurationsAt("mailrepositories.mailrepository");
    } catch (Exception e) {
        LOGGER.warn("Could not process configuration. Skipping Mail Repository initialization.", e);
        return ImmutableList.of();
    }
}
 
Example 15
Source File: CombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Registers providers defined in the configuration.
 *
 * @param defConfig the definition configuration
 * @throws ConfigurationException if an error occurs
 */
private void registerConfiguredProviders(final HierarchicalConfiguration<?> defConfig)
        throws ConfigurationException
{
    final List<? extends HierarchicalConfiguration<?>> nodes =
            defConfig.configurationsAt(KEY_CONFIGURATION_PROVIDERS);
    for (final HierarchicalConfiguration<?> config : nodes)
    {
        final XMLBeanDeclaration decl = new XMLBeanDeclaration(config);
        final String key = config.getString(KEY_PROVIDER_KEY);
        currentParameters.registerProvider(key,
                (ConfigurationBuilderProvider) fetchBeanHelper().createBean(decl));
    }
}
 
Example 16
Source File: CombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * 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 17
Source File: FetchMail.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * Propagate any Session parameters in the configuration to the Session.
 *
 * @param configuration The configuration containing the parameters
 * @throws ConfigurationException
 */
protected void setSessionParameters(HierarchicalConfiguration<ImmutableNode> configuration) {

    if (configuration.getKeys("javaMailProperties.property").hasNext()) {
        Properties properties = getSession().getProperties();
        List<HierarchicalConfiguration<ImmutableNode>> allProperties = configuration.configurationsAt("javaMailProperties.property");
        for (HierarchicalConfiguration<ImmutableNode> propConf : allProperties) {
            String nameProp = propConf.getString("[@name]");
            String valueProp = propConf.getString("[@value]");
            properties.setProperty(nameProp, valueProp);
            LOGGER.debug("Set property name: {} to: {}", nameProp, valueProp);
        }
    }
}
 
Example 18
Source File: ScriptFilter.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected List<FilterMapping> getFilterMappings() {
    final SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        Callback<List<FilterMapping>> callback = new Callback<List<FilterMapping>>() {

            @Override
            public List<FilterMapping> execute() {
                HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
                CachingAwareList<FilterMapping> mappings = new CachingAwareList<>();

                if (config != null) {
                    List<HierarchicalConfiguration> filtersConfig = config.configurationsAt(FILTER_KEY);
                    if (CollectionUtils.isNotEmpty(filtersConfig)) {
                        for (HierarchicalConfiguration filterConfig : filtersConfig) {
                            String scriptUrl = filterConfig.getString(SCRIPT_KEY);
                            String[] includes = filterConfig.getStringArray(INCLUDE_MAPPINGS_KEY);
                            String[] excludes = filterConfig.getStringArray(EXCLUDE_MAPPINGS_KEY);

                            if (StringUtils.isNotEmpty(scriptUrl) && ArrayUtils.isNotEmpty(includes)) {
                                ContentStoreService storeService = siteContext.getStoreService();
                                ScriptFactory scriptFactory = siteContext.getScriptFactory();

                                if (!storeService.exists(siteContext.getContext(), scriptUrl)) {
                                    throw new ConfigurationException("No filter script found at " + scriptUrl);
                                }

                                FilterMapping mapping = new FilterMapping();
                                mapping.script = scriptFactory.getScript(scriptUrl);
                                mapping.includes = includes;
                                mapping.excludes = excludes;

                                mappings.add(mapping);
                            }
                        }
                    }
                }

                return mappings;
            }

        };

        return cacheTemplate.getObject(siteContext.getContext(), callback, FILTER_MAPPINGS_CACHE_KEY);
    } else {
        return null;
    }
}
 
Example 19
Source File: FetchMail.java    From james-project with Apache License 2.0 4 votes vote down vote up
/**
 * 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
 * <code>ParsedDynamicAccountParameters</code> for each dynamic account.
 */
@Override
public void configure(HierarchicalConfiguration<ImmutableNode> 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, getLocalUsers(), getDNSService(), getDomainList(), getMailQueue());

    setParsedConfiguration(parsedConfiguration);

    // Setup the Accounts
    List<HierarchicalConfiguration<ImmutableNode>> 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<ImmutableNode> 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 (ImmutableNode accountsChild : accounts.getNodeModel().getNodeHandler().getRootNode().getChildren()) {

        String accountsChildName = accountsChild.getNodeName();

        List<HierarchicalConfiguration<ImmutableNode>> accountsChildConfig = accounts.configurationsAt(accountsChildName);
        HierarchicalConfiguration<ImmutableNode> 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++;
}
 
Example 20
Source File: AbstractEnvironmentEnricher.java    From obevo with Apache License 2.0 4 votes vote down vote up
private static ImmutableList<HierarchicalConfiguration> iterConfigMutable(HierarchicalConfiguration c, String path) {
    List<HierarchicalConfiguration> list = c.configurationsAt(path);
    return list != null ? ListAdapter.adapt(list).toImmutable() : Lists.immutable.<HierarchicalConfiguration>empty();
}