X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fspring%2FSpringUtils.java;h=cbc5c6abfc21e60eaeb076e27ae0e9f6c668fd04;hb=7ffec52c590ce511b476f55be4ad123418268aa0;hp=73f1ffde37647b9465267ef4cec4316e6dcd17c5;hpb=80389feff3ab8e8743db4abfb6493285f72b24dd;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java index 73f1ffde3..cbc5c6abf 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/spring/SpringUtils.java @@ -1,6 +1,8 @@ package org.argeo.slc.spring; import java.io.IOException; +import java.net.URI; +import java.net.URL; import java.util.Map; import org.apache.commons.logging.Log; @@ -32,24 +34,20 @@ public class SpringUtils { if (urlStr.charAt(urlStr.length() - 1) == '/') urlStr = urlStr.substring(0, urlStr.length() - 2); - String parentUrlStr = urlStr.substring(0, urlStr.lastIndexOf('/')); + String parentUrlStr = urlStr.substring(0, urlStr.lastIndexOf('/')) + '/'; + URI uri = new URI(parentUrlStr).normalize(); return new DefaultResourceLoader(Thread.currentThread() - .getContextClassLoader()).getResource(parentUrlStr + '/'); - } catch (IOException e) { + .getContextClassLoader()).getResource(uri.toString()); + } catch (Exception e) { throw new SlcException("Cannot get parent for resource " + res, e); } } public static String extractRelativePath(Resource ancestor, Resource child) { try { - String childPath = child.getURL().getPath(); - String ancestorPath = ancestor.getURL().getPath(); - - if (log.isTraceEnabled()) - log.trace("extractRelativePath(): childPath=" + childPath - + ", ancestorPath=" + ancestorPath); - return childPath.substring(ancestorPath.length()); + return ancestor.getURI().relativize(child.getURI()).normalize() + .toString(); } catch (IOException e) { throw new SlcException("Cannot extract relative path of " + child + " based on " + ancestor, e);