Search in sources :

Example 1 with JsopBuilder

use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.

the class ClusterView method asJson.

/**
     * Converts the provided parameters into the clusterview json that will be
     * provided via JMX
     **/
private String asJson(final long viewSeqNum, final boolean viewFinal, final String clusterId, final int localId, final Set<Integer> activeIds, final Set<Integer> deactivatingIds, final Set<Integer> inactiveIds) {
    JsopBuilder builder = new JsopBuilder();
    builder.object();
    builder.key("seq").value(viewSeqNum);
    builder.key("final").value(viewFinal);
    builder.key("id").value(clusterId);
    builder.key("me").value(localId);
    builder.key("active").array();
    for (Iterator<Integer> it = activeIds.iterator(); it.hasNext(); ) {
        Integer anInstance = it.next();
        builder.value(anInstance);
    }
    builder.endArray();
    builder.key("deactivating").array();
    for (Iterator<Integer> it = deactivatingIds.iterator(); it.hasNext(); ) {
        Integer anInstance = it.next();
        builder.value(anInstance);
    }
    builder.endArray();
    builder.key("inactive").array();
    for (Iterator<Integer> it = inactiveIds.iterator(); it.hasNext(); ) {
        Integer anInstance = it.next();
        builder.value(anInstance);
    }
    builder.endArray();
    builder.endObject();
    return builder.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder)

Example 2 with JsopBuilder

use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.

the class BundledDocumentDifferTest method testDiff.

@Test
public void testDiff() throws Exception {
    NodeBuilder builder = createContentStructure();
    NodeState r1 = merge(store, builder);
    builder = store.getRoot().builder();
    childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("foo", "bar");
    NodeState r2 = merge(store, builder);
    JsopWriter w = new JsopBuilder();
    String path = "/test";
    assertTrue(differ.diff(dns(r1, path), dns(r2, path), w));
    assertTrue(w.toString().isEmpty());
    w = new JsopBuilder();
    path = "/test/book.jpg";
    assertFalse(differ.diff(dns(r1, path), dns(r2, path), w));
    assertEquals("^\"jcr:content\":{}", w.toString());
    builder = store.getRoot().builder();
    childBuilder(builder, "/test/book.jpg/foo");
    NodeState r3 = merge(store, builder);
    w = new JsopBuilder();
    path = "/test/book.jpg";
    //As there is a non bundled child differ should return true to continue diffing
    assertTrue(differ.diff(dns(r1, path), dns(r3, path), w));
    assertEquals("^\"jcr:content\":{}", w.toString());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) DelegatingDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter) Test(org.junit.Test)

Example 3 with JsopBuilder

use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.

the class IndexDefinitionPrinter method print.

@Override
public void print(PrintWriter printWriter, Format format, boolean isZip) {
    if (format == Format.JSON) {
        NodeState root = nodeStore.getRoot();
        JsopWriter json = new JsopBuilder();
        json.object();
        for (String indexPath : indexPathService.getIndexPaths()) {
            json.key(indexPath);
            NodeState idxState = NodeStateUtils.getNode(root, indexPath);
            NodeStateJsonUtils.copyAsJson(json, idxState, false);
        }
        json.endObject();
        printWriter.print(JsopBuilder.prettyPrint(json.toString()));
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Example 4 with JsopBuilder

use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.

the class RandomizedClusterTest method normalize.

private static String normalize(String json) {
    JsopTokenizer t = new JsopTokenizer(json);
    t.read('{');
    JsonObject o = JsonObject.create(t);
    JsopBuilder w = new JsopBuilder();
    o.toJson(w);
    return w.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer)

Example 5 with JsopBuilder

use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.

the class SimpleTest method escapeUnescape.

@Test
public void escapeUnescape() {
    DocumentMK mk = createMK();
    String rev;
    String nodes;
    Random r = new Random(1);
    for (int i = 0; i < 20; i++) {
        int len = 1 + r.nextInt(5);
        StringBuilder buff = new StringBuilder();
        for (int j = 0; j < len; j++) {
            buff.append((char) (32 + r.nextInt(128)));
        }
        String s = buff.toString();
        String x2 = Utils.escapePropertyName(s);
        String s2 = Utils.unescapePropertyName(x2);
        if (!s.equals(s2)) {
            assertEquals(s, s2);
        }
        if (s.indexOf('/') >= 0) {
            continue;
        }
        JsopBuilder jsop = new JsopBuilder();
        jsop.tag('+').key(s).object().key(s).value("x").endObject();
        rev = mk.commit("/", jsop.toString(), null, null);
        nodes = mk.getNodes("/" + s, rev, 0, 0, 100, null);
        jsop = new JsopBuilder();
        jsop.object().key(s).value("x").key(":childNodeCount").value(0).endObject();
        String n = jsop.toString();
        assertEquals(n, nodes);
        nodes = mk.getNodes("/", rev, 0, 0, 100, null);
        jsop = new JsopBuilder();
        jsop.object().key(s).object().endObject().key(":childNodeCount").value(1).endObject();
        n = jsop.toString();
        assertEquals(n, nodes);
        jsop = new JsopBuilder();
        jsop.tag('-').value(s);
        rev = mk.commit("/", jsop.toString(), rev, null);
    }
}
Also used : Random(java.util.Random) JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) Test(org.junit.Test)

Aggregations

JsopBuilder (org.apache.jackrabbit.oak.commons.json.JsopBuilder)18 JsopWriter (org.apache.jackrabbit.oak.commons.json.JsopWriter)9 Test (org.junit.Test)5 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)2 DelegatingDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 Value (javax.jcr.Value)1