[exo-jcr-commits] exo-jcr SVN: r1938 - in kernel/trunk/exo.kernel.container/src: test/java/org/exoplatform/container/configuration and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Feb 22 12:04:16 EST 2010
Author: nfilotto
Date: 2010-02-22 12:04:15 -0500 (Mon, 22 Feb 2010)
New Revision: 1938
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java
Log:
EXOJCR-534: resolve invalid url of type file:, file:/ or file://
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2010-02-22 16:22:32 UTC (rev 1937)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2010-02-22 17:04:15 UTC (rev 1938)
@@ -317,8 +317,8 @@
}
else if (url.startsWith("file:"))
{
- url = Deserializer.resolveVariables(url);
- return new URL(url.replace('\\', '/'));
+ url = resolveFileURL(url);
+ return new URL(url);
}
else if (url.indexOf(":") < 0 && contextPath != null)
{
@@ -327,6 +327,48 @@
return null;
}
+ /**
+ * This methods is used to convert the given into a valid url, it will:
+ * <ol>
+ * <li>Resolve variables in the path if they exist</li>
+ * <li>Replace windows path separators with proper separators</li>
+ * <li>Ensure that the path start with file:///</li>
+ * </ol>
+ * , then it will
+ * @param url the url to resolve
+ * @return the resolved url
+ */
+ private String resolveFileURL(String url)
+ {
+ url = Deserializer.resolveVariables(url);
+ // we ensure that we don't have windows path separator in the url
+ url = url.replace('\\', '/');
+ if (!url.startsWith("file:///"))
+ {
+ // The url is invalid, so we will fix it
+ // it happens when we use a path of type file://${path}, under
+ // linux or mac os the path will start with a '/' so the url
+ // will be correct but under windows we will have something
+ // like C:\ so the first '/' is missing
+ if (url.startsWith("file://"))
+ {
+ // The url is of type file://, so one '/' is missing
+ url = "file:///" + url.substring(7);
+ }
+ else if (url.startsWith("file:/"))
+ {
+ // The url is of type file:/, so two '/' are missing
+ url = "file:///" + url.substring(6);
+ }
+ else
+ {
+ // The url is of type file:, so three '/' are missing
+ url = "file:///" + url.substring(5);
+ }
+ }
+ return url;
+ }
+
public boolean isDefault(String value)
{
return value == null || value.length() == 0 || "default".equals(value);
Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java 2010-02-22 16:22:32 UTC (rev 1937)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java 2010-02-22 17:04:15 UTC (rev 1938)
@@ -84,6 +84,18 @@
checkURL(url);
url = cm.getURL(sURL + "\\configuration\\empty-config-fake.xml");
checkURL(url, true);
+ String incompleteURL = "file:/" + getClass().getResource("empty-config.xml").getPath();
+ incompleteURL = incompleteURL.substring(0, incompleteURL.lastIndexOf('/'));
+ url = cm.getURL(incompleteURL + "/empty-config.xml");
+ checkURL(url);
+ url = cm.getURL(incompleteURL + "/empty-config-fake.xml");
+ checkURL(url, true);
+ incompleteURL = "file:" + getClass().getResource("empty-config.xml").getPath();
+ incompleteURL = incompleteURL.substring(0, incompleteURL.lastIndexOf('/'));
+ url = cm.getURL(incompleteURL + "/empty-config.xml");
+ checkURL(url);
+ url = cm.getURL(incompleteURL + "/empty-config-fake.xml");
+ checkURL(url, true);
url = cm.getURL("org/exoplatform/container/configuration/empty-config.xml");
assertNull(url);
url = cm.getURL("org/exoplatform/container/configuration/empty-config-fake.xml");
More information about the exo-jcr-commits
mailing list