Search in sources :

Example 21 with SiteContext

use of org.craftercms.engine.service.context.SiteContext 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)

Example 22 with SiteContext

use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.

the class UrlTransformationServiceImpl method transform.

public String transform(String transformerName, String url, boolean cache) {
    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        CachingOptions cachingOptions = new CachingOptions();
        cachingOptions.setDoCaching(cache);
        return siteContext.getUrlTransformationEngine().transformUrl(siteContext.getContext(), cachingOptions, transformerName, url);
    } else {
        return url;
    }
}
Also used : CachingOptions(org.craftercms.core.service.CachingOptions) SiteContext(org.craftercms.engine.service.context.SiteContext)

Example 23 with SiteContext

use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.

the class SiteContextResolvingFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    SiteContext siteContext = contextResolver.getContext((HttpServletRequest) request);
    if (siteContext == null) {
        throw new CrafterException("No site context was resolved for the current request");
    }
    SiteContext.setCurrent(siteContext);
    try {
        chain.doFilter(request, response);
    } finally {
        SiteContext.clear();
    }
}
Also used : CrafterException(org.craftercms.core.exception.CrafterException) SiteContext(org.craftercms.engine.service.context.SiteContext)

Example 24 with SiteContext

use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.

the class ToCurrentTargetedVersionItemProcessorTest method setUpCurrentConfig.

private void setUpCurrentConfig() {
    XMLConfiguration config = mock(XMLConfiguration.class);
    when(config.getBoolean(TARGETING_ENABLED_CONFIG_KEY, false)).thenReturn(true);
    SiteContext siteContext = mock(SiteContext.class);
    when(siteContext.getSiteName()).thenReturn("test");
    when(siteContext.getConfig()).thenReturn(config);
    SiteContext.setCurrent(siteContext);
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) SiteContext(org.craftercms.engine.service.context.SiteContext)

Example 25 with SiteContext

use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.

the class NavBreadcrumbBuilderImplTest method setUpCurrentSiteContext.

private void setUpCurrentSiteContext() {
    SiteContext siteContext = mock(SiteContext.class);
    when(siteContext.getSiteName()).thenReturn("test");
    SiteContext.setCurrent(siteContext);
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext)

Aggregations

SiteContext (org.craftercms.engine.service.context.SiteContext)35 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)8 Context (org.craftercms.core.service.Context)7 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)6 HashMap (java.util.HashMap)4 ServletContext (javax.servlet.ServletContext)4 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)4 RequestContext (org.craftercms.commons.http.RequestContext)4 Callback (org.craftercms.commons.lang.Callback)3 ContentStoreService (org.craftercms.core.service.ContentStoreService)3 Script (org.craftercms.engine.scripting.Script)3 TemplateException (freemarker.template.TemplateException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.commons.configuration.Configuration)2 CrafterException (org.craftercms.core.exception.CrafterException)2 Content (org.craftercms.core.service.Content)2 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2