]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Normalize URLs
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 21 Jun 2008 17:51:52 +0000 (17:51 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 21 Jun 2008 17:51:52 +0000 (17:51 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1272 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java

index 8ef13560cf2695a84139c91ad9d77dafe67b2d8b..cbc5c6abfc21e60eaeb076e27ae0e9f6c668fd04 100644 (file)
@@ -1,6 +1,8 @@
 package org.argeo.slc.spring;\r
 \r
 import java.io.IOException;\r
+import java.net.URI;\r
+import java.net.URL;\r
 import java.util.Map;\r
 \r
 import org.apache.commons.logging.Log;\r
@@ -27,23 +29,25 @@ public class SpringUtils {
                try {\r
                        if (res.getURL().getPath().equals("/"))\r
                                return null;\r
-                       \r
+\r
                        String urlStr = res.getURL().toString();\r
                        if (urlStr.charAt(urlStr.length() - 1) == '/')\r
                                urlStr = urlStr.substring(0, urlStr.length() - 2);\r
 \r
-                       String parentUrlStr = urlStr.substring(0, urlStr.lastIndexOf('/'));\r
+                       String parentUrlStr = urlStr.substring(0, urlStr.lastIndexOf('/')) + '/';\r
+                       URI uri = new URI(parentUrlStr).normalize();\r
                        return new DefaultResourceLoader(Thread.currentThread()\r
-                                       .getContextClassLoader()).getResource(parentUrlStr + '/');\r
-               } catch (IOException e) {\r
+                                       .getContextClassLoader()).getResource(uri.toString());\r
+               } catch (Exception e) {\r
                        throw new SlcException("Cannot get parent for resource " + res, e);\r
                }\r
        }\r
 \r
        public static String extractRelativePath(Resource ancestor, Resource child) {\r
                try {\r
-                       \r
-                       return ancestor.getURI().relativize(child.getURI()).toString();\r
+\r
+                       return ancestor.getURI().relativize(child.getURI()).normalize()\r
+                                       .toString();\r
                } catch (IOException e) {\r
                        throw new SlcException("Cannot extract relative path of " + child\r
                                        + " based on " + ancestor, e);\r