jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1138509 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java test/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/util/PathsTest.java
Date Wed, 22 Jun 2011 15:41:40 GMT
Author: mduerig
Date: Wed Jun 22 15:41:39 2011
New Revision: 1138509

URL: http://svn.apache.org/viewvc?rev=1138509&view=rev
Log:
spi2microkernel prototype (WIP)

Added:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/PathsTest.java
Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java?rev=1138509&r1=1138508&r2=1138509&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
Wed Jun 22 15:41:39 2011
@@ -19,21 +19,27 @@
 
 package org.apache.jackrabbit.spi2microkernel.util;
 
+import org.apache.jackrabbit.mk.util.PathUtils;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Path.Element;
+import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.RepositoryException;
+import java.util.LinkedList;
 
-import static org.apache.jackrabbit.spi.Name.*;
+import static org.apache.jackrabbit.spi.Name.NS_DEFAULT_URI;
 
 public final class Paths {
     public static final String DEFAULT_WORKSPACE = "default";
     public static final String SYSTEM_WORKSPACE = "system";
 
     private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
+    private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
 
     private Paths() {}
 
@@ -53,6 +59,23 @@ public final class Paths {
         }
     }
 
+    public static Path stringToPath(String path) {
+        LinkedList<Element> elements = new LinkedList<Element>();
+        boolean absolute = PathUtils.isAbsolute(path);
+
+        while (!PathUtils.denotesRoot(path)) {
+            String name = PathUtils.getName(path);
+            elements.addFirst(PATH_FACTORY.createElement(stringToName(name)));
+            path = PathUtils.getParentPath(path);
+        }
+
+        if (absolute) {
+            elements.addFirst(PATH_FACTORY.getRootElement());
+        }
+
+        return PATH_FACTORY.create(elements.toArray(new Element[elements.size()]));
+    }
+
     public static String nameToString(Name name) {
         String nameSpaceURI = name.getNamespaceURI();
         return '{' + escapeNameSpaceURI(nameSpaceURI) + '}' + name.getLocalName();

Added: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/PathsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/PathsTest.java?rev=1138509&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/PathsTest.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/PathsTest.java
Wed Jun 22 15:41:39 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.apache.jackrabbit.spi.Path;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class PathsTest {
+
+    @Test
+    public void stringToPath() {
+        Path p = Paths.stringToPath("/foo/bar");
+        Assert.assertEquals("{}\t{}foo\t{}bar", p.toString());
+
+        p = Paths.stringToPath("foo/bar");
+        Assert.assertEquals("{}foo\t{}bar", p.toString());
+
+        p = Paths.stringToPath("/foo");
+        Assert.assertEquals("{}\t{}foo", p.toString());
+
+        p = Paths.stringToPath("foo");
+        Assert.assertEquals("{}foo", p.toString());
+
+        p = Paths.stringToPath("/");
+        Assert.assertEquals("{}", p.toString());
+    }
+
+    @Ignore  // fixme fix in microkernel
+    @Test
+    public void fixInMicrokernel() {
+        Path p = Paths.stringToPath("/foo/");
+        Assert.assertEquals("{}\t{}foo", p.toString());
+    }
+
+    @Ignore  // fixme fix in microkernel
+    @Test
+    public void fixInMicrokernel2() {
+        Path p = Paths.stringToPath("/foo//");
+    }
+}



Mime
View raw message