jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1099866 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java json/DiffParser.java
Date Thu, 05 May 2011 16:35:05 GMT
Author: stefan
Date: Thu May  5 16:35:04 2011
New Revision: 1099866

URL: http://svn.apache.org/viewvc?rev=1099866&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/json/DiffParser.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=1099866&r1=1099865&r2=1099866&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
Thu May  5 16:35:04 2011
@@ -166,7 +166,7 @@ public class MicroKernelImpl implements 
                     public void propAdded(String nodePath, String propName, String value)
{
                         buf.append("+\"");
                         buf.append(PathUtil.concat(nodePath, propName));
-                        buf.append("\":\"");
+                        buf.append("\" : \"");
                         buf.append(value);
                         buf.append("\"\n");
                     }
@@ -174,7 +174,7 @@ public class MicroKernelImpl implements 
                     public void propChanged(String nodePath, String propName, String oldValue,
String newValue) {
                         buf.append("^\"");
                         buf.append(PathUtil.concat(nodePath, propName));
-                        buf.append("\":\"");
+                        buf.append("\" : \"");
                         buf.append(newValue);
                         buf.append("\"\n");
                     }
@@ -188,9 +188,9 @@ public class MicroKernelImpl implements 
                     public void childNodeAdded(String nodePath, String childName, String
id) {
                         buf.append("+\"");
                         buf.append(PathUtil.concat(nodePath, childName));
-                        buf.append("\":");
+                        buf.append("\" : ");
                         try {
-                            toJson(rep.getStore().getNode(id), childName, Integer.MAX_VALUE,
buf);
+                            toJson(rep.getStore().getNode(id), childName, Integer.MAX_VALUE,
false, buf);
                         } catch (Exception e) {
                             buf.append("\"ERROR: failed to retrieve node ");
                             buf.append(id);
@@ -240,7 +240,7 @@ public class MicroKernelImpl implements 
 
         try {
             StringBuilder buf = new StringBuilder();
-            toJson(rep.getNode(revisionId, path), PathUtil.getName(path), depth, buf);
+            toJson(rep.getNode(revisionId, path), PathUtil.getName(path), depth, true, buf);
             return buf.toString();
         } catch (Exception e) {
             throw new MicroKernelException(e);
@@ -265,7 +265,7 @@ public class MicroKernelImpl implements 
                 if (pos - offset >= count) {
                     break;
                 }
-                toJson(rep.getStore().getNode(entry.getValue()), entry.getKey(), depth, buf);
+                toJson(rep.getStore().getNode(entry.getValue()), entry.getKey(), depth, true,
buf);
                 buf.append(',');
                 pos++;
             }
@@ -315,10 +315,10 @@ public class MicroKernelImpl implements 
 
                 public void addNode(String nodeName, String jsonObject) throws Exception
{
                     Object obj = jsonParser.parse(jsonObject, containerFactory);
-                    if (!(obj instanceof JSONObject)) {
+                    if (!(obj instanceof Map)) {
                         throw new Exception("illegal json object format: " + jsonObject);
                     }
-                    JSONObject jsonNode = (JSONObject) obj;
+                    Map jsonNode = (Map) obj;
                     Map<String, String> props = new HashMap<String, String>();
 
                     for (Iterator it = jsonNode.entrySet().iterator(); it.hasNext(); ) {
@@ -386,9 +386,11 @@ public class MicroKernelImpl implements 
 
     //-------------------------------------------------------< implementation >
 
-    void toJson(Node node, String name, int depth, StringBuilder buf) throws Exception {
+    void toJson(Node node, String name, int depth, boolean metaProps, StringBuilder buf)
throws Exception {
         buf.append("{");
-        buf.append("\":name\":\"" + name + "\",");
+        if (metaProps) {
+            buf.append("\":name\":\"" + name + "\",");
+        }
         for (Map.Entry prop : node.getProperties().entrySet()) {
             buf.append('"');
             buf.append(prop.getKey());
@@ -397,10 +399,12 @@ public class MicroKernelImpl implements 
             buf.append("\",");
         }
 
-        buf.append("\":childNodeCount\":");
         long childCount = node.getChildNodeCount();
-        buf.append(childCount);
-        buf.append(",");
+        if (metaProps) {
+            buf.append("\":childNodeCount\":");
+            buf.append(childCount);
+            buf.append(",");
+        }
         if (childCount > 0 && depth > 0) {
             depth--;
             for (Map.Entry<String, String> child : node.getChildNodeEntries().entrySet())
{
@@ -409,7 +413,7 @@ public class MicroKernelImpl implements 
                 buf.append(childName);
                 buf.append("\":");
                 String childId = child.getValue();
-                toJson(rep.getStore().getNode(childId), childName, depth, buf);
+                toJson(rep.getStore().getNode(childId), childName, depth, metaProps, buf);
                 buf.append(',');
             }
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/DiffParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/DiffParser.java?rev=1099866&r1=1099865&r2=1099866&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/DiffParser.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/DiffParser.java
Thu May  5 16:35:04 2011
@@ -143,6 +143,17 @@ public class DiffParser {
                         // a sequence of 'wsp:wsp' indicates the delimiter between
                         // the target path and the diff value.
                         path = bf.substring(0, bf.lastIndexOf(":")).trim();
+
+                        // trim leading/trailing '"'
+                        int start = 0, end = path.length();
+                        if (path.startsWith("\"")) {
+                            start++;
+                        }
+                        if (path.endsWith("\"")) {
+                            end--;
+                        }
+                        path = path.substring(start, end);
+
                         state = STATE_START_VALUE;
                         // reset buffer
                         bf = null;



Mime
View raw message