jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1361282 - /jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Date Fri, 13 Jul 2012 16:20:42 GMT
Author: jukka
Date: Fri Jul 13 16:20:42 2012
New Revision: 1361282

URL: http://svn.apache.org/viewvc?rev=1361282&view=rev
Log:
OAK-188: Invalid JSOP encoding in CommitBuilder

Use JsopBuilder instead of StringBuilder to generate JSOP

Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java?rev=1361282&r1=1361281&r2=1361282&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Fri Jul 13 16:20:42 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.model.tree.DiffBuilder;
 import org.apache.jackrabbit.mk.model.tree.NodeDelta;
 import org.apache.jackrabbit.mk.store.NotFoundException;
@@ -448,26 +449,20 @@ public class CommitBuilder {
         public Map<String, String> props = new HashMap<String, String>();
         public Map<String, NodeTree> nodes = new HashMap<String, NodeTree>();
 
-        void toJson(StringBuilder buf) {
+        void toJson(JsopBuilder buf) {
             toJson(buf, this);
         }
 
-        private static void toJson(StringBuilder buf, NodeTree node) {
-            buf.append('{');
+        private static void toJson(JsopBuilder buf, NodeTree node) {
+            buf.object();
             for (String name : node.props.keySet()) {
-                if (buf.charAt(buf.length() - 1) != '{')  {
-                    buf.append(',');
-                }
-                buf.append('"').append(name).append("\":").append(node.props.get(name));
+                buf.key(name).encodedValue(node.props.get(name));
             }
             for (String name : node.nodes.keySet()) {
-                if (buf.charAt(buf.length() - 1) != '{')  {
-                    buf.append(',');
-                }
-                buf.append('"').append(name).append("\":");
+                buf.key(name);
                 toJson(buf, node.nodes.get(name));
             }
-            buf.append('}');
+            buf.endObject();
         }
     }
 
@@ -494,8 +489,8 @@ public class CommitBuilder {
 
         @Override
         String asDiff() {
-            StringBuilder diff = new StringBuilder("+");
-            diff.append('"').append(PathUtils.concat(parentNodePath, nodeName)).append("\":");
+            JsopBuilder diff = new JsopBuilder();
+            diff.tag('+').key(PathUtils.concat(parentNodePath, nodeName));
             node.toJson(diff);
             return diff.toString();
         }
@@ -542,8 +537,8 @@ public class CommitBuilder {
 
         @Override
         String asDiff() {
-            StringBuilder diff = new StringBuilder("-");
-            diff.append('"').append(nodePath).append('"');
+            JsopBuilder diff = new JsopBuilder();
+            diff.tag('-').value(nodePath);
             return diff.toString();
         }
     }
@@ -596,8 +591,8 @@ public class CommitBuilder {
 
         @Override
         String asDiff() {
-            StringBuilder diff = new StringBuilder(">");
-            diff.append('"').append(srcPath).append("\":\"").append(destPath).append('"');
+            JsopBuilder diff = new JsopBuilder();
+            diff.tag('>').key(srcPath).value(destPath);
             return diff.toString();
         }
     }
@@ -639,10 +634,11 @@ public class CommitBuilder {
 
         @Override
         String asDiff() {
-            StringBuilder diff = new StringBuilder("*");
-            diff.append('"').append(srcPath).append("\":\"").append(destPath).append('"');
+            JsopBuilder diff = new JsopBuilder();
+            diff.tag('*').key(srcPath).value(destPath);
             return diff.toString();
         }
+
     }
 
     class SetProperty extends Change {
@@ -670,9 +666,15 @@ public class CommitBuilder {
 
         @Override
         String asDiff() {
-            StringBuilder diff = new StringBuilder("^");
-            diff.append('"').append(PathUtils.concat(nodePath, propName)).append("\":").append(propValue);
+            JsopBuilder diff = new JsopBuilder();
+            diff.tag('^').key(PathUtils.concat(nodePath, propName));
+            if (propValue != null) {
+                diff.encodedValue(propValue);
+            } else {
+                diff.value(null);
+            }
             return diff.toString();
         }
     }
+
 }



Mime
View raw message