jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1133738 - 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/
Date Thu, 09 Jun 2011 09:25:00 GMT
Author: thomasm
Date: Thu Jun  9 09:24:59 2011
New Revision: 1133738

URL: http://svn.apache.org/viewvc?rev=1133738&view=rev
Log:
Support arrays.

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
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.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=1133738&r1=1133737&r2=1133738&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 Jun  9 09:24:59 2011
@@ -20,6 +20,8 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.DiffHandler;
 import org.apache.jackrabbit.mk.json.DiffParser;
+import org.apache.jackrabbit.mk.mem.JsopBuilder;
+import org.apache.jackrabbit.mk.mem.JsopTokenizer;
 import org.apache.jackrabbit.mk.store.Commit;
 import org.apache.jackrabbit.mk.store.CommitBuilder;
 import org.apache.jackrabbit.mk.store.Node;
@@ -403,9 +405,9 @@ public class MicroKernelImpl implements 
         for (Map.Entry prop : node.getProperties().entrySet()) {
             buf.append('"');
             buf.append(prop.getKey());
-            buf.append("\":\"");
+            buf.append("\":");
             buf.append(prop.getValue());
-            buf.append("\",");
+            buf.append(",");
         }
 
         long childCount = node.getChildNodeCount();
@@ -443,7 +445,11 @@ public class MicroKernelImpl implements 
         for (Iterator it = jsonNode.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             if (! (entry.getValue() instanceof JSONObject)) {
-                props.put((String) entry.getKey(), entry.getValue().toString());
+                Object o = entry.getValue();
+                if (o instanceof String) {
+                    o = JsopTokenizer.encode(o.toString());
+                }
+                props.put((String) entry.getKey(), o.toString());
             }
         }
         cb.addNode(path, name, props);
@@ -458,5 +464,15 @@ public class MicroKernelImpl implements 
 
     //--------------------------------------------------------< inner classes >
     static class JSONObject extends LinkedHashMap<String, Object>{};
-    static class JSONArray extends LinkedList{};
+    static class JSONArray extends LinkedList {
+        public String toString() {
+            JsopBuilder buff = new JsopBuilder();
+            buff.beginArray();
+            for (Object o : this) {
+                buff.addValue(JsopTokenizer.encode(o.toString()));
+            }
+            buff.endArray();
+            return buff.toString();
+        }
+    }
 }

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=1133738&r1=1133737&r2=1133738&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 Jun  9 09:24:59 2011
@@ -22,6 +22,7 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import org.apache.jackrabbit.mk.mem.JsopTokenizer;
 
 /** <code>DiffParser</code>...
  *
@@ -230,8 +231,8 @@ public class DiffParser {
                 handler.addNode(path, value);
                 break;
             case SYMBOL_SET_PROPERTY:
-                // handler.setProperty(path, JsopTokenizer.encode(value));
-                handler.setProperty(path, value);
+                handler.setProperty(path, JsopTokenizer.encode(value));
+                // handler.setProperty(path, value);
                 break;
             case SYMBOL_MOVE:
                 handler.move(path, value);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java?rev=1133738&r1=1133737&r2=1133738&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
Thu Jun  9 09:24:59 2011
@@ -24,17 +24,36 @@ public class JsopBuilder {
     private BitSet commas = new BitSet();
     private int level;
 
-    void beginObject() {
+    public void beginObject() {
         buff.append('{');
         commas.clear(level++);
     }
 
-    void endObject() {
+    public void endObject() {
         buff.append("\n}");
         commas.clear(level--);
     }
 
-    void addProperty(String propertyName, String encodedValue) {
+    public void beginArray() {
+        buff.append('[');
+        commas.clear(level++);
+    }
+
+    public void endArray() {
+        buff.append("]");
+        commas.clear(level--);
+    }
+
+    public void addValue(String encodedValue) {
+        if (commas.get(level)) {
+            buff.append(',');
+        } else {
+            commas.set(level);
+        }
+        buff.append(encodedValue);
+    }
+
+    public void addProperty(String propertyName, String encodedValue) {
         if (commas.get(level)) {
             buff.append(',');
         } else {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java?rev=1133738&r1=1133737&r2=1133738&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java
Thu Jun  9 09:24:59 2011
@@ -25,7 +25,7 @@ public class HelloWorld {
 
     public static void main(String... args) {
         test("mem:");
-        // test("fs:{homeDir};clean");
+        test("fs:{homeDir};clean");
     }
 
     private static void test(String url) {
@@ -42,7 +42,7 @@ public class HelloWorld {
             head = mk.commit("/", "-\"test\"", head);
         }
         // head = mk.commit(null, "+\"/test\" : {\"name\":\"hello\"}", head);
-        head = mk.commit("/", "+\"test\" : {\"name\":\"hello\"}", head);
+        head = mk.commit("/", "+\"test\" : {\"text\":[\"hello\", \"world\"]}", head);
 
         // head = mk.getHeadRevision();
         String s = mk.getNodes("/test", 0, head);
@@ -50,10 +50,11 @@ public class HelloWorld {
 
         System.out.println(s);
 
-        head = mk.commit("/", "- \"test\"", head);
+        head = mk.commit("/", "-\"test\"", head);
         s = mk.getNodes("/", 0, head);
         System.out.println(s);
 
         mk.dispose();
     }
+
 }



Mime
View raw message