You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2011/04/22 19:09:10 UTC
svn commit: r1095962 -
/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Author: stefan
Date: Fri Apr 22 17:09:10 2011
New Revision: 1095962
URL: http://svn.apache.org/viewvc?rev=1095962&view=rev
Log:
MicroKernel prototype (WIP)
Modified:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.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=1095962&r1=1095961&r2=1095962&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 Fri Apr 22 17:09:10 2011
@@ -1,12 +1,30 @@
+/*
+ * 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.mk;
import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.mk.api.MicroKernelException;
import org.apache.jackrabbit.mk.store.Commit;
+import org.apache.jackrabbit.mk.store.Node;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
*
@@ -120,9 +138,13 @@ public class MicroKernelImpl implements
throw new IllegalStateException("this instance has already been disposed");
}
- // todo implement
-
- return null;
+ try {
+ StringBuffer buf = new StringBuffer();
+ toJson(rep.getNode(revisionId, path), depth, buf);
+ return buf.toString();
+ } catch (Exception e) {
+ throw new MicroKernelException(e);
+ }
}
public String getChildNodes(String path, long offset, long count, int depth, String revisionId) throws MicroKernelException {
@@ -186,4 +208,35 @@ public class MicroKernelImpl implements
return null;
}
+
+ //-------------------------------------------------------< implementation >
+
+ void toJson(Node node, int depth, StringBuffer buf) throws Exception {
+ buf.append("{");
+ for (Map.Entry prop : node.getProperties().entrySet()) {
+ buf.append('"');
+ buf.append(prop.getKey());
+ buf.append("\":\"");
+ buf.append(prop.getValue());
+ buf.append("\",");
+ }
+
+ buf.append("\":childNodeCount\":\"");
+ // todo optimize
+ int childCount = node.getChildNodeEntries().size();
+ buf.append(childCount);
+ buf.append("\"");
+ if (childCount > 0 && depth > 0) {
+ depth--;
+ buf.append(',');
+ for (Map.Entry<String, String> child : node.getChildNodeEntries().entrySet()) {
+ buf.append('"');
+ buf.append(child.getKey());
+ buf.append("\":");
+ String childId = child.getValue();
+ toJson(rep.getStore().getNode(childId), depth, buf);
+ }
+ }
+ buf.append("}");
+ }
}