]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java
Remove unused DAOs
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / spring / SpringUtils.java
index 73f1ffde37647b9465267ef4cec4316e6dcd17c5..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
@@ -32,24 +34,20 @@ public class SpringUtils {
                        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
-                       String childPath = child.getURL().getPath();\r
-                       String ancestorPath = ancestor.getURL().getPath();\r
-\r
-                       if (log.isTraceEnabled())\r
-                               log.trace("extractRelativePath(): childPath=" + childPath\r
-                                               + ", ancestorPath=" + ancestorPath);\r
 \r
-                       return childPath.substring(ancestorPath.length());\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