Search in sources :

Example 1 with ConnectionFactory

use of org.springframework.social.connect.ConnectionFactory 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 {
                    SubnodeConfiguration 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 : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) ConnectionFactory(org.springframework.social.connect.ConnectionFactory) Callback(org.craftercms.commons.lang.Callback) SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) ConnectionFactoryLocator(org.springframework.social.connect.ConnectionFactoryLocator) ConnectionFactoryRegistry(org.springframework.social.connect.support.ConnectionFactoryRegistry)

Aggregations

HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 SubnodeConfiguration (org.apache.commons.configuration.SubnodeConfiguration)1 Callback (org.craftercms.commons.lang.Callback)1 SiteContext (org.craftercms.engine.service.context.SiteContext)1 ConnectionFactory (org.springframework.social.connect.ConnectionFactory)1 ConnectionFactoryLocator (org.springframework.social.connect.ConnectionFactoryLocator)1 ConnectionFactoryRegistry (org.springframework.social.connect.support.ConnectionFactoryRegistry)1