jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1132927 - /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtil.java
Date Tue, 07 Jun 2011 09:41:57 GMT
Author: mduerig
Date: Tue Jun  7 09:41:56 2011
New Revision: 1132927

URL: http://svn.apache.org/viewvc?rev=1132927&view=rev
Log:
MicroKernel prototype (WIP)
adding relativize method as inverse of concat method

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtil.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtil.java?rev=1132927&r1=1132926&r2=1132927&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtil.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtil.java
Tue Jun  7 09:41:56 2011
@@ -72,4 +72,20 @@ public class PathUtil {
         buf.append(nameOrRelativePath);
         return buf.toString();
     }
+
+    /**
+     * <code>relativize(path1, concat(path1, path2)) == path2</code>
+     */
+    public static String relativize(String parentPath, String path) {
+        String prefix = parentPath.charAt(parentPath.length() - 1) == '/'
+            ? parentPath
+            : parentPath + '/';
+
+        if (path.startsWith(prefix)) {
+            return path.substring(prefix.length());
+        }
+        else {
+            throw new IllegalAccessError("Cannot relativize " + path + " wrt. " + parentPath);
+        }
+    }
 }



Mime
View raw message