Search in sources :

Example 11 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class ConfigAwareAccessTokenIdResolver method getAccessTokenId.

@Override
public String getAccessTokenId() {
    String accessTokenId = null;
    HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        accessTokenId = config.getString(ACCESS_TOKEN_ID_KEY);
    }
    if (StringUtils.isNotEmpty(accessTokenId)) {
        return accessTokenId;
    } else {
        throw new ConfigurationException("Current config for site '" + SiteContext.getCurrent().getSiteName() + "' doesn't contain required property " + ACCESS_TOKEN_ID_KEY);
    }
}
Also used : ConfigurationException(org.craftercms.engine.exception.ConfigurationException) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Example 12 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class SiteContextFactory method getConfig.

protected HierarchicalConfiguration getConfig(SiteContext siteContext, String[] configPaths, ResourceLoader resourceLoader) {
    String siteName = siteContext.getSiteName();
    try {
        logger.info("--------------------------------------------------");
        logger.info("<Loading configuration for site: " + siteName + ">");
        logger.info("--------------------------------------------------");
        ConfigurationBuilder<HierarchicalConfiguration> builder;
        if (textEncryptor instanceof NoOpTextEncryptor) {
            builder = new MultiResourceConfigurationBuilder(configPaths, resourceLoader);
        } else {
            builder = new MultiResourceConfigurationBuilder(configPaths, resourceLoader, textEncryptor);
        }
        HierarchicalConfiguration config = builder.getConfiguration();
        logger.info("--------------------------------------------------");
        logger.info("</Loading configuration for site: " + siteName + ">");
        logger.info("--------------------------------------------------");
        return config;
    } catch (ConfigurationException e) {
        throw new SiteContextCreationException("Unable to load configuration for site '" + siteContext.getSiteName() + "'", e);
    }
}
Also used : SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) MultiResourceConfigurationBuilder(org.craftercms.engine.util.config.impl.MultiResourceConfigurationBuilder) NoOpTextEncryptor(org.craftercms.commons.crypto.impl.NoOpTextEncryptor) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Example 13 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class ConfigAwareConnectionFactoryLocator method getCurrentConnectionFactoryLocator.

protected ConnectionFactoryLocator getCurrentConnectionFactoryLocator() {
    Callback<ConnectionFactoryLocator> callback = new Callback<ConnectionFactoryLocator>() {

        @Override
        public ConnectionFactoryLocator execute() {
            HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
            ConnectionFactoryRegistry registry = null;
            if (config != null) {
                try {
                    HierarchicalConfiguration socialConnectionsConfig = config.configurationAt(SOCIAL_CONNECTIONS_KEY);
                    for (ConfigurationParser<?> parser : configParsers) {
                        ConnectionFactory<?> factory = (ConnectionFactory<?>) parser.parse(socialConnectionsConfig);
                        if (factory != null) {
                            if (registry == null) {
                                registry = new ConnectionFactoryRegistry();
                            }
                            registry.addConnectionFactory(factory);
                        }
                    }
                } catch (IllegalArgumentException e) {
                // Ignore if != 1
                }
            }
            if (registry != null) {
                return registry;
            } else {
                return defaultLocator;
            }
        }
    };
    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        return cacheTemplate.getObject(siteContext.getContext(), callback, CONNECTION_FACTORY_LOCATOR_CACHE_KEY);
    } else {
        return defaultLocator;
    }
}
Also used : ConnectionFactory(org.springframework.social.connect.ConnectionFactory) Callback(org.craftercms.commons.lang.Callback) SiteContext(org.craftercms.engine.service.context.SiteContext) ConnectionFactoryLocator(org.springframework.social.connect.ConnectionFactoryLocator) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) ConnectionFactoryRegistry(org.springframework.social.connect.support.ConnectionFactoryRegistry)

Example 14 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class CandidateTargetedUrlsResolverImplTest method setUpCurrentSiteContext.

private void setUpCurrentSiteContext() {
    HierarchicalConfiguration config = mock(HierarchicalConfiguration.class);
    when(config.getStringArray(ROOT_FOLDERS_CONFIG_KEY)).thenReturn(ROOT_FOLDERS);
    SiteContext context = new SiteContext();
    context.setSiteName(SITE_NAME);
    context.setConfig(config);
    SiteContext.setCurrent(context);
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Example 15 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class TargetedContentDescriptorMergeStrategyTest method setUpCurrentSiteContext.

private void setUpCurrentSiteContext() {
    HierarchicalConfiguration config = mock(HierarchicalConfiguration.class);
    when(config.getStringArray(ROOT_FOLDERS_CONFIG_KEY)).thenReturn(ROOT_FOLDERS);
    when(config.getStringArray(AVAILABLE_TARGET_IDS_CONFIG_KEY)).thenReturn(AVAILABLE_TARGET_IDS);
    when(config.getString(FALLBACK_ID_CONFIG_KEY)).thenReturn(FALLBACK_TARGET_ID);
    SiteContext siteContext = new SiteContext();
    siteContext.setSiteName(SITE_NAME);
    siteContext.setConfig(config);
    SiteContext.setCurrent(siteContext);
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Aggregations

HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)13 SiteContext (org.craftercms.engine.service.context.SiteContext)8 ArrayList (java.util.ArrayList)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)4 Callback (org.craftercms.commons.lang.Callback)3 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)3 SiteContextCreationException (org.craftercms.engine.exception.SiteContextCreationException)3 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 BeansException (org.springframework.beans.BeansException)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 Resource (org.springframework.core.io.Resource)2 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1