jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1330817 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/namepath/Paths.java test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
Date Thu, 26 Apr 2012 12:49:27 GMT
Author: angela
Date: Thu Apr 26 12:49:27 2012
New Revision: 1330817

URL: http://svn.apache.org/viewvc?rev=1330817&view=rev
Log:
OAK-61 : Implement JCR path handling

- remove unused methods on Paths.java

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java?rev=1330817&r1=1330816&r2=1330817&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
Thu Apr 26 12:49:27 2012
@@ -109,85 +109,6 @@ public final class Paths {
         return PathUtils.getDepth(path);
     }
 
-    /**
-     * Get the prefix of an element. Undefined if {@code element} is
-     * not an {@code ELEMENT}.
-     * @param element
-     * @return  the {@code PREFIX} of {@code element} or {@code null} if none
-     */
-    public static String getPrefixFromElement(String element) {
-        int pos = element.indexOf(':');
-        if (pos == -1) {
-            return null;
-        }
-        else {
-            return element.substring(0, pos);
-        }
-    }
-
-    /**
-     * Get the name of an element. Undefined if {@code element} is
-     * not an {@code ELEMENT}.
-     * @param element
-     * @return  the {@code NAME} of {@code element}
-     */
-    public static String getNameFromElement(String element) {
-        int pos = element.indexOf(':');
-        if (pos == -1) {
-            return element;
-        }
-        else {
-            return element.substring(pos + 1);
-        }
-    }
-
-    /**
-     * Determine whether {@code string} is a valid {@code ELEMENT}.
-     * @param string
-     * @return  {@code true} iff {@code string} is a valid {@code ELEMENT}.
-     */
-    public static boolean isValidElement(String string) {
-        if (string.isEmpty()) {
-            return false;
-        }
-
-        int colons = 0;
-        int pos = -1;
-        for (int k = 0; k < string.length(); k++) {
-            if (string.charAt(k) == ':') {
-                colons += 1;
-                pos = k;
-            }
-            else if (string.charAt(k) == '/') {
-                return false;
-            }
-        }
-
-        return colons <= 1 && (pos != 0 && pos != string.length() - 1);
-    }
-
-    /**
-     * Determine whether {@code string} is a valid {@code PATH}.
-     * @param string
-     * @return  {@code true} iff {@code string} is a valid {@code PATH}.
-     */
-    public static boolean isValidPath(String string) {
-        if (string.isEmpty()) {
-            return false;
-        }
-        if (string.length() > 1 && string.endsWith("/")) {
-            return false;
-        }
-
-        for (String part : split(string, '/')) {
-            if (!isValidElement(part)) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
     public static String toOakName(String name, final NameMapper mapper) {
         final StringBuilder element = new StringBuilder();
         
@@ -217,6 +138,9 @@ public final class Paths {
         }
 
         JcrPathParser.Listener listener = new JcrPathParser.Listener() {
+
+            // TODO: replace RuntimeException by something that oak-jcr can deal with (e.g.
ValueFactory)
+
             @Override
             public void root() {
                 if (!elements.isEmpty()) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java?rev=1330817&r1=1330816&r2=1330817&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/PathsTest.java
Thu Apr 26 12:49:27 2012
@@ -16,69 +16,41 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import org.junit.Test;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 public class PathsTest {
 
     private TestNameMapper mapper = new TestNameMapper();
 
     @Test
-    public void getPrefix() {
-        assertEquals(null, Paths.getPrefixFromElement("foo"));
-        assertEquals("foo", Paths.getPrefixFromElement("foo:bar"));
-    }
-
-    @Test
-    public void getName() {
-        assertEquals("foo", Paths.getNameFromElement("foo"));
-        assertEquals("bar", Paths.getNameFromElement("foo:bar"));
+    public void testValidIdentifierPath() {
+        String idPath = '[' + UUID.randomUUID().toString()+ ']';
+        Paths.toOakPath(idPath, mapper);
     }
 
     @Test
-    public void isValidElement() {
-        assertTrue(Paths.isValidElement("foo"));
-        assertTrue(Paths.isValidElement("foo:bar"));
-
-        assertFalse(Paths.isValidElement(""));
-        assertFalse(Paths.isValidElement(":"));
-        assertFalse(Paths.isValidElement("foo:"));
-        assertFalse(Paths.isValidElement("fo/o:"));
-        assertFalse(Paths.isValidElement(":bar"));
-    }
-
-    @Test
-    public void isValidAbsolutePath() {
-        assertTrue(Paths.isValidPath("/"));
-        assertTrue(Paths.isValidPath("/a/b/c"));
-        assertTrue(Paths.isValidPath("/p:a/q:b/r:c"));
-
-        assertFalse(Paths.isValidPath(""));
-        assertFalse(Paths.isValidPath("/a/b/c/"));
-        assertFalse(Paths.isValidPath("/p:a/:b/r:c"));
-        assertFalse(Paths.isValidPath("/p:a/q:/r:c"));
-        assertFalse(Paths.isValidPath("/p:a/:/r:c"));
-        assertFalse(Paths.isValidPath("/p:a//r:c"));
-        assertFalse(Paths.isValidPath("//"));
-    }
-
-    @Test
-    public void isValidRelativePath() {
-        assertTrue(Paths.isValidPath("a/b/c"));
-        assertTrue(Paths.isValidPath("p:a/q:b/r:c"));
-
-        assertFalse(Paths.isValidPath("a/b/c/"));
-        assertFalse(Paths.isValidPath("p:a/:b/r:c"));
-        assertFalse(Paths.isValidPath("p:a/q:/r:c"));
-        assertFalse(Paths.isValidPath("p:a/:/r:c"));
-        assertFalse(Paths.isValidPath("p:a//r:c"));
+    public void testInvalidIdentifierPath() {
+        List<String> invalid = new ArrayList();
+        invalid.add('[' + UUID.randomUUID().toString()+ "]abc");
+        invalid.add('[' + UUID.randomUUID().toString()+ "]/a/b/c");
+
+        for (String jcrPath : invalid) {
+            try {
+                Paths.toOakPath(jcrPath, mapper);
+                fail("Invalid identifier path");
+            } catch (Exception e) {
+                // success
+            }
+        }
     }
 
     @Test
@@ -102,15 +74,13 @@ public class PathsTest {
         assertEquals("jcr-foo:bar", Paths.toJcrPath("foo:bar", mapper));
 
         try {
-            Paths.toJcrPath("{http://www.jcp.org/jcr/nt/1.0}unstructured",
-                    mapper);
+            Paths.toJcrPath("{http://www.jcp.org/jcr/nt/1.0}unstructured", mapper);
             fail("expanded name should not be accepted");
         } catch (IllegalStateException expected) {
         }
 
         try {
-            Paths.toJcrPath("foobar/{http://www.jcp.org/jcr/1.0}content",
-                    mapper);
+            Paths.toJcrPath("foobar/{http://www.jcp.org/jcr/1.0}content", mapper);
             fail("expanded name should not be accepted");
         } catch (IllegalStateException expected) {
         }



Mime
View raw message