use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class RestScriptsControllerTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) {
SiteContext siteContext = mock(SiteContext.class);
ContentStoreResourceConnector resourceConnector = new ContentStoreResourceConnector(siteContext);
ScriptFactory scriptFactory = new GroovyScriptFactory(resourceConnector, Collections.<String, Object>emptyMap());
when(siteContext.getSiteName()).thenReturn("test");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getRestScriptsPath()).thenReturn("/scripts");
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getScriptFactory()).thenReturn(scriptFactory);
return siteContext;
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class StaticAssetsRequestHandler method handleRequest.
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
checkAndPrepare(request, response, true);
SiteContext siteContext = SiteContext.getCurrent();
String path = getPath(request, siteContext);
if (siteContext == null) {
throw new IllegalStateException("No current site context found");
}
if (logger.isDebugEnabled()) {
logger.debug("Trying to get content for static asset at [context=" + siteContext + ", path='" + path + "']");
}
Content content = getContent(siteContext, path);
if (content == null) {
if (logger.isDebugEnabled()) {
logger.debug("No static asset found at [context=" + siteContext + ", path='" + path + "'] - returning 404");
}
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
MediaType mediaType = getMediaType(path);
if (mediaType != null) {
if (logger.isDebugEnabled()) {
logger.debug("Determined media type '" + mediaType + "' for static asset at [context=" + siteContext + ", path='" + path + "']");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("No media type found for static asset at [context=" + siteContext + ", path='" + path + "'] - not sending a content-type header");
}
}
if ((new ServletWebRequest(request, response)).checkNotModified(content.getLastModified())) {
if (logger.isDebugEnabled()) {
logger.debug("Static asset not modified - returning 304");
}
return;
}
setHeaders(response, content, mediaType);
if (disableCaching) {
if (logger.isDebugEnabled()) {
logger.debug("Caching disabled on client");
}
HttpUtils.disableCaching(response);
}
if (METHOD_HEAD.equals(request.getMethod())) {
logger.trace("HEAD request - skipping content");
return;
}
writeContent(response, content);
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class ScriptFilterTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) throws Exception {
SiteContext siteContext = mock(SiteContext.class);
ScriptFactory scriptFactory = createScriptFactory(siteContext);
when(siteContext.getSiteName()).thenReturn("default");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getConfig()).thenReturn(new XMLConfiguration("config/site.xml"));
when(siteContext.getScriptFactory()).thenReturn(scriptFactory);
return siteContext;
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class SiteItemScriptResolverImplTest method createSiteContext.
private SiteContext createSiteContext() {
SiteContext siteContext = mock(SiteContext.class);
when(siteContext.getSiteName()).thenReturn("test");
when(siteContext.getContext()).thenReturn(mock(Context.class));
return siteContext;
}
use of org.craftercms.engine.service.context.SiteContext in project engine by craftercms.
the class ToTargetedUrlTransformerTest method setUpCurrentSiteContext.
private void setUpCurrentSiteContext() {
HierarchicalConfiguration config = mock(HierarchicalConfiguration.class);
when(config.getBoolean(TARGETING_ENABLED_CONFIG_KEY, false)).thenReturn(true);
when(config.getStringArray(ROOT_FOLDERS_CONFIG_KEY)).thenReturn(ROOT_FOLDERS);
when(config.getStringArray(EXCLUDE_PATTERNS_CONFIG_KEY)).thenReturn(new String[] { "/site/website/index\\.xml" });
SiteContext siteContext = new SiteContext();
siteContext.setSiteName(SITE_NAME);
siteContext.setConfig(config);
SiteContext.setCurrent(siteContext);
}
Aggregations