From 0793aa4c87aa5158a117260aa414cf983cedb201 Mon Sep 17 00:00:00 2001 From: Minos Chatzidakis Date: Thu, 19 Dec 2019 13:05:16 +0100 Subject: [PATCH] HSTTWO-4530 Use hstRoot property from hcm-site.yaml Alternative implementation using the DefaultHstSiteConfigurer --- .../container/DefaultHstSiteConfigurer.java | 35 +++++++++++++++++-- .../SpringComponentManager.properties | 2 -- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/community/site-toolkit/components/core/src/main/java/org/hippoecm/hst/site/container/DefaultHstSiteConfigurer.java b/community/site-toolkit/components/core/src/main/java/org/hippoecm/hst/site/container/DefaultHstSiteConfigurer.java index fae30785f8d..3bdaf1d0bb9 100644 --- a/community/site-toolkit/components/core/src/main/java/org/hippoecm/hst/site/container/DefaultHstSiteConfigurer.java +++ b/community/site-toolkit/components/core/src/main/java/org/hippoecm/hst/site/container/DefaultHstSiteConfigurer.java @@ -16,10 +16,13 @@ package org.hippoecm.hst.site.container; import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -45,8 +48,10 @@ import org.hippoecm.hst.site.HstServices; import org.hippoecm.hst.site.addon.module.model.ModuleDefinition; import org.hippoecm.hst.util.ServletConfigUtils; import org.onehippo.cms7.services.context.HippoWebappContext; +import org.onehippo.cms7.services.context.HippoWebappContextRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; import static org.onehippo.cms7.services.context.HippoWebappContext.CMS_OR_PLATFORM; @@ -144,7 +149,7 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer { private boolean forcefulReinitialization; - private Configuration configuration; + private CompositeConfiguration configuration; private long configurationRefreshDelay; @@ -214,6 +219,8 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer { configurationRefreshDelay = NumberUtils.toLong(getConfigOrContextInitParameter(HST_CONFIGURATION_REFRESH_DELAY_PARAM, null), DEFAULT_CONFIGURATION_REFRESH_DELAY); this.configuration = getConfiguration(); + this.configuration.addProperty("hst.configuration.rootPath", getHstRootPath(servletContext)); + if (configurationRefreshDelay > 0L) { setUpFileConfigurationReloadingStrategies(); @@ -350,7 +357,7 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer { * @return Configuration containing all the params found in the system, jndi and the config file found * @throws ContainerException thrown if file's cannot be found or configuration problems arise. */ - protected Configuration getConfiguration() throws ContainerException { + protected CompositeConfiguration getConfiguration() throws ContainerException { try { Configuration [] configs = loadFileConfigurations(); CompositeConfiguration configuration = new CompositeConfiguration(); @@ -645,4 +652,28 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer { } } + private static final String PLATFORM_HST_ROOT_PATH = "/hst:platform"; + private static final String HST_DEFAULT_ROOT_PATH = "/hst:hst"; + private static final String HCM_SITE_DESCRIPTOR = "hcm-site.yaml"; + private static final String HCM_SITE_DESCRIPTOR_LOCATION = "META-INF/" + HCM_SITE_DESCRIPTOR; + private static final String HCM_SITE_DESCRIPTOR_FIELD_ROOT = "hstRoot"; + + public static String getHstRootPath(final ServletContext servletContext) { + final HippoWebappContext.Type type = HippoWebappContextRegistry.get().getContext(servletContext.getContextPath()).getType(); + if (CMS_OR_PLATFORM.contains(type)) { + return PLATFORM_HST_ROOT_PATH; + } + try (final InputStream hcmSiteIs = servletContext.getResourceAsStream(HCM_SITE_DESCRIPTOR_LOCATION)) { + if (hcmSiteIs != null) { + final Yaml yamlReader = new Yaml(); + Map siteConfig = yamlReader.load(hcmSiteIs); + if (siteConfig.containsKey(HCM_SITE_DESCRIPTOR_FIELD_ROOT)) { + return siteConfig.get(HCM_SITE_DESCRIPTOR_FIELD_ROOT); + } + } + } catch (IOException e) { + } + return HST_DEFAULT_ROOT_PATH; + } + } diff --git a/community/site-toolkit/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager.properties b/community/site-toolkit/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager.properties index 26dfc08527c..b27f9d1635b 100644 --- a/community/site-toolkit/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager.properties +++ b/community/site-toolkit/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager.properties @@ -148,8 +148,6 @@ writable.repository.user.name = sitewriter writable.repository.pool.name = writable writable.repository.password = -# if not explicitly defined, the root path is '/hst:platform' -hst.configuration.rootPath = /hst:platform repository.pool.counter.enabled = true default.binaries.cache.maxEntries = 256 -- 2.24.3 (Apple Git-128)