jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1097879 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java Repository.java
Date Fri, 29 Apr 2011 16:43:02 GMT
Author: stefan
Date: Fri Apr 29 16:43:02 2011
New Revision: 1097879

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

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1097879&r1=1097878&r2=1097879&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Fri Apr 29 16:43:02 2011
@@ -105,16 +105,16 @@ public class MicroKernelImpl implements 
         StringBuilder buf = new StringBuilder();
         buf.append("[");
         for (Commit commit : history) {
-            if (buf.charAt(buf.length() - 1) != '[') {
-                buf.append(",{");
-            } else {
-                buf.append("{");
-            }
+            buf.append("{");
             buf.append("\"id\":\"");
             buf.append(commit.getId());
             buf.append("\",\"ts\":\"");
             buf.append(commit.getCommitTS());
-            buf.append("\"}");
+            buf.append("\"},");
+        }
+        // trim redundant trailing comma
+        if (buf.charAt(buf.length() - 1) == ',') {
+            buf.deleteCharAt(buf.length() - 1);
         }
         buf.append("]");
         return buf.toString();
@@ -173,13 +173,17 @@ public class MicroKernelImpl implements 
                     pos++;
                     continue;
                 }
-                if (pos - offset > count) {
+                if (pos - offset >= count) {
                     break;
                 }
                 toJson(rep.getStore().getNode(entry.getValue()), entry.getKey(), depth, buf);
                 buf.append(',');
                 pos++;
             }
+            // trim redundant trailing comma
+            if (buf.charAt(buf.length() - 1) == ',') {
+                buf.deleteCharAt(buf.length() - 1);
+            }
             buf.append(']');
             return buf.toString();
         } catch (Exception e) {
@@ -301,16 +305,15 @@ public class MicroKernelImpl implements 
             buf.append(prop.getKey());
             buf.append("\":\"");
             buf.append(prop.getValue());
-            buf.append("\"");
+            buf.append("\",");
         }
 
-        buf.append("\":childNodeCount\":\"");
+        buf.append("\":childNodeCount\":");
         long childCount = node.getChildNodeCount();
         buf.append(childCount);
-        buf.append("\"");
+        buf.append(",");
         if (childCount > 0 && depth > 0) {
             depth--;
-            buf.append(',');
             for (Map.Entry<String, String> child : node.getChildNodeEntries().entrySet())
{
                 buf.append('"');
                 String childName = child.getKey();
@@ -318,8 +321,13 @@ public class MicroKernelImpl implements 
                 buf.append("\":");
                 String childId = child.getValue();
                 toJson(rep.getStore().getNode(childId), childName, depth, buf);
+                buf.append(',');
             }
         }
+        // trim redundant trailing comma
+        if (buf.charAt(buf.length() - 1) == ',') {
+            buf.deleteCharAt(buf.length() - 1);
+        }
         buf.append("}");
     }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1097879&r1=1097878&r2=1097879&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
Fri Apr 29 16:43:02 2011
@@ -110,16 +110,19 @@ public class Repository {
 
         Commit commit = store.getCommit(revId);
 
-        String[] names = path.split("/");
+        if (path.equals("/")) {
+            return new String[] { commit.getRootNodeId() };
+        }
+        String[] names = path.substring(1).split("/");
         String[] ids = new String[names.length + 1];
 
         // get root node
         ids[0] = commit.getRootNodeId();
         Node parent = store.getNode(ids[0]);
         // traverse path and store id of each element
-        for (int i = 1; i <= names.length; i++) {
-            ids[i] = parent.getChildNodeEntries().get(names[i]);
-            parent = store.getNode(ids[i]);
+        for (int i = 0; i < names.length; i++) {
+            ids[i + 1] = parent.getChildNodeEntries().get(names[i]);
+            parent = store.getNode(ids[i + 1]);
         }
         return ids;
     }



Mime
View raw message