jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1346396 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath: JcrNameParser.java JcrPathParser.java NamePathMapperImpl.java
Date Tue, 05 Jun 2012 14:26:31 GMT
Author: reschke
Date: Tue Jun  5 14:26:31 2012
New Revision: 1346396

URL: http://svn.apache.org/viewvc?rev=1346396&view=rev
Log:
OAK-61: handle names with their indices in a single call

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java?rev=1346396&r1=1346395&r2=1346396&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
Tue Jun  5 14:26:31 2012
@@ -53,8 +53,9 @@ public class JcrNameParser {
          *
          * @param name The resulting name upon successful completion of
          * {@link org.apache.jackrabbit.oak.namepath.JcrNameParser#parse(String, org.apache.jackrabbit.oak.namepath.JcrNameParser.Listener)}
+         * @param index the index (or {@code 0} when not specified)
          */
-        boolean name(String name);
+        boolean name(String name, int index);
     }
 
     /**
@@ -69,17 +70,19 @@ public class JcrNameParser {
      *
      * @param jcrName The jcr name to be parsed.
      * @param listener The listener to be informed about success or failure.
+     * @param index index, or {@code 0} when not specified
+     * @return whether parsing was successful
      */
-    public static void parse(String jcrName, Listener listener) {
+    public static boolean parse(String jcrName, Listener listener, int index) {
         // trivial check
         int len = jcrName == null ? 0 : jcrName.length();
         if (len == 0) {
             listener.error("Empty name");
-            return;
+            return false;
         }
         if (".".equals(jcrName) || "..".equals(jcrName)) {
             listener.error("Illegal name:" + jcrName);
-            return;
+            return false;
         }
 
         // parse the name
@@ -93,40 +96,40 @@ public class JcrNameParser {
             if (c == ':') {
                 if (state == STATE_PREFIX_START) {
                     listener.error("Prefix must not be empty");
-                    return;
+                    return false;
                 } else if (state == STATE_PREFIX) {
                     if (trailingSpaces) {
                         listener.error("Trailing spaces not allowed");
-                        return;
+                        return false;
                     }
                     prefix = jcrName.substring(0, i);
                     if (!XMLChar.isValidNCName(prefix)) {
                         listener.error("Invalid name prefix: "+ prefix);
-                        return;
+                        return false;
                     }
                     state = STATE_NAME_START;
                 } else if (state == STATE_URI) {
                     // ignore -> validation of uri later on.
                 } else {
                     listener.error("'" + c + "' not allowed in name");
-                    return;
+                    return false;
                 }
                 trailingSpaces = false;
             } else if (c == ' ') {
                 if (state == STATE_PREFIX_START || state == STATE_NAME_START) {
                     listener.error("'" + c + "' not valid name start");
-                    return;
+                    return false;
                 }
                 trailingSpaces = true;
             } else if (Character.isWhitespace(c) || c == '[' || c == ']' || c == '*' || c
== '|') {
                 listener.error("'" + c + "' not allowed in name");
-                return;
+                return false;
             } else if (c == '/') {
                 if (state == STATE_URI_START) {
                     state = STATE_URI;
                 } else if (state != STATE_URI) {
                     listener.error("'" + c + "' not allowed in name");
-                    return;
+                    return false;
                 }
                 trailingSpaces = false;
             } else if (c == '{') {
@@ -164,7 +167,7 @@ public class JcrNameParser {
                     } else {
                         listener.error("The URI prefix of the name " + jcrName + " is " +
                                 "neither a valid URI nor a valid part of a local name.");
-                        return;
+                        return false;
                     }
                 } else if (state == STATE_PREFIX_START) {
                     state = STATE_PREFIX; // prefix start -> validation later on will
fail.
@@ -190,19 +193,19 @@ public class JcrNameParser {
         // a terminating '}' -> make sure there are no illegal characters present.
         if (state == STATE_URI && (jcrName.indexOf(':') > -1 || jcrName.indexOf('/')
> -1)) {
             listener.error("Local name may not contain ':' nor '/'");
-            return;
+            return false;
         }
 
         if (nameStart == len || state == STATE_NAME_START) {
             listener.error("Local name must not be empty");
-            return;
+            return false;
         }
         if (trailingSpaces) {
             listener.error("Trailing spaces not allowed");
-            return;
+            return false;
         }
 
-        listener.name(jcrName);
+        return listener.name(jcrName, index);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java?rev=1346396&r1=1346395&r2=1346396&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
Tue Jun  5 14:26:31 2012
@@ -39,7 +39,6 @@ public class JcrPathParser {
         boolean root();
         boolean current();
         boolean parent();
-        boolean index(int index);
     }
 
     public static void parse(String jcrPath, Listener listener) {
@@ -106,8 +105,7 @@ public class JcrPathParser {
                             name = jcrPath.substring(lastPos, pos - 1);
                         }
 
-                        JcrNameParser.parse(name, listener);
-                        if (!listener.index(index)) {
+                        if (!JcrNameParser.parse(name, listener, index)) {
                             return;
                         }
                         state = STATE_PREFIX_START;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1346396&r1=1346395&r2=1346396&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Tue Jun  5 14:26:31 2012
@@ -96,21 +96,16 @@ public class NamePathMapperImpl implemen
             }
 
             @Override
-            public boolean index(int index) {
-                if (index > 1) {
-                    parseErrors.append("index > 1");
-                    return false;
-                }
-                return true;
-            }
-
-            @Override
             public void error(String message) {
                 parseErrors.append(message);
             }
 
             @Override
-            public boolean name(String name) {
+            public boolean name(String name, int index) {
+                if (index > 1) {
+                    parseErrors.append("index > 1");
+                    return false;
+                }
                 String p = nameMapper.getOakName(name);
                 if (p == null) {
                     parseErrors.append("Invalid name: ").append(name);
@@ -187,20 +182,15 @@ public class NamePathMapperImpl implemen
             }
 
             @Override
-            public boolean index(int index) {
-                if (index > 1) {
-                    throw new IllegalArgumentException("index > 1");
-                }
-                return true;
-            }
-
-            @Override
             public void error(String message) {
                 throw new IllegalArgumentException(message);
             }
 
             @Override
-            public boolean name(String name) {
+            public boolean name(String name, int index) {
+                if (index > 1) {
+                    throw new IllegalArgumentException("index > 1");
+                }
                 String p = nameMapper.getJcrName(name);
                 elements.add(p);
                 return true;



Mime
View raw message