use of org.craftercms.engine.graphql.GraphQLFactory in project engine by craftercms.
the class SiteContextFactory method createContext.
public SiteContext createContext(String siteName) {
Map<String, String> macroValues = new HashMap<>();
macroValues.put(siteNameMacroName, siteName);
if (publishingTargetResolver instanceof SiteAwarePublishingTargetResolver) {
String target = ((SiteAwarePublishingTargetResolver) publishingTargetResolver).getPublishingTarget(siteName);
macroValues.put(publishingTargetMacroName, target);
}
String resolvedRootFolderPath = macroResolver.resolveMacros(rootFolderPath, macroValues);
Context context = storeService.getContext(UUID.randomUUID().toString(), storeType, resolvedRootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
try {
SiteContext siteContext = new SiteContext();
siteContext.setInitTimeout(initTimeout);
siteContext.setStoreService(storeService);
siteContext.setCacheTemplate(cacheTemplate);
siteContext.setSiteName(siteName);
siteContext.setContext(context);
siteContext.setStaticAssetsPath(staticAssetsPath);
siteContext.setTemplatesPath(templatesPath);
siteContext.setInitScriptPath(initScriptPath);
siteContext.setFreeMarkerConfig(freeMarkerConfigFactory.getObject());
siteContext.setUrlTransformationEngine(urlTransformationEngine);
siteContext.setRestScriptsPath(restScriptsPath);
siteContext.setControllerScriptsPath(controllerScriptsPath);
siteContext.setGraphQLFactory(graphQLFactory);
siteContext.setShutdownTimeout(shutdownTimeout);
if (disableVariableRestrictions) {
siteContext.setServletContext(servletContext);
}
if (cacheWarmUpEnabled) {
siteContext.setCacheWarmer(cacheWarmer);
}
String[] resolvedConfigPaths = new String[configPaths.length];
for (int i = 0; i < configPaths.length; i++) {
resolvedConfigPaths[i] = macroResolver.resolveMacros(configPaths[i], macroValues);
}
String[] resolvedAppContextPaths = new String[applicationContextPaths.length];
for (int i = 0; i < applicationContextPaths.length; i++) {
resolvedAppContextPaths[i] = macroResolver.resolveMacros(applicationContextPaths[i], macroValues);
}
String[] resolvedUrlRewriteConfPaths = new String[urlRewriteConfPaths.length];
for (int i = 0; i < urlRewriteConfPaths.length; i++) {
resolvedUrlRewriteConfPaths[i] = macroResolver.resolveMacros(urlRewriteConfPaths[i], macroValues);
}
List<String> resolvedProxyConfPaths = Stream.of(proxyConfigPaths).map(path -> macroResolver.resolveMacros(path, macroValues)).collect(toList());
ResourceLoader resourceLoader = new ContentStoreResourceLoader(siteContext);
HierarchicalConfiguration<?> config = getConfig(siteContext, resolvedConfigPaths, resourceLoader);
configureScriptSandbox(siteContext, resourceLoader);
URLClassLoader classLoader = getClassLoader(siteContext);
ScriptFactory scriptFactory = getScriptFactory(siteContext, classLoader);
ConfigurableApplicationContext appContext = getApplicationContext(siteContext, classLoader, config, resolvedAppContextPaths, resourceLoader);
UrlRewriter urlRewriter = getUrlRewriter(siteContext, resolvedUrlRewriteConfPaths, resourceLoader);
HierarchicalConfiguration proxyConfig = getProxyConfig(siteContext, resolvedProxyConfPaths, resourceLoader);
siteContext.setScriptFactory(scriptFactory);
siteContext.setConfig(config);
siteContext.setGlobalApplicationContext(globalApplicationContext);
siteContext.setApplicationContext(appContext);
siteContext.setClassLoader(classLoader);
siteContext.setUrlRewriter(urlRewriter);
siteContext.setProxyConfig(proxyConfig);
if (config != null) {
siteContext.setAllowedTemplatePaths(config.getStringArray(CONFIG_KEY_ALLOWED_TEMPLATE_PATHS));
}
Scheduler scheduler = scheduleJobs(siteContext);
siteContext.setScheduler(scheduler);
return siteContext;
} catch (Exception e) {
logger.error("Error creating context for site '" + siteName + "'", e);
// Destroy context if the site context creation failed
storeService.destroyContext(context);
throw e;
}
}
Aggregations