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

The following examples show how to use org.apache.commons.configuration2.HierarchicalConfiguration#childConfigurationsAt() . 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: StandaloneHeadersAuthenticationFilter.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets additional attributes on the given user based on the requests headers and the site configuration
 */
@SuppressWarnings("unchecked")
protected void addAttributes(final CustomUser user, final HttpServletRequest request,
                             final HierarchicalConfiguration config) {
    List<HierarchicalConfiguration> attrsConfig = config.childConfigurationsAt(HEADERS_ATTRS_CONFIG_KEY);
    if (CollectionUtils.isNotEmpty(attrsConfig)) {
        attrsConfig.forEach(attrConfig -> {
            String headerName = attrConfig.getString(NAME_CONFIG_KEY);
            String fieldName = attrConfig.getString(FIELD_CONFIG_KEY);
            String fieldValue = request.getHeader(headerPrefix + headerName);

            if (isNotEmpty(fieldValue)) {
                logger.debug("Adding attribute '{}' with value '{}'", fieldName, fieldValue);
                user.setAttribute(fieldName, fieldValue);
            } else {
                logger.debug("Expected header '{}' was not present in the request", headerName);
            }
        });
    }
}
 
Example 2
Source File: CombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the override configurations that are defined as top level
 * elements in the configuration definition file. This method fetches
 * the child elements of the root node and removes the nodes that
 * represent other configuration sections. The remaining nodes are
 * treated as definitions for override configurations.
 *
 * @param config the definition configuration
 * @return a list with sub configurations for the top level override
 *         configurations
 */
private List<? extends HierarchicalConfiguration<?>> fetchTopLevelOverrideConfigs(
        final HierarchicalConfiguration<?> config)
{

    final List<? extends HierarchicalConfiguration<?>> configs =
            config.childConfigurationsAt(null);
    for (final Iterator<? extends HierarchicalConfiguration<?>> it =
            configs.iterator(); it.hasNext();)
    {
        final String nodeName = it.next().getRootElementName();
        for (final String element : CONFIG_SECTIONS)
        {
            if (element.equals(nodeName))
            {
                it.remove();
                break;
            }
        }
    }
    return configs;
}
 
Example 3
Source File: DefaultUpgradeManagerImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void upgradeSiteConfiguration(final String site) throws UpgradeException {
    logger.info("Checking upgrades for configuration in site {0}", site);

    String defaultEnvironment = studioConfiguration.getProperty(CONFIGURATION_ENVIRONMENT_ACTIVE);
    HierarchicalConfiguration config = loadUpgradeConfiguration();
    List<HierarchicalConfiguration> managedFiles = config.childConfigurationsAt(CONFIG_KEY_CONFIGURATIONS);
    String configPath = null;

    try {
        for (HierarchicalConfiguration configFile : managedFiles) {
            String module = configFile.getString(CONFIG_KEY_MODULE);
            String file = configFile.getString(CONFIG_KEY_PATH);
            List<String> environments = getExistingEnvironments(site);

            for (String env : environments) {
                Map<String, String> values = new HashMap<>();
                values.put(CONFIG_KEY_MODULE, module);
                values.put(CONFIG_KEY_ENVIRONMENT, env);
                String basePath;

                if (StringUtils.isEmpty(env) || env.equals(defaultEnvironment)) {
                    basePath = studioConfiguration.getProperty(CONFIGURATION_SITE_CONFIG_BASE_PATH_PATTERN);
                } else {
                    basePath = studioConfiguration.getProperty(
                            CONFIGURATION_SITE_MUTLI_ENVIRONMENT_CONFIG_BASE_PATH_PATTERN);
                }
                configPath = get(StrSubstitutor.replace(basePath, values, "{", "}"), file).toString();
                logger.info("Checking upgrades for file {0}", configPath);
                currentFile.set(configPath);

                VersionProvider versionProvider = getVersionProvider("fileVersionProvider", site, configPath);
                UpgradePipeline pipeline = getPipeline(versionProvider, "filePipelineFactory",
                        configFile.getRootElementName() + CONFIG_PIPELINE_SUFFIX);

                pipeline.execute(site);
            }
        }
    } catch (Exception e) {
        logger.error("Error upgrading configuration file {0}", e, configPath);
    } finally {
        currentFile.remove();
    }
}