[exo-jcr-commits] exo-jcr SVN: r1951 - in kernel/trunk/exo.kernel.container/src: main/java/org/exoplatform/container/util and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Feb 25 07:04:16 EST 2010
Author: nfilotto
Date: 2010-02-25 07:04:15 -0500 (Thu, 25 Feb 2010)
New Revision: 1951
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties
Log:
EXOJCR-528: Allow to use ${name}, ${rest} and ${realm} in the external properties file
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-02-24 15:39:10 UTC (rev 1950)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-02-25 12:04:15 UTC (rev 1951)
@@ -481,21 +481,36 @@
String path = def.getExternalSettingsPath();
if (path != null && (path = path.trim()).length() > 0)
{
- final Map<String, String> props = loadExternalSettings(path, def.getName());
+ final Map<String, String> props = loadExternalSettings(path, def);
if (props != null && !props.isEmpty())
{
mergeSettings(settings, props);
}
}
- // We then add the portal container name
+ // We then add the main settings
+ settings.putAll(getMainSettings(def));
+ // We re-inject the settings and we make sure it is thread safe
+ def.setSettings(Collections.unmodifiableMap(settings));
+ }
+
+ /**
+ * This method gives the main settings such as the portal container name, the rest context name
+ * and the realm name into a {@link Map}
+ * @param def the {@link PortalContainerDefinition} from which we extract the value of the main
+ * settings, if a main setting is null, we use the default value.
+ * @return A {@link Map} of settings including the main settings
+ */
+ private Map<String, String> getMainSettings(PortalContainerDefinition def)
+ {
+ final Map<String, String> settings = new HashMap<String, String>(3);
+ // We add the portal container name
settings.put(PORTAL_CONTAINER_SETTING_NAME, def.getName());
// We add the rest context name
settings.put(REST_CONTEXT_SETTING_NAME, def.getRestContextName() == null ? defaultRestContextName : def
.getRestContextName());
// We add the realm name
settings.put(REALM_SETTING_NAME, def.getRealmName() == null ? defaultRealmName : def.getRealmName());
- // We re-inject the settings and we make sure it is thread safe
- def.setSettings(Collections.unmodifiableMap(settings));
+ return settings;
}
/**
@@ -515,10 +530,10 @@
* by the {@link ConfigurationManager}</li>
* </ol>
* @param path the path of the external settings to load
- * @param portalContainerName the name of the related portal container
+ * @param def the {@link PortalContainerDefinition} for which we load the external settings
* @return A {@link Map} of settings if the file could be loaded, <code>null</code> otherwise
*/
- private Map<String, String> loadExternalSettings(String path, String portalContainerName)
+ private Map<String, String> loadExternalSettings(String path, PortalContainerDefinition def)
{
try
{
@@ -526,7 +541,7 @@
if (path.indexOf(':') == -1)
{
// We first check if the file is not in eXo configuration directory
- String fullPath = serverInfo.getExoConfigurationDirectory() + "/portal/" + portalContainerName + "/" + path;
+ String fullPath = serverInfo.getExoConfigurationDirectory() + "/portal/" + def.getName() + "/" + path;
File file = new File(fullPath);
if (file.exists())
{
@@ -540,7 +555,7 @@
url = cm.getURL(path);
}
// We load the properties from the url found
- return ContainerUtil.loadProperties(url);
+ return ContainerUtil.loadProperties(url, getMainSettings(def));
}
catch (Exception e)
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java 2010-02-24 15:39:10 UTC (rev 1950)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java 2010-02-25 12:04:15 UTC (rev 1951)
@@ -208,6 +208,17 @@
*/
public static Map<String, String> loadProperties(URL url)
{
+ return loadProperties(url, null);
+ }
+
+ /**
+ * Loads the properties file corresponding to the given url
+ * @param url the url of the properties file
+ * @param initEnv the initial environment that is composed of a set of initial variables
+ * @return a {@link Map} of properties
+ */
+ public static Map<String, String> loadProperties(URL url, Map<String, String> initEnv)
+ {
LinkedHashMap<String, String> props = null;
String path = null;
InputStream in = null;
@@ -243,7 +254,12 @@
if (props != null)
{
// Those properties are used for variables resolution
- final LinkedHashMap<String, String> currentProps = new LinkedHashMap<String,String>();
+ final Map<String, String> currentProps = new HashMap<String,String>();
+ if (initEnv != null && !initEnv.isEmpty())
+ {
+ // There are a set of initial variables to load into the environment
+ currentProps.putAll(initEnv);
+ }
for (Map.Entry<String, String> entry : props.entrySet())
{
String propertyName = entry.getKey();
Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-02-24 15:39:10 UTC (rev 1950)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-02-25 12:04:15 UTC (rev 1951)
@@ -278,7 +278,7 @@
assertEquals("20", config.getSetting("myPortal-pcdef", "long"));
assertEquals("20", config.getSetting("myPortal-pcdef", "double"));
assertEquals("false", config.getSetting("myPortal-pcdef", "boolean"));
- assertEquals("value-new value", config.getSetting("myPortal-pcdef", "complex-value"));
+ assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value-new value", config.getSetting("myPortal-pcdef", "complex-value"));
assertNull(config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
assertNull(config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef",
@@ -311,7 +311,7 @@
assertEquals("22", config.getSetting("myPortal-pcdef", "long"));
assertEquals("22", config.getSetting("myPortal-pcdef", "double"));
assertEquals("true", config.getSetting("myPortal-pcdef", "boolean"));
- assertEquals("value 2-new value 2", config.getSetting("myPortal-pcdef", "complex-value"));
+ assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value 2-new value 2", config.getSetting("myPortal-pcdef", "complex-value"));
assertNull(config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
assertNull(config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef",
Modified: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties 2010-02-24 15:39:10 UTC (rev 1950)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties 2010-02-25 12:04:15 UTC (rev 1951)
@@ -4,4 +4,4 @@
long=22
double=22
boolean=true
-complex-value=${foo2}-${string}
\ No newline at end of file
+complex-value=${name}-${rest}-${realm}-${foo2}-${string}
\ No newline at end of file
Modified: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties 2010-02-24 15:39:10 UTC (rev 1950)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties 2010-02-25 12:04:15 UTC (rev 1951)
@@ -4,4 +4,4 @@
long=20
double=20
boolean=false
-complex-value=${foo2}-${string}
\ No newline at end of file
+complex-value=${name}-${rest}-${realm}-${foo2}-${string}
\ No newline at end of file
More information about the exo-jcr-commits
mailing list