Search in sources :

Example 6 with JsopWriter

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

the class DocumentNodeState method asString.

public String asString() {
    JsopWriter json = new JsopBuilder();
    json.key("path").value(path);
    json.key("rev").value(rootRevision.toString());
    if (lastRevision != null) {
        json.key("lastRev").value(lastRevision.toString());
    }
    if (hasChildren) {
        json.key("hasChildren").value(true);
    }
    if (properties.size() > 0) {
        json.key("prop").object();
        for (Map.Entry<String, PropertyState> e : bundlingContext.getAllProperties().entrySet()) {
            json.key(e.getKey()).value(asString(e.getValue()));
        }
        json.endObject();
    }
    return json.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 7 with JsopWriter

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

the class Commit method addChangesToDiffCacheEntry.

/**
     * Apply the changes of a node to the cache.
     *
     * @param path the path
     * @param added the list of added child nodes
     * @param removed the list of removed child nodes
     * @param changed the list of changed child nodes
     * @param cacheEntry the cache entry changes are added to
     */
private void addChangesToDiffCacheEntry(String path, List<String> added, List<String> removed, List<String> changed, DiffCache.Entry cacheEntry) {
    // update diff cache
    JsopWriter w = new JsopStream();
    for (String p : added) {
        w.tag('+').key(PathUtils.getName(p)).object().endObject();
    }
    for (String p : removed) {
        w.tag('-').value(PathUtils.getName(p));
    }
    for (String p : changed) {
        w.tag('^').key(PathUtils.getName(p)).object().endObject();
    }
    cacheEntry.append(path, w.toString());
}
Also used : JsopStream(org.apache.jackrabbit.oak.commons.json.JsopStream) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Example 8 with JsopWriter

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

the class NodeStateJsonUtils method toJson.

public static String toJson(NodeState state, boolean includeHiddenContent) {
    JsopWriter json = new JsopBuilder();
    copyAsJson(json, state, includeHiddenContent);
    return json.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Example 9 with JsopWriter

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

the class BundledDocumentDifferTest method diffWithSecondary.

@Test
public void diffWithSecondary() throws Exception {
    configureSecondary();
    NodeBuilder builder = createContentStructure();
    NodeState r1 = merge(store, builder);
    NodeState rs1 = DelegatingDocumentNodeState.wrap(secondary.getRoot(), store);
    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/book.jpg";
    assertFalse(differ.diff(adns(rs1, path), adns(r2, 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 10 with JsopWriter

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

the class BundledDocumentDifferTest method jsopDiff.

@Test
public void jsopDiff() throws Exception {
    JsopWriter w = new JsopBuilder();
    differ.diffChildren(of("a", "b"), of("b", "c"), w);
    //removed a
    //changed b
    //added b
    assertEquals("-\"a\"^\"b\":{}+\"c\":{}", w.toString());
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter) Test(org.junit.Test)

Aggregations

JsopWriter (org.apache.jackrabbit.oak.commons.json.JsopWriter)11 JsopBuilder (org.apache.jackrabbit.oak.commons.json.JsopBuilder)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 Test (org.junit.Test)3 Map (java.util.Map)2 JsopStream (org.apache.jackrabbit.oak.commons.json.JsopStream)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 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1