use of org.craftercms.engine.exception.SiteContextCreationException in project engine by craftercms.
the class SiteContextFactory method getApplicationContext.
protected ConfigurableApplicationContext getApplicationContext(SiteContext siteContext, URLClassLoader classLoader, HierarchicalConfiguration config, String[] applicationContextPaths, ResourceLoader resourceLoader) {
try {
List<Resource> resources = new ArrayList<>();
for (String path : applicationContextPaths) {
Resource resource = resourceLoader.getResource(path);
if (resource.exists()) {
resources.add(resource);
}
}
if (CollectionUtils.isNotEmpty(resources)) {
String siteName = siteContext.getSiteName();
logger.info("--------------------------------------------------");
logger.info("<Loading application context for site: " + siteName + ">");
logger.info("--------------------------------------------------");
GenericApplicationContext appContext = new GenericApplicationContext(mainApplicationContext);
appContext.setClassLoader(classLoader);
if (config != null) {
MutablePropertySources propertySources = appContext.getEnvironment().getPropertySources();
propertySources.addFirst(new ApacheCommonsConfigPropertySource("siteConfig", config));
}
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
for (Resource resource : resources) {
reader.loadBeanDefinitions(resource);
}
appContext.refresh();
logger.info("--------------------------------------------------");
logger.info("</Loading application context for site: " + siteName + ">");
logger.info("--------------------------------------------------");
return appContext;
} else {
return null;
}
} catch (Exception e) {
throw new SiteContextCreationException("Unable to load application context for site '" + siteContext.getSiteName() + "'", e);
}
}
use of org.craftercms.engine.exception.SiteContextCreationException in project engine by craftercms.
the class SiteContextFactory method getConfig.
protected HierarchicalConfiguration getConfig(SiteContext siteContext, String[] configPaths, ResourceLoader resourceLoader) {
String siteName = siteContext.getSiteName();
try {
logger.info("--------------------------------------------------");
logger.info("<Loading configuration for site: " + siteName + ">");
logger.info("--------------------------------------------------");
ConfigurationBuilder builder = new MultiConfigurationBuilder(configPaths, resourceLoader);
HierarchicalConfiguration config = (HierarchicalConfiguration) builder.getConfiguration();
logger.info("--------------------------------------------------");
logger.info("</Loading configuration for site: " + siteName + ">");
logger.info("--------------------------------------------------");
return config;
} catch (ConfigurationException e) {
throw new SiteContextCreationException("Unable to load configuration for site '" + siteContext.getSiteName() + "'", e);
}
}
Aggregations