jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1128354 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Fri, 27 May 2011 15:16:29 GMT
Author: mduerig
Date: Fri May 27 15:16:29 2011
New Revision: 1128354

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

Added:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonHandlerBase.java
Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1128354&r1=1128353&r2=1128354&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri May 27 15:16:29 2011
@@ -38,18 +38,24 @@ import org.apache.jackrabbit.spi.Session
 import org.apache.jackrabbit.spi.commons.AbstractRepositoryService;
 import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
 import org.apache.jackrabbit.spi2microkernel.util.Json;
+import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
 import org.apache.jackrabbit.spi2microkernel.util.NodeTypes;
 import org.apache.jackrabbit.spi2microkernel.util.Paths;
 import org.apache.jackrabbit.spi2microkernel.util.Values;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
 
 import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 public class RepositoryServiceImpl extends AbstractRepositoryService {
@@ -118,8 +124,32 @@ public class RepositoryServiceImpl exten
         String json = microKernel.getNodes("/", 0, rev);
 
         // Names of first level nodes correspond to workspace names
+        final List<String> workspaces = new ArrayList<String>();
 
-        return new String[0]; // todo implement getWorkspaceNames
+        try {
+            new JSONParser().parse(json, new JsonHandlerBase(){
+                public String currentKey;
+
+                @Override
+                public boolean startObject() throws ParseException, IOException {
+                    if (currentKey != null) {
+                        workspaces.add(currentKey);
+                    }
+                    return true;
+                }
+
+                @Override
+                public boolean startObjectEntry(String key) throws ParseException, IOException
{
+                    currentKey = key;
+                    return true;
+                }
+            });
+        }
+        catch (ParseException e) {
+            throw new RepositoryException(e.getMessage(), e );
+        }
+
+        return workspaces.toArray(new String[workspaces.size()]);
     }
 
     @Override

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java?rev=1128354&r1=1128353&r2=1128354&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Json.java
Fri May 27 15:16:29 2011
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.Listener;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.PropertyInfoBuilder;
-import org.json.simple.parser.ContentHandler;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
@@ -141,7 +140,7 @@ public final class Json {
         return path.denotesRoot() ? null : path.getAncestor(1);
     }
     
-    private static class JsonHandler implements ContentHandler {
+    private static class JsonHandler extends JsonHandlerBase {
         private final Path parent;
         private final InfoListener infoListener;
 
@@ -154,10 +153,7 @@ public final class Json {
             this.parent = parent;
         }
 
-        public void startJSON() throws ParseException, IOException {}
-
-        public void endJSON() throws ParseException, IOException {}
-
+        @Override
         public boolean startObject() throws ParseException, IOException {
             if (nodeInfoBuilder == null) {
                 nodeInfoBuilder = ItemInfoBuilder.nodeInfoBuilder(infoListener);
@@ -171,6 +167,7 @@ public final class Json {
             return !infoListener.done();
         }
 
+        @Override
         public boolean endObject() throws ParseException, IOException {
             try {
                 nodeInfoBuilder = isObjectEmpty
@@ -185,17 +182,20 @@ public final class Json {
             }
         }
 
+        @Override
         public boolean startObjectEntry(String key) throws ParseException, IOException {
             isObjectEmpty = false;
             currentKey = key;
             return !infoListener.done();
         }
 
+        @Override
         public boolean endObjectEntry() throws ParseException, IOException {
             currentKey = null;
             return !infoListener.done();
         }
 
+        @Override
         public boolean primitive(Object value) throws ParseException, IOException {
             if (":name".equals(currentKey)) {
                 Name name = Paths.translateName((String) value);
@@ -220,10 +220,12 @@ public final class Json {
             }
         }
 
+        @Override
         public boolean startArray() throws ParseException, IOException {
             throw new ParseException(3, "Array not expected");
         }
 
+        @Override
         public boolean endArray() throws ParseException, IOException {
             throw new ParseException(3, "Array not expected");
         }

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonHandlerBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonHandlerBase.java?rev=1128354&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonHandlerBase.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/JsonHandlerBase.java
Fri May 27 15:16:29 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.json.simple.parser.ContentHandler;
+import org.json.simple.parser.ParseException;
+
+import java.io.IOException;
+
+
+public abstract class JsonHandlerBase implements ContentHandler {
+    public void startJSON() throws ParseException, IOException {
+    }
+
+    public void endJSON() throws ParseException, IOException {
+    }
+
+    public boolean startObject() throws ParseException, IOException {
+        return true;
+    }
+
+    public boolean endObject() throws ParseException, IOException {
+        return true;
+    }
+
+    public boolean startObjectEntry(String key) throws ParseException, IOException {
+        return true;
+    }
+
+    public boolean endObjectEntry() throws ParseException, IOException {
+        return true;
+    }
+
+    public boolean startArray() throws ParseException, IOException {
+        return true;
+    }
+
+    public boolean endArray() throws ParseException, IOException {
+        return true;
+    }
+
+    public boolean primitive(Object value) throws ParseException, IOException {
+        return true;
+    }
+}

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java?rev=1128354&r1=1128353&r2=1128354&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Fri May 27 15:16:29 2011
@@ -35,10 +35,13 @@ import javax.jcr.Session;
 import javax.jcr.Value;
 import java.io.File;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 public class Tests {
     private static final File REPO_HOME_DIR = new File("target/repository");
@@ -75,6 +78,17 @@ public class Tests {
     public void getWorkspaceNames() throws RepositoryException {
         Session session = getSession();
         String[] workspaces = session.getWorkspace().getAccessibleWorkspaceNames();
+
+        Set<String> names = new HashSet<String>() {{
+            add("default");
+            add("system");
+        }};
+
+        for (String wsp : workspaces) {
+            assertTrue(names.remove(wsp));
+        }
+
+        assertTrue(names.isEmpty());
     }
 
     @Test



Mime
View raw message