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;
}
}
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;
}
}
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();
}
}
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);
}
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);
}
Aggregations