jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1153163 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/json/ main/java/org/apache/jackrabbit/mk/mem/ test/java/org/apache/jackrabbit/mk/ test/java/org/apache/jackrabbit/mk/j...
Date Tue, 02 Aug 2011 15:20:36 GMT
Author: thomasm
Date: Tue Aug  2 15:20:17 2011
New Revision: 1153163

URL: http://svn.apache.org/viewvc?rev=1153163&view=rev
Log:
JsopBuilder.append broke existing code - create a new appendWhitespace to avoid problems.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.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=1153163&r1=1153162&r2=1153163&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
Tue Aug  2 15:20:17 2011
@@ -162,14 +162,14 @@ public class MicroKernelImpl implements 
                         buff.append("+ ").
                             key(PathUtils.concat(nodePath, propName)).
                             encodedValue(value).
-                            append("\n");
+                            appendWhitespace("\n");
                     }
 
                     public void propChanged(String nodePath, String propName, String oldValue,
String newValue) {
                         buff.append("^ ").
                             key(PathUtils.concat(nodePath, propName)).
                             encodedValue(newValue).
-                            append("\n");
+                            appendWhitespace("\n");
                     }
 
                     public void propDeleted(String nodePath, String propName, String value)
{
@@ -179,7 +179,7 @@ public class MicroKernelImpl implements 
                         buff.append("^ ").
                             key(PathUtils.concat(nodePath, propName)).
                             encodedValue("null").
-                            append("\n");
+                            appendWhitespace("\n");
                     }
 
                     public void childNodeAdded(String nodePath, String childName, String
id) {
@@ -190,13 +190,13 @@ public class MicroKernelImpl implements 
                         } catch (Exception e) {
                             buff.value("ERROR: failed to retrieve node " + id);
                         }
-                        buff.endObject().append("\n");
+                        buff.endObject().appendWhitespace("\n");
                     }
 
                     public void childNodeDeleted(String nodePath, String childName, String
id) {
                         buff.append("- ");
                         buff.value(PathUtils.concat(nodePath, childName));
-                        buff.append("\n");
+                        buff.appendWhitespace("\n");
                     }
 
                     public void childNodeChanged(String nodePath, String childName, String
oldId, String newId) {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java?rev=1153163&r1=1153162&r2=1153163&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
Tue Aug  2 15:20:17 2011
@@ -30,13 +30,27 @@ public class JsopBuilder {
     private boolean needComma;
 
     /**
-     * Append an already formatted string, comment, or whitespace.
+     * Append an already formatted string. This will reset the comma flag, so no
+     * comma is added before the next key or value.
      *
      * @param string the string to append
      * @return this
      */
     public JsopBuilder append(String string) {
         buff.append(string);
+        needComma = false;
+        return this;
+    }
+
+    /**
+     * Append an already formatted comment or whitespace. The comma flag is not
+     * changed.
+     *
+     * @param string the string to append
+     * @return this
+     */
+    public JsopBuilder appendWhitespace(String string) {
+        buff.append(string);
         return this;
     }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1153163&r1=1153162&r2=1153163&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Tue Aug  2 15:20:17 2011
@@ -110,13 +110,13 @@ public class MemoryKernelImpl implements
                 t.read('{');
                 NodeImpl n = NodeImpl.parse(t, headRevId);
                 headRoot = headRoot.cloneAndAddChildNode(PathUtils.concat(fromRoot, path),
false, null, n, headRevId);
-                w.append(n.toString()).append("\n");
+                w.append(n.toString()).appendWhitespace("\n");
                 break;
             case '-':
                 path = t.readString();
                 w.append("- ").key(PathUtils.concat(rootPath, path));
                 headRoot = headRoot.cloneAndRemoveChildNode(PathUtils.concat(fromRoot, path),
headRevId);
-                w.append("\n");
+                w.appendWhitespace("\n");
                 break;
             case '^':
                 path = t.readString();
@@ -138,7 +138,7 @@ public class MemoryKernelImpl implements
                     w.append(value);
                 }
                 headRoot = headRoot.cloneAndSetProperty(PathUtils.concat(fromRoot, path),
value, headRevId);
-                w.append("\n");
+                w.appendWhitespace("\n");
                 break;
             case '>':
                 path = t.readString();
@@ -172,7 +172,7 @@ public class MemoryKernelImpl implements
                         w.value(PathUtils.concat(rootPath, target));
                     }
                 }
-                w.append("\n");
+                w.appendWhitespace("\n");
                 boolean before = false;
                 if ("last".equals(position)) {
                     target = PathUtils.concat(target, name);
@@ -256,7 +256,7 @@ public class MemoryKernelImpl implements
     public String getJournal(String fromRevisionId, String toRevisionId) {
         long fromRevId = parseRevisionId(fromRevisionId);
         long toRevId = parseRevisionId(toRevisionId);
-        JsopBuilder buff = new JsopBuilder().array().append("\n");
+        JsopBuilder buff = new JsopBuilder().array().appendWhitespace("\n");
         SortedMap<Long, Revision> map = revisions.subMap(fromRevId, true, toRevId,
true);
         for (Revision rev : map.values()) {
             buff.object().
@@ -264,7 +264,7 @@ public class MemoryKernelImpl implements
                 key("ts").value(rev.getTime()).
                 key("msg").value(rev.getMsg()).
                 key("changes").value(rev.getDiff()).
-            endObject().append("\n");
+            endObject().appendWhitespace("\n");
         }
         return buff.endArray().toString();
     }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java?rev=1153163&r1=1153162&r2=1153163&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Tue Aug  2 15:20:17 2011
@@ -237,7 +237,6 @@ public class MoveNodeTest extends TestCa
             isNew = true;
             t.read('}');
         } while (t.matches(','));
-        System.out.println();
         journalRevision = head;
         return buff.toString();
     }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java?rev=1153163&r1=1153162&r2=1153163&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
Tue Aug  2 15:20:17 2011
@@ -233,11 +233,24 @@ public class JsopTest extends TestCase {
 
         buff = new JsopBuilder();
         buff.array().
-            object().key("x").value("1").endObject().append("\n").
-            object().key("y").value("2").endObject().append("\n").
+            object().key("x").value("1").endObject().appendWhitespace("\n").
+            object().key("y").value("2").endObject().appendWhitespace("\n").
             endArray();
         json = buff.toString();
         assertEquals("[{\"x\":\"1\"}\n,{\"y\":\"2\"}\n]", json);
+
+        buff = new JsopBuilder();
+        buff.append("+ ").key("x").value("1").appendWhitespace("\n");
+        buff.append("+ ").key("y").value("2").appendWhitespace("\n");
+        json = buff.toString();
+        assertEquals("+ \"x\":\"1\"\n+ \"y\":\"2\"\n", json);
+
+        buff = new JsopBuilder();
+        buff.appendWhitespace("+ ").key("x").value("1").appendWhitespace("\n");
+        buff.appendWhitespace("+ ").key("y").value("2").appendWhitespace("\n");
+        json = buff.toString();
+        assertEquals("+ \"x\":\"1\"\n+ ,\"y\":\"2\"\n", json);
+
     }
 
     public void testEscape() throws IOException {



Mime
View raw message